Python Why Can't I Draw Multiple Houses in Python?

  • Thread starter Thread starter brushman
  • Start date Start date
  • Tags Tags
    Python
AI Thread Summary
The discussion revolves around a Python function designed to draw houses on a graphics canvas using the GASP library. The issue arises when attempting to draw multiple houses by calling the draw_house(x, y) function twice. The first house is drawn successfully, but the second call does not execute because the function includes an update_when('key_pressed') command that closes the graphics canvas after the first house is drawn. This prevents any subsequent drawing commands from being executed. The solution involves restructuring the code to allow for multiple house drawings before closing the canvas, ensuring that both draw_house calls can be processed.
brushman
Messages
112
Reaction score
1
Basically, I have a function that draws a house. You enter (x, y) coordinates to pick where the house is drawn. However, it only let's me draw one house. Why can't I draw more then one house by calling the draw_house(x, y) function multiple times? Here's the code:

Code:
from gasp import *          # import everything from the gasp library

begin_graphics()            # open the graphics canvas


def draw_house(x, y):
    Box((x, y), 100, 100)         # the house
    Box((x+35, y), 30, 50)           # the door
    Box((x+20, y+60), 20, 20)           # the left window
    Box((x+60, y+60), 20, 20)           # the right window
    Line((x, y+100), (x+50, y+140))      # the left roof
    Line((x+50, y+140), (x+100, y+100))     # the right roof

    update_when('key_pressed')  # keep the canvas open until a key is pressed

draw_house(90, 90)
draw_house(200, 200)

end_graphics()              # close the canvas

In the code above, is draws the first house at (90, 90), but why doesn't it draw the second house?
 
Technology news on Phys.org
Caveat emptor: I don't know anything about python, so I might be way off in left field here.

The code starts off by the call to begin_graphics(), which opens the graphics canvas. Then there is the call to draw_house(90, 90), which causes the body of the draw_house function to execute, drawing a house whose opposite corners are at (90, 90) and (190, 190).

The last line of code in the draw_house function calls update_when, which, when a key is pressed, closes the graphics canvas (which I infer from the comment), so the call to draw_house(200, 200) fails, probably because the graphics canvas is closed.

That's what I think is going on.
 
Thanks, that was it.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
4
Views
1K
Replies
1
Views
4K
Replies
4
Views
4K
Replies
2
Views
2K
Replies
0
Views
865
Replies
2
Views
2K
Replies
7
Views
7K
Replies
5
Views
2K
Replies
1
Views
1K
Replies
2
Views
3K
Back
Top