Lesson 19: Spiral art
Art with a robot
- Artists use robots and code to make drawings that are hard to do by hand.
- A loop repeats the same move. If a variable changes each time, every side is a bit different, and a square becomes a spiral.
- With a list of colours, each side can have its own colour.
Words for this lesson
| Word | Meaning |
|---|---|
| spiral | a line that goes round and round and gets bigger |
| list | many values in order, like [RED, GREEN, BLUE, BLACK] |
| % | the remainder after dividing: 7 % 4 is 3 |
| angle | how far the robot turns, in degrees |
How the square spiral grows
| side | step before | drive | step after |
|---|---|---|---|
| 0 | 50 | 50 mm | 100 |
| 1 | 100 | 100 mm | 150 |
| 2 | 150 | 150 mm | 200 |
| … | … | … | … |
| 15 | 800 | 800 mm | 850 |
Colours in turn
| side | side % 4 | colour |
|---|---|---|
| 0 | 0 | RED |
| 1 | 1 | GREEN |
| 2 | 2 | BLUE |
| 3 | 3 | BLACK |
| 4 | 0 | RED |
| 5 | 1 | GREEN |
from vexcode_vr import *
def main():
colours = [RED, GREEN, BLUE, BLACK]
for side in range(6):
brain.print(side % 4)
brain.new_line()
vr_thread(main)
- The brain prints 0, 1, 2, 3, 0, 1: the positions in the list, round and round.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
Draw a square spiral with the pen. The robot drives a side, turns right 90°, and the next side is 50 mm longer. Start with step = 50 and draw 16 sides. The starter draws 16 sides that are all the same, so it only goes round a square.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 4/5 · 280 pièces + un petit bonus lors de la première réussite aujourd'hui
Now a colourful twisted spiral: 36 sides, starting at 20 mm and 20 mm longer each time, with a turn of 125° (5° more than a triangle's 120°, so each triangle is turned a little). Change the pen colour on every side, taking the colours from the list in order: colours[side % 4].
Cliquez sur Exécuter pour voir le résultat ici.