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:

defineResetdefineDraw

Afterwards, make this script,

whenclickedsetpencolortopickrandom1to100ResetforevereraseallDrawchangedeltaby1end

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 block, make this script:

defineResetsetangleto0setAto220setBto160setr1topickrandom1to100setr2topickrandom1to100setdeltatopickrandom1to90gotox:A*sinofangle*r1+deltay:B*cosofangle*r2+deltapendownsetpensizeto50

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 block. This block will be more complicated.

defineDrawshoweraseallpendownrepeat360gotox:A*sinofangle*r1+deltay:B*cosofangle*r2setpensizetoabsof1000-A*sinofangle*r1+delta-B*cosofangle*r2/150setpenbrightnessto-0.5*A*sinofangle*r1+delta-B*cosofangle*r2changeangleby1move10steps

Example Project