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, it is recommended that you have 16 slices.[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, we must calculate the offsets using 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, when this runs, it is extremely slow. 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'. Right-click the top block of the script inside the repeat block (change x by), and select "duplicate". A copy of the script appears at your mouse. Drop this script right above the block you right-clicked. Now repeat this 3 more times.

 Note: Each time, remember to right-click the new top block

Finally, replace the "16" in the repeat block with 1:

```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 (1)
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
end
```

## 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
clear
forever
clear
change x by (2)
stamp
change x by (2)
stamp
change x by (2)
stamp
change x by (2)
stamp
change x by (2)
stamp
change x by (2)
stamp
change x by (2)
stamp
change x by (2)
stamp
change x by (2)
stamp
```

This is another way of stacking slices on top of each other. This will not give you as satisfying results as the other technique shown above will. It will not create a very good 3D effect.

## Examples

Cookies help us deliver our services. By using our services, you agree to our use of cookies.