Nov 302021
Recap
- What is a procedure?
- How do we code a procedure?
- What is a procedure with variables?
New skill
- random 100 = chooses a number between 1 and 50
- So typing “c random 100” draws a c which is between 1 and 100 big
- setpensize rnadom 30 chooses a pen width between 1 and 30
- If you c had two variables, then you could type:
- c random 100 random 30
- The coordinates on the drawing canvas go from -250 to 250 across and -250 to 250 up and down. (0,0) is in the middle.
- To make your shape appear in a random place:
- setxy (-250 + random 500) (-250 + random 500)
Tasks
- Open you “c size procedure” file
- Add the following code to make lots of random c shapes
- repeat 100
- [
- c random 100 random 30
- pu
- setxy (-250 + random 500) (-250 + random 500)
- pd
- ]
- ** Put this line inside the repeat to get random colours!
- colour [random 255 random 255 random 255]
- ** Write your own letter procedure with a variable :size instead of fd/bk numbers
- *** Can you include a :col variable to choose the colour?
- How else could you use random? Try these ideas on different files
- circle random 100
- repeat 100 [fd random 100 rt 90]
- repeat 100 [fd random 200 setxy 0 0 rt 5]
See these posts for more ideas and techniques:
- Draw letter rainbows, flowers and shapes
- Stars and shapes 2
- Stars and shapes 1
- The power of procedures with variables
- Use variables to draw spirals
- Use variables to draw shapes
- Random
- Repeat, setxy, procedures
LOGO example files – can you work out how they work?