five click house or newton's method

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2007
Posts: 13
Reputation: gusbear is an unknown quantity at this point 
Solved Threads: 0
gusbear gusbear is offline Offline
Newbie Poster

five click house or newton's method

 
0
  #1
Dec 27th, 2007
can someone please post the correct method of the five click house or the newton's method from zelles book, reward promised,it is xmas?? thanks a mill need this for xmas tests!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,297
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 178
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: five click house or newton's method

 
0
  #2
Dec 28th, 2007
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.
Last edited by sneekula; Dec 28th, 2007 at 3:30 pm.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,065
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 299
woooee woooee is offline Offline
Veteran Poster

Re: five click house or newton's method

 
0
  #3
Dec 28th, 2007
Last edited by woooee; Dec 28th, 2007 at 6:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 13
Reputation: gusbear is an unknown quantity at this point 
Solved Threads: 0
gusbear gusbear is offline Offline
Newbie Poster

Re: five click house or newton's method

 
0
  #4
Jan 3rd, 2008
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()
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: five click house or newton's method

 
0
  #5
Jan 3rd, 2008
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.
Last edited by Duoas; Jan 3rd, 2008 at 7:43 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 13
Reputation: gusbear is an unknown quantity at this point 
Solved Threads: 0
gusbear gusbear is offline Offline
Newbie Poster

Re: five click house or newton's method

 
0
  #6
Jan 10th, 2008
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()
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: five click house or newton's method

 
0
  #7
Jan 10th, 2008
You're doing well; you've just made a simple mistake.

p8 is the upper-left corner of the door
p7 should be the lower-right corner of the door

the mistake is when you say
p7=(p8,

p8 is a point, not a number...

You'll need to add something to p8's x coordinate.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 13
Reputation: gusbear is an unknown quantity at this point 
Solved Threads: 0
gusbear gusbear is offline Offline
Newbie Poster

Re: five click house or newton's method

 
0
  #8
Jan 11th, 2008
p3=win.getMouse()
p8=(p3.getX() + (distance / 5.0),p3.getY())
p7=(p8.getX(),p1.getY())
door=Rectangle(p3,p7)
door.draw(win)

then i get this :"p7=(p8.getX(),p1.getY())
AttributeError: 'tuple' object has no attribute 'getX'
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: five click house or newton's method

 
0
  #9
Jan 11th, 2008
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:
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 13
Reputation: gusbear is an unknown quantity at this point 
Solved Threads: 0
gusbear gusbear is offline Offline
Newbie Poster

Re: five click house or newton's method

 
0
  #10
Jan 11th, 2008
thanks it worked, do you know how to create a square by clicking in the middle to produce it??
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum


Views: 2619 | Replies: 10
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC