| | |
five click house or newton's method
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Take a look at this thread and then do your own thinking:
http://www.daniweb.com/forums/thread...ve+click+house
I entered 'five click house' into the search option for this Python forum.
http://www.daniweb.com/forums/thread...ve+click+house
I entered 'five click house' into the search option for this Python forum.
Last edited by sneekula; Dec 28th, 2007 at 3:30 pm.
No one died when Clinton lied.
•
•
Join Date: Dec 2006
Posts: 1,065
Reputation:
Solved Threads: 299
The link
http://www.daniweb.com/forums/thread...ve+click+house yields a 404 File Not Found. Try one of these (and learn how to search)
http://www.daniweb.com/forums/thread94059.html
http://www.daniweb.com/forums/thread40738.html
http://www.daniweb.com/forums/thread...ve+click+house yields a 404 File Not Found. Try one of these (and learn how to search)
http://www.daniweb.com/forums/thread94059.html
http://www.daniweb.com/forums/thread40738.html
Last edited by woooee; Dec 28th, 2007 at 6:05 pm.
•
•
Join Date: Dec 2007
Posts: 13
Reputation:
Solved Threads: 0
Arrrrggghhh!! Where am I going wrong??
from graphics import *
distance = math.sqrt(square(p2.getX() - p1.getX()) + (square(p2.getY() - p2.getY()
def main():
win = GraphWin("house.py", 500, 500)
win.setCoords(0,0, 4,4)
p1=win.getMouse()
p2=win.getMouse()
p3=win.getMouse()
p4=win.getMouse()
p5=win.getMouse()
house = Rectangle(p1, p2)
house.setFill("Red")
house.draw(win)
win.getMouse()
#width one fifth of the area of house
door = Rectangle(p3)
doorwidth = door.setWidth(distance / 5.0)
door.setFill("Brown")
door.draw(win)
#window one forth of the door
window = Rectangle(p4)
window.setWidth(doorwidth/ 4.0)
window.setFill("White")
window.draw(win)
roof = Line(p5, p2)
roof.setFill("Black")
roof.draw(win)
clone = getP5(), getP2()
clone.draw(win) #have to flip this one
win.getMouse()
win.close()
main()
from graphics import *
distance = math.sqrt(square(p2.getX() - p1.getX()) + (square(p2.getY() - p2.getY()
def main():
win = GraphWin("house.py", 500, 500)
win.setCoords(0,0, 4,4)
p1=win.getMouse()
p2=win.getMouse()
p3=win.getMouse()
p4=win.getMouse()
p5=win.getMouse()
house = Rectangle(p1, p2)
house.setFill("Red")
house.draw(win)
win.getMouse()
#width one fifth of the area of house
door = Rectangle(p3)
doorwidth = door.setWidth(distance / 5.0)
door.setFill("Brown")
door.draw(win)
#window one forth of the door
window = Rectangle(p4)
window.setWidth(doorwidth/ 4.0)
window.setFill("White")
window.draw(win)
roof = Line(p5, p2)
roof.setFill("Black")
roof.draw(win)
clone = getP5(), getP2()
clone.draw(win) #have to flip this one
win.getMouse()
win.close()
main()
The problem is you aren't thinking it through: you are trying to use things before they exist.
To best help, you need to work on how to convert abstract stuff like "draw a door of a specific width" to the code that actually draws a door.
Do like I suggested in first thread woooee linked, and think about exactly what information
1. that you have
2. that you must calculate
in order to draw each part of the house.
Also, always get only the minimum amount of information you need from the user before drawing each part of the house. Again, read the link woooee listed.
You'll have to think about this a bit more, alas. Good luck.
To best help, you need to work on how to convert abstract stuff like "draw a door of a specific width" to the code that actually draws a door.
Do like I suggested in first thread woooee linked, and think about exactly what information
1. that you have
2. that you must calculate
in order to draw each part of the house.
Also, always get only the minimum amount of information you need from the user before drawing each part of the house. Again, read the link woooee listed.
You'll have to think about this a bit more, alas. Good luck.
Last edited by Duoas; Jan 3rd, 2008 at 7:43 pm.
•
•
Join Date: Dec 2007
Posts: 13
Reputation:
Solved Threads: 0
Something wrong with the door, says attribute not cloned or something, any ideas why??
from graphics import *
def main():
win = GraphWin("house.py", 500, 500)
win.setCoords(0,0, 4,4)
p1=win.getMouse()
p2=win.getMouse()
house = Rectangle(p1, p2)
house.setFill("Red")
house.draw(win)
win.getMouse()
p1.getX()
p2.getX()
distance=(p2.getX()-p1.getX())
#door
p3=win.getMouse()
p8=(p3.getX() + (distance / 5.0),p3.getY())
p7=(p8,p1.getY())
door=Rectangle(p3,p7)
door.draw(win)
win.getMouse()
win.close()
main()
from graphics import *
def main():
win = GraphWin("house.py", 500, 500)
win.setCoords(0,0, 4,4)
p1=win.getMouse()
p2=win.getMouse()
house = Rectangle(p1, p2)
house.setFill("Red")
house.draw(win)
win.getMouse()
p1.getX()
p2.getX()
distance=(p2.getX()-p1.getX())
#door
p3=win.getMouse()
p8=(p3.getX() + (distance / 5.0),p3.getY())
p7=(p8,p1.getY())
door=Rectangle(p3,p7)
door.draw(win)
win.getMouse()
win.close()
main()
Ah, yes, my mistake. You are using graphics.py. The type of thing matters. A point is an object, not a tuple.
So, you need to create a point using the appropriate constructor:
etc.
Sorry I missed that.
So, you need to create a point using the appropriate constructor:
p8 = Point( p3.getX() + (distance / 5.0), p3.getY() )etc.
Sorry I missed that.
Last edited by Duoas; Jan 11th, 2008 at 1:42 pm.
![]() |
Other Threads in the Python Forum
- Previous Thread: How to get modules working?
- Next Thread: Python to C, C++,Kylix,Delphi or whatever
Views: 2619 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for Python
alarm aliased application argv beginner casino character code command cursor cx-freeze definedlines development dictionary dynamic error event examples excel exe file filename float format ftp function google graphics gui homework ideas import input java launcher line linux list lists logging loop matching microphone mouse movingimageswithpygame newb number numbers obexftp output parsing path permissions phonebook port prime program programming projects py2exe pygame pyglet pyqt pysimplewizard python random recursion recursive refresh return reverse scrolledtext shebang simple skinning sprite ssh statistics string strings table terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode urllib urllib2 valueerror variable voip windows wxpython






