3D Patterns

Материал из Поле цифровой дидактики

Шаблон:Expand This tutorial explains how to make 3-dimensional patterns in Scratch.

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. To do this, pen blocks and custom blocks have to be used.

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 v) to (pick random (1) to (100))
Reset :: custom
forever
erase all
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

Creating the Draw Script

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

define Draw
show
erase all
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 (brightness v) 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