$34.99
This lab explores modular program development using functions (See: Lec. 3B). You will write simple functions to draw line segments and arcs and then use these functions to draw a flower with a stem. See examples below.
• Any effort is fine - you will have a chance to improve on your art another time.
• The purpose is to build a little drawing library and to have a bit of fun doing it.
• Make sure to test each function before proceeding.
(a) 5 Petals. (b) Lopsided (c) A good effort.
Figure 1: flowers.
Test your function before proceeding.
It is good practice to put a description of the function just after the name. e.g. def polyLine(t, n, length, angle):
’’’Draws ’n’ line segments of ’length’; tilted at ’angle’ to the prev. ”’ note the triple quotes - they allows for multi-line comments. Triple quoted strings at the tops of functions are known as docstrings.
Ex. 2. Use polyLine(...) to a construct a function polygon(t, numSides).
Ex 3 Write a function drawArc to draw an arc of circle of radius r, subtended by an angle α. The example below shows the arc of a circle of radius 100 in blue subtended by α = 90o
You must use polyLine(...) to write drawArc.
The arc length s = r · α where α is in radians.
Break up the arc into (an integer) number of st. line segments n of a small fixed length (∼ 5 pixels). Therefore each line segment of the arc will be of length = s/n
Call polyLine(...) with the above parameters to draw the arc
Ex. 4 Use drawArc(...) to define a function drawCircle(t, r) (r is the radius of the circle).
Ex. 5 Define a function drawPetal(...). A petal is drawn by making two calls to drawArc(...), appropriately flipping the turtle heading between the calls.
Ex. 6 Define drawStem(t, length, heading). Which draws a stem, a straight line, coloured brown.
Ex. 7 Finally, define drawFlower(t, r, angle, numPetals, p) which makes numPetal calls to drawPetal(...), each turned an angle p away from the previous).
Bonus for very nicely drawn flowers! Esp. those that incorporate more colours, new elements etc..
• Zip into a folder and submit!