Document.png Please expand this article. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (December 2017)

How Does 3D Work in Scratch?

Scratch is mostly intended for 2D projects, but it is possible to create a 3D effect with scratch. This can be done by projecting a point that uses the dimensions x, y, and z to find its position.

Making the Main Script

First of all, make some custom blocks as follows:

define Reset
define Draw

Afterwards, make this script,

when green flag clicked
set pen color to (pick random (1) to (100))
Reset :: custom
forever
clear
Draw :: custom
change [delta v] by (1)
end

The script above is the loop that will start everything up in the project.

Getting the Variables Ready

Next, get the variables ready. In the Reset :: custom custom block, make this script:

define Reset
set [angle v] to [0]
set [A v] to [220]
set [B v] to [160]
set [r1 v] to (pick random (1) to (100))
set [r2 v] to (pick random (1) to (100))
set [delta v] to (pick random (1) to (90))
go to x: ((A) * ([sin v] of (((angle) * (r1)) + (delta)))) y: ((B) * ([cos v] of (((angle) * (r2)) + (delta)))
pen down
set pen size to (50)

The Reset block will also make a pattern, so it will be useful.

Note Note: For easier access, make the r1 and r2 variables sliders.

Creating the Draw Script

The following script will be very complicated since it will use a lot of math. The reason for that is because the script also shades what it will draw.

Next, make the code for the Draw :: custom custom block. This block will be more complicated.

define Draw
show
clear
pen down
repeat (360)
go to x: ((A) * ([sin v] of (((angle) * (r1)) + (delta)))) y: ((B) * ([cos v] of ((angle) * (r2))
set pen size to ([abs v] of ((((1000) - ((A) * ([sin v] of (((angle) * (r1)) + (delta))))) - ((B) * ([cos v] of ((angle) * (r2))))) / (150)))
set pen shade to ((-0.5) * (((A) * ([sin v] of (((angle) * (r1)) + (delta)))) - ((B) * ([cos v] of ((angle) * (r2))))
change [angle v] by (1)
move (10) steps

Example Project