| | |
Drawing stick figure?
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 28
Reputation:
Solved Threads: 1
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)
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)
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!
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!
•
•
Join Date: Dec 2006
Posts: 1,008
Reputation:
Solved Threads: 285
0
#3 25 Days Ago
And it's not tough to do. What version of Python are you using? Make sure you are using an integer for the radius.
Python Syntax (Toggle Plain Text)
import Tkinter root = Tkinter.Tk() root.title('Canvas') canvas = Tkinter.Canvas(root, width=450, height=450) canvas.create_oval(100,50,150,100, fill='gray90') x = 125 y = 175 stick = canvas.create_line(x, y-75, x, y) diff_x = 25 stick_leg1 = canvas.create_line(x, y, x-diff_x, y+50) stick_leg2 = canvas.create_line(x, y, x+diff_x, y+50) y=145 stick_arm1 = canvas.create_line(x, y, x-30, y-20) stick_leg2 = canvas.create_line(x, y, x+30, y-10) canvas.pack() root.mainloop()
•
•
•
•
But for some reasn (reason) my code doesnt (doesn't) seem to be working
Python Syntax (Toggle Plain Text)
def draw_circle(): x = input("please enter the radius of the circle: ") print "the radius is", x, type(x) centre= Point(100, 100) circle1 = Circle(centre, x) circle1.draw(win)
Last edited by woooee; 25 Days Ago at 7:28 pm.
Linux counter #99383
•
•
Join Date: Nov 2009
Posts: 12
Reputation:
Solved Threads: 5
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.
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)
def drawStickFigure(): from graphics import * win = GraphWin("Stick figure") head = Circle(Point(100, 60), 20).draw(win) body = Line(Point(100, 80), Point(100, 120)).draw(win) arms= Line(Point(60, 100), Point(140, 100)).draw(win) leg1 = Line(Point(100,120), Point(60,160)).draw(win) leg2 = Line(Point(100,120), Point(140,160)).draw(win) 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)
from graphics import * def drawCircle(): win = GraphWin("Stick figure",500,500) win.setCoords(-20,-20,20,20)#By setting the coords to this the center is at (0,0) x = input("please enter the radius of the circle: ") center = Point(0,0) circle1 = Circle(center, x) circle1.draw(win) drawCircle()
![]() |
Other Threads in the Python Forum
- Previous Thread: Reasons to extend Python with C
- Next Thread: neeed help!!!
| Thread Tools | Search this Thread |
abrupt alarm ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui halp heads homework http ideas import input java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib






