Hey i'm trying to draw this patch in python 3.2. As you can see I can get it to draw the top row, but I cannot get it to truncate the rectangles at the left and right hand side, and I cannot get it to repeat itself...

Please Help :)!

from graphics import *
def drawPatch2():
    win = GraphWin("Patch 2", 500, 500)
    x = 100
    y = 100
    colour = "red"
    for i in range(5):
        for j in range(11):
            if j % 2 == 0:
                topLeftX = x + j * 10
                topLeftY = y
                rectangle = Rectangle(Point(topLeftX, topLeftY),
                                        Point(topLeftX + 10, topLeftY + 10))
                rectangle.setFill(colour)
                rectangle.draw(win)
            else:
                topLeftX = x + j * 10
                topLeftY = y
                rectangle = Rectangle(Point(topLeftX, topLeftY),
                                        Point(topLeftX + 10, topLeftY + 10))
                rectangle.draw(win)
            if row%2: 
                points_list = [ 0, points_list[1]+25, 25, points_list[3]+25]
            else: 
                points_list = [25, points_list[1]+25, 50, points_list[3]+25]
        for k in range(5):
            topLeftX = x + k * 20
            topLeftY = y
            rectangle = Rectangle(Point(topLeftX, topLeftY),
                                  Point(topLeftX + 20, topLeftY + 20))
            rectangle.draw(win)

Use a function to draw the rectangles. Within a loop, send the function the parameters for the smaller rectangle, then send the parameters for the 4 larger rectangles, and finally a smaller rectangle. It will draw a row for every iteration in the loop.

Thanks for getting back to me so quickly! Could you be more specific please? I need to be able to move the patch also by changing the x and y co-ordinates of the top left corner.

Cheers

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.