2016-03-26 00:47:20 +01:00
# rotation animation challenges
Coding challenges for the rotation animation tutorial. #docs
## Before we get started
Complete the following guided tutorial:
2016-04-13 17:27:45 +02:00
* [tutorial ](/lessons/rotation-animation/tutorial )
2016-03-26 00:47:20 +01:00
At the end of the tutorial, click `keep editing` . Your code should look like this:
```
rotating = true
while (rotating) {
basic.showAnimation(`
# . . . . . . # . . . . . . # . . . . .
. # . . . . . # . . . . . # . . . . . .
. . # . . . . # . . . . # . . # # # # #
. . . # . . . # . . . # . . . . . . . .
. . . . # . . # . . # . . . . . . . . .
`, 400)
basic.pause(25)
}
```
### Challenge 1
Now let's add to this by creating a condition for on button pressed `A` before the while loop.
```
rotating = true
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
}) // ** *
while (rotating) {
basic.showAnimation(`
# . . . . . . # . . . . . . # . . . . .
. # . . . . . # . . . . . # . . . . . .
. . # . . . . # . . . . # . . # # # # #
. . . # . . . # . . . # . . . . . . . .
. . . . # . . # . . # . . . . . . . . .
`, 400)
basic.pause(25)
}
```
### Challenge 2
### @video td/videos/rotation-animation-1-and-2
Now that we have the on button pressed condition, let's make the animation stop rotating by setting the rotating global variable to false when button `A` is pressed.
```
rotating = true
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
rotating = false // ** *
}) // ** *
while (rotating) {
basic.showAnimation(`
# . . . . . . # . . . . . . # . . . . .
. # . . . . . # . . . . . # . . . . . .
. . # . . . . # . . . . # . . # # # # #
. . . # . . . # . . . # . . . . . . . .
. . . . # . . # . . # . . . . . . . . .
`, 400)
basic.pause(25)
}
```
* Run the code to see the awesome rotation.
### Challenge 3
Let's also make the image rotate the opposite way when button A is pressed! We can do this with another while loop that is only executed while `not rotating` .