Drawing stick figure?

Thread Solved

Join Date: Nov 2009
Posts: 28
Reputation: jaison2 is an unknown quantity at this point 
Solved Threads: 1
jaison2 jaison2 is offline Offline
Light Poster

Drawing stick figure?

 
0
  #1
25 Days Ago
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)
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,983
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 926
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #2
25 Days Ago
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; 25 Days Ago at 5:51 pm. Reason: candy
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,008
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 285
woooee woooee is offline Offline
Veteran Poster
 
0
  #3
25 Days Ago
And it's not tough to do.
  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()
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.
  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; 25 Days Ago at 7:28 pm.
Linux counter #99383
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 12
Reputation: tbone2sk is an unknown quantity at this point 
Solved Threads: 5
tbone2sk tbone2sk is offline Offline
Newbie Poster
 
0
  #4
25 Days Ago
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.
  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.
  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()
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC