Hi guys i was wondering how in python you invert this line as I have indicated. I have tried all sorts of mathemtical functions. I am using zelle graphics module. Currnetly I have produced lines going in one direction im trying to produce the same lines again but in the other direction i am sure its just a logical solution. Any help would be most appreciated. Thanks.

from graphics import *
 
def main():
    colour = raw_input("Enter the patch colour: ")
    win = GraphWin("Patch", 200, 200)
    drawPatch(win, 50, 50, colour)

def drawPatch(win, x, y, colour):
    for i in range(5):
        for j in range(5):
            if (i + j) % 2 == 0:
                topLeftX = x + i * 20
                topLeftY = y + j * 20
                topRightX = x + i * 20  #how to invert lines so they cross
                topRightY = y + j * 20 
                
                line1 = Line(Point(topLeftX, topLeftY),
                                      Point(topLeftX + 20, topLeftY + 20))
                line1.setFill(colour)
                line1.draw(win)
                #Next Lines accross
                line2 = Line(Point(topRightX, topRightY),
                                      Point(topRightX + 20, topRightY + 20))
                line2.setFill(colour)
                line2.draw(win)
                
                
                
main()

Hello, can you point me to zelle graphics module so I can try and trouble shoot this?

edit: found the module.

Edited 6 Years Ago by Mensa180: n/a

I changed lines 24&25. Well really only 25. If this is the result you desired...

line2 = Line(Point(topRightX, topRightY),
                                      Point(topRightY - 20, topRightX + 20))

Edited 6 Years Ago by Mensa180: n/a

Sorry to bring the thread back up again but Im not sure why the lines aren't going alway accross (the inverted ones.) Im not sure which variable i should edit to effect this. Whenever i edit the points its editing the angle. Any help would be muchly appreciated. Thank you.

from graphics import *
 
def main():
    colour = raw_input("Enter the patch colour: ")
    win = GraphWin("patch", 180, 180)
    drawLinesCrossPatch(win, 0, 0, colour)

def drawLinesCrossPatch(win, x, y, colour):
    for i in range(9):
        for j in range(9):
            if (i + j) % 2 == 0:
                topLeftX = x + i * 8
                topLeftY = y + j * 8
                topRightX = x + i * 8  
                topRightY = y + j * 8
                
                line1 = Line(Point(topLeftX, topLeftY),
                                      Point(topLeftX + 20, topLeftY + 20))
                line1.setFill(colour)
                line1.setWidth(2)
                line1.draw(win)
        
                line2 = Line(Point(topRightX, topRightY),
                                        Point(topRightX - 20, topRightY + 20))
                line2.setFill(colour)
                line2.setWidth(2)
                line2.draw(win)
main()
This question has already been answered. Start a new discussion instead.