Difference between revisions of "Looping with GASP Exercises"

From WLCS
(Created page with "'''Objectives:''' * You will practice creating while loops * You will integrate loops into drawing graphics with GASP '''Directions:''' * Use the following template in a file na...")
 
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
 
* You will practice creating while loops
 
* You will practice creating while loops
 
* You will integrate loops into drawing graphics with GASP
 
* You will integrate loops into drawing graphics with GASP
 +
 +
'''Resources:'''
 +
* [http://www.openbookproject.net/thinkcs/python/english2e/app_b.html GASP Reference]
  
 
'''Directions:'''
 
'''Directions:'''
Line 8: Line 11:
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
from gasp import *
 
from gasp import *
begin_graphics()
+
#begin_graphics()
 +
begin_graphics(width=800, height=600, title="Crazy Drawing", background=color.WHITE)
  
int x = 0
+
x = 0
 
while x < 1000:
 
while x < 1000:
 
     print x
 
     print x

Latest revision as of 12:26, 19 November 2010

Objectives:

  • You will practice creating while loops
  • You will integrate loops into drawing graphics with GASP

Resources:

Directions:

  • Use the following template in a file named loopGasp.py:
from gasp import *
#begin_graphics()
begin_graphics(width=800, height=600, title="Crazy Drawing", background=color.WHITE)

x = 0
while x < 1000:
    print x
    Circle ( (0, 0), x)
    x = x + 10

update_when('key_pressed')
end_graphics()
  • What do you see when you run the code above?
  • Let's try to create some other graphics with GASP and loops. Complete the following drawings, but you must create new files for each (e.g. loopGasp1.py, loopGasp2.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