Here is a subset of the possible solutions for drawing the polygons in this assignment. Please keep in mind that there are multiple correct ways of programming each of these figures.
The following programs draw the polygons without using Repeat Loops.
All of the regular polygons below have sides of 6 cm.
1. Equilateral Triangle
The following programs draw the polygons without using Repeat Loops.
1. Square of sides 8 cm:
Fd 8
Rt
Fd 8
Rt
Fd 8
Rt
Fd 8
2. Rectangle 4 cm x 6 cm:
Fd 43. Parallelogram 4 cm x 6 cm:
Rt
Fd 6
Rt
Fd 4
Rt
Fd 6
Fd 44. Rhombus 6 cm:
Rt 45
Fd 6
Rt 135
Fd 4
Rt 65
Fd 6
Fd 65. Equilateral Triangle of sides 6 cm:
Rt 60
Fd 6
Rt 120
Fd 6
Rt 60
Fd 6
Fd 66. Right Triangle of sides 3 cm, 4 cm, 5 cm:
Rt 120
Fd 6
Rt 120
Fd 6
Fd 3
Rt 126
Fd 5
Rt 144
Fd 4
Drawing Regular Polygons using Repeat Loops in Pro-Bot
All of the regular polygons below have sides of 6 cm.
Rpt 3 [2. Square
Fd 6
Rt 120
]
Rpt 4 [
Fd 6
Rt 90
]
// You can also use the instruction "Rt", instead of "Rt 90" in the code above, // as the default turn is 90 degrees for Pro-Bot.3. Pentagon
Rpt 5 [4. Hexagon
Fd 6
Rt 72
]
Rpt 6 [5. Octagon
Fd 6
Rt 60
]
Rpt 8 [6. Nonagon
Fd 6
Rt 45
]
Rpt 9 [7. Decagon
Fd 6
Rt 40
]
Rpt 10 [
Fd 6
Rt 36
]
A Circle using a Repeat Loop
Rpt 360 [
Fd 1 // Move 1 cm
Rt 1 // Turn 1 degree
]
Fd 1 // Move 1 cm
Rt 1 // Turn 1 degree
]
An Algorithm for Drawing Regular Polygons using Repeat Loops
From the pieces of code above for various regular polygons, the relation between the number of sides of a regular polygon and the angle of turn can be deduced to 360/N where N is the number of sides of the polygon.
The generalized algorithm for drawing regular polygons is:
Rpt N [where N is the number of sides of the regular polygon, X is the length of each side of the polygon.
Fd X
Rt 360/N
]
awesome job!
ReplyDelete