Difference between revisions of "Turtle - Looping Assignment"

From WLCS
(Created page with "'''Objectives:''' * You will practice creating while loops * You will integrate loops into drawing graphics with Python's turtle '''Resources:''' * [http://docs.python.org/py3k/...")
 
 
(2 intermediate revisions by the same user not shown)
Line 20: Line 20:
 
     x = x + 10
 
     x = x + 10
  
exitonclick()
+
done()
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Latest revision as of 14:06, 1 October 2014

Objectives:

  • You will practice creating while loops
  • You will integrate loops into drawing graphics with Python's turtle

Resources:

Directions:

  • Use the following template in a file named loopTurtle.py:
from turtle import *

speed(0) # fastest turtle

x = 0
while x < 500:
    print(x)
    circle(x)
    x = x + 10

done()
  • What do you see when you run the code above?
  • Let's try to create some other graphics with Turtle and loops. Complete the following drawings, but you must create new files for each (e.g. loopTurtle1.py, loopTurtle2.py, etc.)
  1. Draw a bunch of Circles across the bottom of the screen
  2. Draw Circles along all the sides of the screen (left, bottom, right, top)
  3. Draw a diagonal of Circles from the bottom-left to the upper-right
  4. Draw 100 Circles of random sizes and random locations throughout the screen (HINT: random.randint())
  5. Draw 10 random Circles, but each time you draw a Circle, connect a Line from it to the previous Circle