Revision as of 11:48, 17 December 2017 by Kieranblackley (talk | contribs) (←Created page with " == How Does 3D Work In Scratch? == Scratch is mostly intended for 2d projects, but it is possible to create a 3d effect with scratch. We can do this by projecting a point ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How Does 3D Work In Scratch?

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


What Is This Tutorial For?

This tutorial will show how to make 3d patterns.


Making The Main Script

First of all we will need to make some define blocks. Here they are:

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 we will need to get the variables ready. With the Reset 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: you can make the r1 and r2 variables sliders if you want to.


Creating the Draw Script

Note: The next script will be very complicated since it will use a lot of math. The reason why is because the script also shades what it is drawing.

Next we will need to make a very complicated script. We will use the draw custom block to make it.

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

Sadly the script above, went rather wrong. The operator blocks that turned into a red or blue colour should all be green-coloured.


End

Well done, you have finally created a small, but complicated, 3d engine.


If you would like to see some examples of projects like this you can look down below:

3D Pattern Drawer