Hello, I am thinking if in python - is there a "check for color under you" command??? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Hello, I am thinking if in python - is there a "check for color under you" command??? (/thread-8357.html) |
Hello, I am thinking if in python - is there a "check for color under you" command??? - Ondrejoda - Feb-16-2018 Because I was tying to make a tron- like game... RE: Hello, I am thinking if in python - is there a "check for color under you" command??? - Larz60+ - Feb-16-2018 Attributes can always be checked. Color is an attribute. So the answer is yes. RE: Hello, I am thinking if in python - is there a "check for color under you" command??? - Ondrejoda - Feb-17-2018 So, can you please give me the command? Thanks. ;) RE: Hello, I am thinking if in python - is there a "check for color under you" command??? - Larz60+ - Feb-17-2018 There is no one command. It all depends on context. please show some code, and specifically what 'under you' pertains to. RE: Hello, I am thinking if in python - is there a "check for color under you" command??? - Ondrejoda - Feb-17-2018 Like, if a turtle is touching a pecific color. Code for the "tron" game(dosen't have the death function, please code it for me): import turtle troncycle = turtle.Turtle() troncycle1 = turtle.Turtle() screen = turtle.Screen() troncycle.pensize(1) troncycle.color("blue") troncycle.pencolor("blue") troncycle1.pensize(1) troncycle1.color("orange") troncycle1.pencolor("orange") def moveforward(): troncycle.forward(10) def moveforward1(): troncycle1.forward(10) def moveright(): troncycle.right(90) def moveleft(): troncycle.left(90) def moveright1(): troncycle1.right(90) def moveleft1(): troncycle1.left(90) troncycle.forward(1) troncycle1.forward(1) screen.onkeypress(moveright, "Right") screen.onkeypress(moveleft, "Left") screen.onkeypress(moveright1, "d") screen.onkeypress(moveleft1, "a") screen.onkeypress(moveforward1, "w") screen.onkeypress(moveforward, "Up") screen.listen() screen.mainloop() RE: Hello, I am thinking if in python - is there a "check for color under you" command??? - Larz60+ - Feb-17-2018 see: https://stackoverflow.com/questions/41624269/turtle-graphics-if-touching-colour RE: Hello, I am thinking if in python - is there a "check for color under you" command??? - Ondrejoda - Feb-17-2018 sorry, but I just don't understand it... RE: Hello, I am thinking if in python - is there a "check for color under you" command??? - Larz60+ - Feb-17-2018 Ok, I'm not a turtle guy, so you're going to have to play with this to get what you want, but here's a routine to get the canvas attributes: import turtle troncycle = turtle.Turtle() troncycle1 = turtle.Turtle() screen = turtle.Screen() troncycle.pensize(1) troncycle.color("blue") troncycle.pencolor("blue") troncycle1.pensize(1) troncycle1.color("orange") troncycle1.pencolor("orange") def moveforward(): troncycle.forward(10) def moveforward1(): troncycle1.forward(10) def moveright(): troncycle.right(90) def moveleft(): troncycle.left(90) def moveright1(): troncycle1.right(90) def get_color(): cv = screen.getcanvas() cvitems = cv.__dict__ for attribute in cvitems.items(): print(attribute) def moveleft1(): troncycle1.left(90) troncycle.forward(1) troncycle1.forward(1) screen.onkeypress(moveright, "Right") screen.onkeypress(moveleft, "Left") screen.onkeypress(moveright1, "d") screen.onkeypress(moveleft1, "a") screen.onkeypress(moveforward1, "w") screen.onkeypress(moveforward, "Up") get_color() screen.listen() screen.mainloop()which will show: so to access just the color, (once cv has been defined) x = cv.bgx = cv.bg print('the color of x is: {}'.format(x))
|