This is a tutorial on animating a three-dimensional object using the stack method.

Creating the Costumes

The first step in making an animated 3D object is to create the costumes. This is done by imagining one is slicing the object so that it is a stack of slices. For example, a cylinder, when sliced, would be a stack of circles. A cone would be a stack of circles with a decreasing diameter, and a sphere would be a stack of circles whose diameter first increases, then decreases. Each of these imaginary slices must then be drawn with a paint editor. For the sake of simplicity when programming, the recommended number of slices is 16.[citation needed]

Writing the Script

This project will require only one script and one sprite, thus it will be One Sprite One Script.

Theory

The script will draw the 3D object by Stamping each slice on top of the other, slightly displaced. This will cause the illusion of a 3D object by reconstructing the object which was "sliced" in the above section. The displacement will be determined by calculating the horizontal and vertical offset with a given angle, using trigonometry. The script will loop forever, slightly incrementing the angle each repetition to give the illusion of rotation. The drawing script must be Single Frame to prevent rendering lag.

Part 1: Setting up the stage

Firstly, the project must be set up. This includes:

  • Centering the object on the Stage
  • Clearing the stage
  • Rotating the sprite
  • Incrementing the angle

The script is shown here:

when gf clicked
forever
go to x: (0) y: (0)//center sprite
turn ccw (1) degrees//rotate sprite
clear//clear stage
change [angle v] by (1)//increment angle

Next, the offsets must be calculated with a certain amount of trigonometry:

when gf clicked
forever
go to x: (0) y: (0)
turn ccw (1) degrees
clear
change [angle v] by (1)
set [x-offset v] to ([sin v] of (angle))//x offset
set [y-offset v] to ([cos v] of (angle))//y offset

Part 2: Moving and stamping

Next, the sprite must move and stamp itself, and change its costume accordingly. This is done with the following change:

when gf clicked
forever
go to x: (0) y: (0)
turn ccw (1) degrees
clear
change [angle v] by (1)
set [x-offset v] to ([sin v] of (angle))
set [y-offset v] to ([cos v] of (angle))
repeat (16)//repeat for each of the 16 slices
change x by (x-offset)//move
change y by (y-offset)//move
stamp//stamp
next costume//change costume
end

However, this runs extremely slowly. To speed it up, it is best to make the script Single Frame. The easiest way to do this is by using the duplicate function:

  1. Right-click the top block of the script inside the repeat block (change x by), and select "duplicate".
  2. A copy of the script will appear at the mouse cursor.
  3. Drop this script right above the block right-clicked. Now repeat this 3 more times.
Note Note: Each time, remember to right-click the new top block

Finally, move the blocks out of, and remove, the repeat block:

when gf clicked
forever
go to x: (0) y: (0)
turn ccw (1) degrees
clear
change [angle v] by (1)
set [x-offset v] to ([sin v] of (angle))
set [y-offset v] to ([cos v] of (angle))
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume
change x by (x-offset)
change y by (y-offset)
stamp
next costume

Mouse 3D

This is how to make a 3D object follow the mouse. Adding a repeat block will make it easier.

  1. Make the costumes (see Creating the Costumes)
  2. Add this script:
when gf clicked
clear
forever
turn cw (3) degrees
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume
change x by ((0.05) * (mouse x))
change y by ((0.05) * (mouse y))
stamp
next costume


Another simpler technique is shown below:

when gf clicked
forever
clear
change x by (2)

Though this is easier, it also produces less satisfactory results, so a certain tradeoff needs to be made between simplicity and complexity.

Examples