Drwaing Circles?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

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

Drwaing Circles?

 
0
  #1
Nov 5th, 2009
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
  1. from graphics import *
  2. import math
  3. def drawCircle(win, centre, radius, colour):
  4. circle = Circle(centre, radius)
  5. circle.setFill(colour)
  6. circle.setWidth(2)
  7. circle.draw(win)
  8.  
  9. def drawTarget():
  10. win = GraphWin()
  11. centre = Point(100,100)
  12. drawCircle(win, centre, 40, "white")
  13. drawCircle(win, centre, 20, "blue")
  14. drawCircle(win, centre, 10, "black")
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,113
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: 944
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #2
Nov 5th, 2009
One eye has to be positioned center_left, the other center_right ...
  1. from graphics import *
  2. import math
  3.  
  4. def drawCircle(win, centre, radius, colour):
  5. circle = Circle(centre, radius)
  6. circle.setFill(colour)
  7. circle.setWidth(2)
  8. circle.draw(win)
  9.  
  10. def drawTarget():
  11. win = GraphWin()
  12. centre_left = Point(50,100)
  13. centre_right = Point(150,100)
  14. drawCircle(win, centre_left, 40, "white")
  15. drawCircle(win, centre_left, 20, "blue")
  16. drawCircle(win, centre_left, 10, "black")
  17. drawCircle(win, centre_right, 40, "white")
  18. drawCircle(win, centre_right, 20, "blue")
  19. drawCircle(win, centre_right, 10, "black")
  20. # this keeps the window up/open
  21. win.getMouse()
  22.  
  23. drawTarget()
For those who don't know ...
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"
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.
Last edited by vegaseat; Nov 5th, 2009 at 8:13 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 33
Reputation: jaison2 is an unknown quantity at this point 
Solved Threads: 1
jaison2 jaison2 is offline Offline
Light Poster
 
0
  #3
Nov 6th, 2009
but hw would you get them in the exact centre of the graphics window.. is this fine?

  1. from graphics import *
  2. import math
  3.  
  4. def drawCircle(win, centre, radius, colour):
  5. circle = Circle(centre, radius)
  6. circle.setFill(colour)
  7. circle.setWidth(2)
  8. circle.draw(win)
  9.  
  10. def drawTarget():
  11. win = GraphWin()
  12. centre_left = Point(60,100)
  13. centre_right = Point(140,100)
  14. drawCircle(win, centre_left, 40, "white")
  15. drawCircle(win, centre_left, 20, "blue")
  16. drawCircle(win, centre_left, 10, "black")
  17. drawCircle(win, centre_right, 40, "white")
  18. drawCircle(win, centre_right, 20, "blue")
  19. drawCircle(win, centre_right, 10, "black")
  20. # this keeps the window up/open
  21. win.getMouse()
  22.  
  23. drawTarget()
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,113
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: 944
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
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 ...
  1. from graphics import *
  2.  
  3. def drawCircle(win, centre, radius, colour):
  4. circle = Circle(centre, radius)
  5. circle.setFill(colour)
  6. circle.setWidth(2)
  7. circle.draw(win)
  8.  
  9. def drawTarget():
  10. w = 250
  11. h = 250
  12. win = GraphWin("Spooky Eyes", w, h)
  13. # center should be at 1/2 width and height
  14. center_w = w//2
  15. center_h = h//2
  16. centre_left = Point(center_w - 50, center_h)
  17. centre_right = Point(center_w + 50, center_h)
  18. drawCircle(win, centre_left, 40, "white")
  19. drawCircle(win, centre_left, 20, "blue")
  20. drawCircle(win, centre_left, 10, "black")
  21. drawCircle(win, centre_right, 40, "white")
  22. drawCircle(win, centre_right, 20, "blue")
  23. drawCircle(win, centre_right, 10, "black")
  24. # this keeps the window up/open
  25. win.getMouse()
  26.  
  27. drawTarget()
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 33
Reputation: jaison2 is an unknown quantity at this point 
Solved Threads: 1
jaison2 jaison2 is offline Offline
Light Poster
 
0
  #5
Nov 6th, 2009
thankyou.. that makes sense nw.. had to tweak code a bit more for my requirements.. thx a lot..
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 33
Reputation: jaison2 is an unknown quantity at this point 
Solved Threads: 1
jaison2 jaison2 is offline Offline
Light Poster
 
0
  #6
Nov 6th, 2009
can i quickly just ask a question, would we be able to shrink the code anymore if it was just for one eye?.. as it has repetitive code?
Last edited by jaison2; Nov 6th, 2009 at 11:15 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,113
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: 944
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #7
Nov 6th, 2009
One eye would make it simpler ...
  1. from graphics import *
  2.  
  3. def drawCircle(win, centre, radius, colour):
  4. circle = Circle(centre, radius)
  5. circle.setFill(colour)
  6. circle.setWidth(2)
  7. circle.draw(win)
  8.  
  9. def drawTarget():
  10. w = 250
  11. h = 250
  12. win = GraphWin("One Spooky Eye", w, h)
  13. # center should be at 1/2 width and height
  14. centre = Point(w//2, h//2)
  15. drawCircle(win, centre, 40, "white")
  16. drawCircle(win, centre, 20, "blue")
  17. drawCircle(win, centre, 10, "black")
  18. # click mouse to go on
  19. win.getMouse()
  20. win.close()
  21.  
  22. drawTarget()
You can streamline the whole thing a little more using a for loop ...
  1. # draw one spooky eye in the center of the drawing window
  2. # calculate the center from width, height
  3.  
  4. from graphics import *
  5.  
  6. def drawCircle(win, centre, radius, colour):
  7. circle = Circle(centre, radius)
  8. circle.setFill(colour)
  9. circle.setWidth(2)
  10. circle.draw(win)
  11.  
  12. def drawTarget():
  13. w = h = 250
  14. win = GraphWin("One Spooky Eye", w, h)
  15. # center should be at 1/2 width and height
  16. centre = Point(w//2, h//2)
  17. for radius, color in ((40,"white"), (20,"blue"), (10,"black")):
  18. drawCircle(win, centre, radius, color)
  19. # click mouse to go on
  20. win.getMouse()
  21. win.close()
  22.  
  23. drawTarget()
Stop before the code gets too cryptic and hard to read and understand.
Last edited by vegaseat; Nov 6th, 2009 at 4:21 pm. Reason: optimize
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC