In the book "How to Think Like A Computer Scientist" on the website openbookproject.net the tutorial leads you to draw a house with a pre-written script. It then instructs you to: # Wrap the house code in a function named draw_house().
# Run the script now. Do you see a house? Why not?
# Add a call to draw_house() at the botton of the script so
that the house returns to the screen.
# Parameterize the function with x and y parameters
-- the header should then become def draw_house(x, y):, so that
you can pass in the location of the house on the canvas.
# Use draw_house to place five houses on the canvas in
different locations.
So I wrote this (the parameters given in the definition were already given to draw a single house):

from gasp import *

def draw_house(x, y):
    Box((20, 20), 100, 100)     #the house
    Box((55, 20), 30, 50)       #the door
    Box((40, 80), 20, 20)       #the left window
    Box((80, 80), 20, 20)       #the right window
    Line((20, 120), (70, 160))  #the left roof
    Line((70, 160), (120, 120)) #the right roof
draw_house(5, 5)
draw_house(5, 100)
draw_house(30, 50)
draw_house(100, 5)
draw_house(100, 100)

The problem is, it only draws a single house at the bottom left of the canvas and does nothing else even with keystrokes. When I X-out of gasp, I get the following errors in the python shell"

Traceback (most recent call last):
Exception in thread Thread-14:
Traceback (most recent call last):
  File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner
  File "/usr/lib/python2.5/site-packages/gasp/backend.py", line 396, in run
    e = pygame.event.wait()

             File "/home/me/draw_house.py", line 15, in <module>
    draw_house(5, 100)
  File "/home/me/draw_house.py", line 11, in draw_house
  File "/usr/lib/python2.5/site-packages/gasp/api.py", line 449, in update_when
  File "/usr/lib/python2.5/site-packages/gasp/backend.py", line 482, in update_when
error: video system not initialized
7 Years
Discussion Span
Last Post by shasta90

You have to use the x and y values for it to have any effect.

Box((20 + x, 20 + y), 100 + x, 100 + y)     #the house

if Box takes x1, y1, x2, y2 as arguments the code above should work


Thanks for the help. that didn't do EXACTLY what I was shooting for, but you put me on the right track. Now it just needs a little fine tuning. Thanks again.


What code did you us to get the 5 houses to appear in the end as I am trying to make a call
to draw_house() which is not working?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.