ScratchX: Scratch in 3D

Today our advanced group started to look at ScratchX. With ScratchX you can add extra modules to the Scratch environment, and today we looked at the Scratch3D extension.

Scratch space 3D coordinate imageFirstly, we looked at 3D coordinates. With Scratch we normally have x and y, but now we have z. In the picture you can see x going left to right and y going up and down, but now we also have z coming torwards and away from us. In this image the sun is at the centre of the solar system, x=y=z=0.

Scratch code showing how to make 3D coordinates display in spaceBecause you can move around the 3D space, you can’t easily show coordinates in the corner like you can with the fixed 2D space of normal Scratch. Well, you could show where the viewer (or “camera”) is located, but since you can be facing in any direction, and maybe even upside-down, your location is only part of the story. The code here shows how you can set the x, y, and z coordinates to be displayed as big numbers in 3D space as in the image above. It’s much easier to see where you are with big numbers floating all around you!

Solar System scriptFinally, here’s the code to create the sun and planets, and place them around in space. The Scratch3D extension makes it really easy to create a planet, place it where you want, scale it to the size you want, complete with full-colour texture map, and all in one line. We also have a Lego Darth Vader and a Car (a Tesla?) hidden somewhere in space. Next the forever loop keeps the planets and sun rotating gradually. You can see in the corner the first few blocks for moving around. You can download the Scratch script here.