By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,270 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,270 IT Pros & Developers. It's quick & easy.

Draw five times on one window with for loop

P: 1
Howdy,

I need to create a pair of circles, but have them drawn five times onto a single window. I am totally stumped. Here is what I have so far that prints one pair of circles:

Expand|Select|Wrap|Line Numbers
  1. def p91_clone():
  2.     win = GraphWin("cloning dots")
  3.     leftEye = Circle(Point(80,50),5)
  4.     leftEye.setFill('yellow')
  5.     leftEye.setOutline('red')
  6.     rightEye = leftEye.clone()
  7.     rightEye.move(20,0)
  8.     leftEye.draw(win)
  9.     rightEye.draw(win)
  10.  
  11.  
  12.  
  13.  
  14. p91_clone()

That program creates a pair of circles. I need five pairs of circles for my work. I know I use "for i in range (5):", but where
Oct 7 '11 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
Here's an example of creating graphic circles using a range that may help you:
Expand|Select|Wrap|Line Numbers
  1. from graphics import *
  2.  
  3. def main(size=40, rows=2, cols=5):
  4.     length = (cols-1)*size + size*2
  5.     height = (rows-1)*size + size*2
  6.     win = GraphWin("My Circle", length, height)
  7.     for row in range(rows):
  8.         for col in range(cols):
  9.             x = size+col*size
  10.             y = size+row*size
  11.             c = Circle(Point(x,y), size/2)
  12.             if row % 2:
  13.                 c.setFill('white')
  14.             else:
  15.                 c.setFill('red')
  16.             c.draw(win)
  17.     win.getMouse()
  18.     win.close()    
  19. main()
Oct 7 '11 #2

bvdet
Expert Mod 2.5K+
P: 2,851
Another example:
Expand|Select|Wrap|Line Numbers
  1. from graphics import *
  2.  
  3. def p91_clone(X):
  4.     leftEye = Circle(Point(20+x,50),5)
  5.     leftEye.setFill('yellow')
  6.     leftEye.setOutline('red')
  7.     rightEye = leftEye.clone()
  8.     rightEye.move(20,0)
  9.     leftEye.draw(win)
  10.     rightEye.draw(win)
  11.  
  12. win = GraphWin("cloning dots", width=220, height=100)
  13. for x in range(0, 200, 40):
  14.     p91_clone(x)
Oct 7 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.