samedi 25 novembre 2017

graphics.py pattern calculation to flip coordinates

I am using graphics.py to create a pattern that will then be used as part of a tiling system to populate a window. The following code works, however, when X and Y are different values, one side of the pattern diverges. I have tried variants of this calculation and can't get it to work:

def drawLine(window, x1, y1, x2, y2, colour):
    line = g.Line(g.Point(x1, y1), g.Point(x2, y2)).draw(window)
    line.setFill(colour)

def draw_Patch_Final(window, pos_x, pos_y, colour):
    x = pos_x
    y = pos_y
    print(x, y)

    while x < pos_x + 100 and y < pos_y + 100:
        print(pos_y, x, (2 * pos_y) + 100 + x, pos_x + 100)

        # TODO Flip Coordinates for reverted pattern
        # If X and Y are different values, pattern diverges
        drawLine(window, pos_y, x, (2 * pos_y) + 100 - x, pos_x + 100, 
colour)
        drawLine(window, y, pos_x, pos_y + 100, (2 * pos_x) + 100 - x, 
colour)

        drawLine(window, y, pos_x, pos_y, x, colour)
        drawLine(window, pos_y + 100, x, y, pos_x + 100, colour)
        x += 20
    y += 20

This produces:

enter image description here

With the code calls of:

draw_Patch_Final(window, 50, 50, "Red")
draw_Patch_Final(window, 180, 180, "Black")
draw_Patch_Final(window, 300, 250, "Green")

As the green patch's x and y values are different it hinders me from calling the pattern at any given grid location. Any fixes for different X and Y values? The pattern draws in the correct location but wrong dimensions.

Aucun commentaire:

Enregistrer un commentaire