Skip to content

Instantly share code, notes, and snippets.

@sanjayts
Created July 1, 2011 06:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanjayts/1057999 to your computer and use it in GitHub Desktop.
Save sanjayts/1057999 to your computer and use it in GitHub Desktop.
draw house in gasp
import sys
from gasp import * # import everything from the gasp library
def draw_house_colored(x, y):
begin_graphics(1024, 768, "Game", color.BLACK) # open the graphics canvas
Box((x + 20, y + 20), 100, 100, True, color.BLUE) # the house
Box((x + 55, y + 20), 30, 50, True, color.GREEN) # the door
Box((x + 40, y + 80), 20, 20, True, color.YELLOW) # the left window
Box((x + 80, y + 80), 20, 20, True, color.YELLOW) # the right window
Polygon([(x + 20, y + 120), (x + 70, y + 160), (x + 120, y + 120)], True, color.RED) # the roof
update_when('key_pressed') # keep the canvas open until a key is pressed
end_graphics() # close the canvas (which would happen
# anyway, since the script ends here, but it
# is better to be explicit).
def draw_house(x, y):
begin_graphics(800, 600) # open the graphics canvas
Box((x + 20, y + 20), 100, 100) # the house
Box((x + 55, y + 20), 30, 50) # the door
Box((x + 40, y + 80), 20, 20) # the left window
Box((x + 80, y + 80), 20, 20) # the right window
Line((x + 20, y + 120), (x + 70, y + 160)) # the left roof
Line((x + 70, y + 160), (x + 120, y + 120)) # the right roof
update_when('key_pressed') # keep the canvas open until a key is pressed
end_graphics() # close the canvas (which would happen
# anyway, since the script ends here, but it
# is better to be explicit).
def draw_just_house(x, y):
"""Draw the house assuming that the canvas has already been initialized"""
Box((x + 20, y + 20), 100, 100, True, color.BLUE) # the house
Box((x + 55, y + 20), 30, 50, True, color.GREEN) # the door
Box((x + 40, y + 80), 20, 20, True, color.YELLOW) # the left window
Box((x + 80, y + 80), 20, 20, True, color.YELLOW) # the right window
Polygon([(x + 20, y + 120), (x + 70, y + 160), (x + 120, y + 120)], True, color.RED) # the roof
def do_main_one():
x = input('Enter x: ')
y = input('Enter y: ')
draw_house_colored(x, y)
def do_main_two():
# initialize
begin_graphics(1024, 768, "Game", color.BLACK) # open the graphics canvas
# first row
draw_just_house(0, 0)
draw_just_house(200, 0)
draw_just_house(400, 0)
# second row
draw_just_house(100, 140)
draw_just_house(300, 140)
# topmost row
draw_just_house(200, 280)
# cleanup
update_when('key_pressed') # keep the canvas open until a key is pressed
end_graphics() # close the canvas (which would happen
if __name__ == '__main__':
do_main_two()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment