Creating a program to make shapes

advertisement
Creating a program to make a shape
Open the chrome browser
Search for Blockly Turtle
Drawing shapes using a repeat loop
Task Copy this script
change the:
Repeat to 3
and the
Turn to 120
What happens?
Creating a stepping loop using the
Variable i
Variable i
Step
Upper limit (end)
The VARIABLE i is a value that changes each time the loop is executed (run)
A common mistake when people learn stepping loops it to misread i as a 1.
You can use any letter you like
Task. Copy this script.
Lets change the variable to J change the upper limit to 8 and step 2.
What happens?
https://blockly-demo.appspot.com/static/apps/turtle/index.html#cbzn2z
Using a procedure AKA subroutine
• Procedures are used to complete distinct (separate)
tasks
• To run a procedure you need to use a call or execute
command.
There are many ways to solve problems
This is the execute call command
Using a procedure inside another Procedure
(Nesting)
Use the DrawSquare
procedure as before.
We are going to make a pattern
Using the DrawSquare routine to draw
petals of a flower.
Create a procedure called FlowerPattern
This new procedure must
Repeat the DrawSquare routine 36 times
Each petal must rotate by 10 degrees
https://blockly-demo.appspot.com/static/apps/turtle/index.html#wcysxu
Improving our program
Using random to select line colours
What happens if I move the colour script here?
What happens if I put this colour
script here?
OK but Squares are boring!
We can draw any shape if we know the
Number of sides
and
The interior angles
Look at this site
• You can see that there is a relationship between
the number of sides and the internal angles.
Using a rule
The inside angle of any shape is related to the number of sides. E.g. 4 sides = 90 degrees
360 degrees divided by the No of Sides of any shape
Or to put it another way
360/the number of sides
We can create a variable for the number of sides we want.
Create a variable NumberOfSides
Create a variable InternalAngle
Set NumberOfSides to 4
It would be useful to define the SideLength also create a variable to store this. Make the
SideLength=30
Using a mathematical rule in a Variable
Use variables in your DrawShape
routine
This now
DrawShape
execute call will
run the procedure
if it is placed on
the stage.
https://blockly-demo.appspot.com/static/apps/turtle/inde
https://blockly-demo.appspot.com/static/apps/turtle/index.html#o3gvhh
Create a
procedure called
RunShapeArt
Create a loop to create
rotated repetitions of
the shape.
This is similar to the
flower loop that you’ve
already practised.
Using Blockly Minecraft
Download