I need the function to display a set of eyes, so if i call the function
Eyes(3,4) a graphics window opens with exact dimesions for 4 coloumns and 2 rows of eyes...

from graphics import *
def drawCircle(win, centre, radius, colour):
    circle = Circle(centre, radius)
    circle.setFill(colour)
    circle.setWidth(2)
    circle.draw(win)

def drawEye():
    w = 250
    h = 250
    win = GraphWin(" 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()

drawEye()

def Eyes(rows, columns):
    for i in range( rows ):
        print colums * draweye
Eyes()

Dani AI

Generated

The goal is a single graphics window sized to hold an R x C grid of eyes, with each eye centered in its cell and scaled so no overlap occurs. started with a fixed-size window and a single eye; correctly pointed out overlap is the immediate problem; demonstrated a grid approach but swapped the row/column math when computing window width/height. The steps below give a clear, robust pattern to follow.

Compute a per-cell size and margins first, then derive window dimensions and eye radius from that cell. Use:

  • cell_width = cell_height = desired cell size (or calculate from desired eye size + spacing)
  • window_width = columns cell_width + 2 outer_margin
  • window_height = rows cell_height + 2 outer_margin
  • center_x = outer_margin + column_index * cell_width + cell_width / 2
  • center_y = outer_margin + row_index * cell_height + cell_height / 2
  • radius = int(min(cell_width, cell_height) * scale_factor) where scale_factor is < 0.5 (e.g., 0.4) to leave breathing room

Keep the semantics clear: the first argument (rows) controls vertical count (y), the second (columns) controls horizontal count (x). That avoids the common swap error seen in 's widths/heights.

Example layout (pseudo-code):

def Eyes(rows, cols, cell=100, margin=8):
    win_w = cols * cell + 2 * margin
    win_h = rows * cell + 2 * margin
    win = GraphWin("Eyes", win_w, win_h)
    for r in range(rows):
        for c in range(cols):
            cx = margin + c * cell + cell / 2
            cy = margin + r * cell + cell / 2
            radius = int(cell * 0.4)
            draw_eye(win, Point(cx, cy), radius)
    win.getMouse()
    win.close()

Troubleshooting: use integers for pixel positions (cast if necessary), call getMouse once after drawing the whole grid (not per eye), and clamp cell size if the computed window would exceed the screen. For the Zelle graphics module used here see .

Recommended Answers

All 4 Replies

Can you please be more clear, from what I understand you want 8 eyes total to be printed out on the screen, but with the radius size of 40 you have, all there is room for is a single eye before overlap.

Can you please be more clear, from what I understand you want 8 eyes total to be printed out on the screen, but with the radius size of 40 you have, all there is room for is a single eye before overlap.

...

Can you please be more clear, from what I understand you want 8 eyes total to be printed out on the screen, but with the radius size of 40 you have, all there is room for is a single eye before overlap.

well thts wht i need help with, the window should automatically change according to the number of eyes requested?

from graphics import *

def drawCircle(win, centre, radius, colour, color):
    circle = Circle(centre, radius)
    circle.setFill(colour)
    circle.setOutline(color)
    circle.draw(win)

def drawEye(win, center, radius):
    # center should be at half width and height
    drawCircle(win, center, radius, "white", "black")
    drawCircle(win, center, radius*0.5, "blue", "blue")
    drawCircle(win, center, radius*0.25, "black", "blue")

def Eyes(rows, columns):
      radius = 100
      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 )
            drawEye( win, center, radius )

Eyes(4,3)

is that it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.