In the book "How to Think Like A Computer Scientist" on the website 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/", line 486, in __bootstrap_inner
  File "/usr/lib/python2.5/site-packages/gasp/", line 396, in run
    e = pygame.event.wait()

             File "/home/me/", line 15, in <module>
    draw_house(5, 100)
  File "/home/me/", line 11, in draw_house
  File "/usr/lib/python2.5/site-packages/gasp/", line 449, in update_when
  File "/usr/lib/python2.5/site-packages/gasp/", line 482, in update_when
error: video system not initialized

Recommended Answers

All 3 Replies

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.