Draw five times on one window with for loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sammyj
    New Member
    • Oct 2011
    • 1

    Draw five times on one window with for loop

    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:

    Code:
    def p91_clone():
        win = GraphWin("cloning dots")
        leftEye = Circle(Point(80,50),5)
        leftEye.setFill('yellow')
        leftEye.setOutline('red')
        rightEye = leftEye.clone()
        rightEye.move(20,0)
        leftEye.draw(win)
        rightEye.draw(win)
        
       
        
    
    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
    Last edited by Meetee; Oct 7 '11, 06:02 AM. Reason: code tags added
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Here's an example of creating graphic circles using a range that may help you:
    Code:
    from graphics import *
    
    def main(size=40, rows=2, cols=5):
        length = (cols-1)*size + size*2
        height = (rows-1)*size + size*2
        win = GraphWin("My Circle", length, height)
        for row in range(rows):
            for col in range(cols):
                x = size+col*size
                y = size+row*size
                c = Circle(Point(x,y), size/2)
                if row % 2:
                    c.setFill('white')
                else:
                    c.setFill('red')
                c.draw(win)
        win.getMouse()
        win.close()    
    main()

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      Another example:
      Code:
      from graphics import *
      
      def p91_clone(X):
          leftEye = Circle(Point(20+x,50),5)
          leftEye.setFill('yellow')
          leftEye.setOutline('red')
          rightEye = leftEye.clone()
          rightEye.move(20,0)
          leftEye.draw(win)
          rightEye.draw(win)
       
      win = GraphWin("cloning dots", width=220, height=100)
      for x in range(0, 200, 40):
          p91_clone(x)

      Comment

      Working...