Random numbers:
Logo
instructions using RANDOM to get numbers from the given
range:
Range:
(500 to 999)
500 + RANDOM 500
Range:
(-200 to 0)
(RANDOM 201) - 200
Range:
(-30 to 29)
(RANDOM 60) – 30
Even
numbers in the range: (0 to 198)
(RANDOM 100) * 2
RANDOM
100 will give numbers in the range (0 to 99). Multiplying by 2 will give us
only the even numbers in the range (0 to 198).
Wheel of Triangles:
REPEAT 15 [
SETPC 1+(RANDOM 15)
triangle 100
RT 360/15
]
Since we want all colors except black, we want to use the color range (1 to 15). This range consists of 15 numbers. Adding 1 shifts the range from (0 to 14) to (1 to 15).
City from space:
The
procedure to draw the cityscape consists of the following steps:
-
The Turtle moves some random distance forward
- Then, it either randomly turns left or right, or remains straight
This procedure is then repeated a number of times.
Repeat 5000 [
FD random 25
RT 90*((Random 3)-1)
]
To get a colorful cityscape, we will randomly change color after a certain number of steps. We want colors 1 to 15 (we want to avoid black since the background is black). RANDOM 15 will give us number in the range (0 to 14) which we can shift to (1 to 15) by simply adding 1.
REPEAT 100 [
SETPC 1+(RANDOM 15)
Repeat 50 [
FD RANDOM 25 RT (90 * ((RANDOM 3)-1))
]
]