Circles help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cid11
    New Member
    • Jun 2010
    • 10

    Circles help please

    atlast I have managed to get some working code but the first problem is that I have is taht.. when I call draw(2,4) I have a column of 2 circles and 4 rows and I would actually like it to be a clomun of 2 and row of 4. Secodly although my code works I have a main function and an input for an colour how could I fill the circles with the requested colour?

    like
    This is what i currently have
    00
    00
    00
    00

    I want it like

    0000
    0000

    Code:
    from graphics import *
    
    def main():
        colour = raw_input("Enter the colour: ")
    
    def drawCircle(win, centre, radius, colour, color):
        circle = Circle(centre, radius)
        circle.setFill(colour)
        circle.setOutline(color)
        circle.draw(win)
    
    def drawWindow(win, center, radius):
        drawCircle(win, center, radius, "white", "black")
    
    
    def draw(rows, columns):
          radius = 50
          diameter = 2 * radius
          width = rows*diameter+1
          height = columns*diameter+1
          win = GraphWin("", width, height )
          for x in range( rows ):
             for y in range( columns ):
                xPosition = radius + 2 + diameter * x
                yPosition = radius + 2 + diameter * y
                center = Point( xPosition, yPosition )
                drawWindow( win, center, radius )
                
    
    main()
  • cid11
    New Member
    • Jun 2010
    • 10

    #2
    I have managed to dorrect the first problem by changing the loop around.. but If someone could help me with the second one please..

    Comment

    • Glenton
      Recognized Expert Contributor
      • Nov 2008
      • 391

      #3
      Hi. Basically you want to pass the colour across as an argument. Something like this:

      Code:
      from graphics import *
       
      def main():
          colour = raw_input("Enter the colour: ")
          draw(4,4,colour)    #NOTE CHANGE
       
      def drawCircle(win, centre, radius, colour, color):
          circle = Circle(centre, radius)
          circle.setFill(colour)
          circle.setOutline(color)
          circle.draw(win)
       
      def drawWindow(win, center, radius, mycolour):  #NOTE CHANGE
          drawCircle(win, center, radius, mycolour, "black")  #NOTE CHANGE
       
       
      def draw(rows, columns,mycolour):  #NOTE CHANGE
            radius = 50
            diameter = 2 * radius
            width = rows*diameter+1
            height = columns*diameter+1
            win = GraphWin("", width, height )
            for x in range( rows ):
               for y in range( columns ):
                  xPosition = radius + 2 + diameter * x
                  yPosition = radius + 2 + diameter * y
                  center = Point( xPosition, yPosition )
                  drawWindow( win, center, radius,mycolour )  #NOTE CHANGE
       
       
      main()

      Comment

      Working...