| | |
Drwaing Circles?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 33
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 Nov 5th, 2009
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; Nov 5th, 2009 at 8:13 pm.
May 'the Google' be with you!
•
•
Join Date: Nov 2009
Posts: 33
Reputation:
Solved Threads: 1
0
#3 Nov 6th, 2009
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 Nov 6th, 2009
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 Nov 6th, 2009
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; Nov 6th, 2009 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 |
Tag cloud for Python
abrupt ansi anti approximation assignment avogadro backend basic beginner binary bluetooth calculator character code customdialog decimals dictionaries dictionary drive dynamic examples excel exe file float format ftp function gnu graphics gui heads homework http ideas import input java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime program programming progressbar projects py2exe pygame pyqt python random recursion recursive refresh schedule scrolledtext sqlite ssh statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode update urllib urllib2 variable wikipedia windows write wxpython xlib






