0

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)
Attachments patch.jpg 29.04 KB
2
Contributors
2
Replies
7
Views
5 Years
Discussion Span
Last Post by theraggamuffin
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.