| | |
Drwaing Circles?
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 28
Reputation:
Solved Threads: 1
hi, i want to be able to draw two eyes with are exactly the same in radius and colour etc next to eachother. So when i open the window the pair of eyes are there in the centre. I have managed to get one eye but i dnt have a clue to how to get one beside it, i am not sure hw to.. here is my code for the first eye and function should be calling the drawCircle six times.
please help
please help
Python Syntax (Toggle Plain Text)
from graphics import * import math def drawCircle(win, centre, radius, colour): circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) def drawTarget(): win = GraphWin() centre = Point(100,100) drawCircle(win, centre, 40, "white") drawCircle(win, centre, 20, "blue") drawCircle(win, centre, 10, "black")
0
#2 20 Days Ago
One eye has to be positioned center_left, the other center_right ...
For those who don't know ...
At this point in time module graphics.py works with Python2 only.
Install graphics.py in your working directory or the Lib/site-packages directory.
Python Syntax (Toggle Plain Text)
from graphics import * import math def drawCircle(win, centre, radius, colour): circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) def drawTarget(): win = GraphWin() centre_left = Point(50,100) centre_right = Point(150,100) drawCircle(win, centre_left, 40, "white") drawCircle(win, centre_left, 20, "blue") drawCircle(win, centre_left, 10, "black") drawCircle(win, centre_right, 40, "white") drawCircle(win, centre_right, 20, "blue") drawCircle(win, centre_right, 10, "black") # this keeps the window up/open win.getMouse() drawTarget()
•
•
•
•
John Zelle, Ph.D. teaches Python at Wartburg College
he is the author of graphics.py used by a number of schools instead
of Tkinter
Here is the graphics module (a thin wrapper for Tkinter) ...
http://mcsp.wartburg.edu/zelle/python/graphics.py
also has a nice documentation ...
http://mcsp.wartburg.edu/zelle/pytho...s/graphics.pdf
http://mcsp.wartburg.edu/zelle
Founded in 1852, Wartburg College is a nationally recognized selective
four-year liberal arts college of the Evangelical Lutheran Church in
America.
Wartburg College
100 Wartburg Blvd.
Waverly, IA 50677
(800) 772-2085
"Be Orange"
Install graphics.py in your working directory or the Lib/site-packages directory.
Last edited by vegaseat; 20 Days Ago at 8:13 pm.
May 'the Google' be with you!
•
•
Join Date: Nov 2009
Posts: 28
Reputation:
Solved Threads: 1
0
#3 20 Days Ago
but hw would you get them in the exact centre of the graphics window.. is this fine?
Python Syntax (Toggle Plain Text)
from graphics import * import math def drawCircle(win, centre, radius, colour): circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) def drawTarget(): win = GraphWin() centre_left = Point(60,100) centre_right = Point(140,100) drawCircle(win, centre_left, 40, "white") drawCircle(win, centre_left, 20, "blue") drawCircle(win, centre_left, 10, "black") drawCircle(win, centre_right, 40, "white") drawCircle(win, centre_right, 20, "blue") drawCircle(win, centre_right, 10, "black") # this keeps the window up/open win.getMouse() drawTarget()
0
#4 20 Days Ago
One way would be to say that the center should be at 1/2 width and height of the drawing window ...
python Syntax (Toggle Plain Text)
from graphics import * def drawCircle(win, centre, radius, colour): circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) def drawTarget(): w = 250 h = 250 win = GraphWin("Spooky Eyes", w, h) # center should be at 1/2 width and height center_w = w//2 center_h = h//2 centre_left = Point(center_w - 50, center_h) centre_right = Point(center_w + 50, center_h) drawCircle(win, centre_left, 40, "white") drawCircle(win, centre_left, 20, "blue") drawCircle(win, centre_left, 10, "black") drawCircle(win, centre_right, 40, "white") drawCircle(win, centre_right, 20, "blue") drawCircle(win, centre_right, 10, "black") # this keeps the window up/open win.getMouse() drawTarget()
May 'the Google' be with you!
0
#7 19 Days Ago
One eye would make it simpler ...
You can streamline the whole thing a little more using a for loop ...
Stop before the code gets too cryptic and hard to read and understand.
python Syntax (Toggle Plain Text)
from graphics import * def drawCircle(win, centre, radius, colour): circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) def drawTarget(): w = 250 h = 250 win = GraphWin("One Spooky Eye", w, h) # center should be at 1/2 width and height centre = Point(w//2, h//2) drawCircle(win, centre, 40, "white") drawCircle(win, centre, 20, "blue") drawCircle(win, centre, 10, "black") # click mouse to go on win.getMouse() win.close() drawTarget()
python Syntax (Toggle Plain Text)
# draw one spooky eye in the center of the drawing window # calculate the center from width, height from graphics import * def drawCircle(win, centre, radius, colour): circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) def drawTarget(): w = h = 250 win = GraphWin("One Spooky Eye", w, h) # center should be at 1/2 width and height centre = Point(w//2, h//2) for radius, color in ((40,"white"), (20,"blue"), (10,"black")): drawCircle(win, centre, radius, color) # click mouse to go on win.getMouse() win.close() drawTarget()
Last edited by vegaseat; 19 Days Ago at 4:21 pm. Reason: optimize
May 'the Google' be with you!
![]() |
Similar Threads
- Drawing circles and connecting them (C#)
- Drawing circles and connecting them (C#)
- circles erased ?? (C#)
- Document Root paths and circles (Search Engine Optimization)
- Circles .... Locus... (C++)
- Two red circles with X (Viruses, Spyware and other Nasties)
Other Threads in the Python Forum
- Previous Thread: List convert to string
- Next Thread: 1 digit number 2 to 3 digit number 002
| Thread Tools | Search this Thread |
abrupt accessdenied anti apache application approximation argv array beginner book builtin calculator change converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit enter examples file float format function gui heads homework import inches input java keyboard lapse launcher library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl python random recursion redirect remote reverse scrolledtext session simple software sprite statictext statistics string strings syntax table terminal text textarea threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable wordgame wxpython






