944,148 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 797
  • Python RSS
Nov 1st, 2009
0

Drawing stick figure?

Expand Post »
well basically i have to draw a stick figure for which is my first question... i cant figure out how to draw a horizontal line and also a line at a angle for the legs... here is the code for the first one

def drawStickFigure():
from graphics import *
win = GraphWin("Stick figure")
head = Circle(Point(100, 60), 20)
head.draw(win)
body = Line(Point(100, 80), Point(100, 120))
body.draw(win)
arms= Line(Point(0, 100), Point(0, 100))
arms.draw(win)

for the second question i have to draw a circle which is at the centre of the graphics window. the user inputs the radius of the circle and the circle should come. But for some reasn my code doesnt seem to be working please help

def drawCircle():
x = input("please enter the radius of the circle: ")
centre= Point(100, 100)
circle1 = Circle(centre, x)
circle1.draw(win)
Reputation Points: 10
Solved Threads: 2
Light Poster
jaison2 is offline Offline
33 posts
since Nov 2009
Nov 1st, 2009
0
Re: Drawing stick figure?
I hope you are not stuck with an outdated module like graphics, which is a wrapper for Tkinter, written by some guy to sell his book. You are much better off using the Tkinter GUI toolkit directly and learn something you can actually use later on.

To say it bluntly, the module graphics is all candy and no meat!
Last edited by vegaseat; Nov 1st, 2009 at 5:51 pm. Reason: candy
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Nov 1st, 2009
0
Re: Drawing stick figure?
And it's not tough to do.
Python Syntax (Toggle Plain Text)
  1. import Tkinter
  2.  
  3. root = Tkinter.Tk()
  4. root.title('Canvas')
  5. canvas = Tkinter.Canvas(root, width=450, height=450)
  6.  
  7. canvas.create_oval(100,50,150,100, fill='gray90')
  8.  
  9. x = 125
  10. y = 175
  11. stick = canvas.create_line(x, y-75, x, y)
  12.  
  13. diff_x = 25
  14. stick_leg1 = canvas.create_line(x, y, x-diff_x, y+50)
  15. stick_leg2 = canvas.create_line(x, y, x+diff_x, y+50)
  16.  
  17. y=145
  18. stick_arm1 = canvas.create_line(x, y, x-30, y-20)
  19. stick_leg2 = canvas.create_line(x, y, x+30, y-10)
  20.  
  21. canvas.pack()
  22. root.mainloop()
Quote ...
But for some reasn (reason) my code doesnt (doesn't) seem to be working
What version of Python are you using? Make sure you are using an integer for the radius.
Python Syntax (Toggle Plain Text)
  1. def draw_circle():
  2. x = input("please enter the radius of the circle: ")
  3. print "the radius is", x, type(x)
  4. centre= Point(100, 100)
  5. circle1 = Circle(centre, x)
  6. circle1.draw(win)
Last edited by woooee; Nov 1st, 2009 at 7:28 pm.
Reputation Points: 741
Solved Threads: 694
Nearly a Posting Maven
woooee is offline Offline
2,314 posts
since Dec 2006
Nov 1st, 2009
0
Re: Drawing stick figure?
He is using the graphics file from a python book. Your code for the stick figure would look like this. The Line command uses two points(x,y) for the starting point and (x,y) for the ending point.
Python Syntax (Toggle Plain Text)
  1. def drawStickFigure():
  2. from graphics import *
  3. win = GraphWin("Stick figure")
  4. head = Circle(Point(100, 60), 20).draw(win)
  5. body = Line(Point(100, 80), Point(100, 120)).draw(win)
  6. arms= Line(Point(60, 100), Point(140, 100)).draw(win)
  7. leg1 = Line(Point(100,120), Point(60,160)).draw(win)
  8. leg2 = Line(Point(100,120), Point(140,160)).draw(win)
  9. drawStickFigure()

For the circle you need to use setCoords to make sure that it is in the center of the window.
Python Syntax (Toggle Plain Text)
  1. from graphics import *
  2. def drawCircle():
  3. win = GraphWin("Stick figure",500,500)
  4. win.setCoords(-20,-20,20,20)#By setting the coords to this the center is at (0,0)
  5. x = input("please enter the radius of the circle: ")
  6. center = Point(0,0)
  7. circle1 = Circle(center, x)
  8. circle1.draw(win)
  9. drawCircle()
Reputation Points: 24
Solved Threads: 22
Junior Poster in Training
tbone2sk is offline Offline
64 posts
since Nov 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Reasons to extend Python with C
Next Thread in Python Forum Timeline: neeed help!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC