turtle-graphics

Reinforcement learning algorithm using turtle graphics not functioning

梦想与她 提交于 2019-12-25 00:58:06
问题 Currently trying to implement a Q table algorithm in my environment created using turtle graphics. When i try running the algorithm which uses Q learning I get an error stating: File "<ipython-input-1-cf5669494f75>", line 304, in <module> rl() File "<ipython-input-1-cf5669494f75>", line 282, in rl A = choose_action(S, q_table) File "<ipython-input-1-cf5669494f75>", line 162, in choose_action state_actions = q_table.iloc[state, :] File "/Users/himansuodedra/anaconda3/lib/python3.6/site

How to detect if turtle is in the radius of x & y and then do something?

我的未来我决定 提交于 2019-12-24 23:30:02
问题 Currently, I'm trying to make a game and in the game I would like it so if the character is on top of an object, it picks it up. This is what I have so far: import turtle import time default = turtle.clone() scar = turtle.clone() def pickupScar(): if default.distance(-7,48) > 5.0: default.changeshape('defaultscar.gif') wn = turtle.Screen() wn.setup(500,500) wn.bgpic('TrumpTowers.gif') wn.register_shape('default.gif') wn.register_shape('scar.gif') wn.register_shape('defaultscar.gif') turtle

Getting “maximum recursion depth exceeded” with Python turtle mouse move

北城以北 提交于 2019-12-24 21:23:21
问题 This code should utilize mouse motion events to draw a dot at the current mouse position: import turtle def motion(event): x, y = event.x, event.y turtle.goto(x-300, 300-y) turtle.dot(5, "red") turtle.pu() turtle.setup(600, 600) turtle.hideturtle() canvas = turtle.getcanvas() canvas.bind("<Motion>", motion) The code works as expected for a few seconds or longer if the mouse is moved very slowly. Then it throws: >>> ====================== RESTART: C:/code/turtle_move.py ======================

Create more than two turtles and moving them

故事扮演 提交于 2019-12-24 19:46:37
问题 How to make few turtles in a screen and make them move one at once? 回答1: You can use turtle.Turtle() to create many turtles and then you can use it one by one to make small move. Turtles will move almost at the same time. import turtle t1 = turtle.Turtle() t2 = turtle.Turtle() for x in range(36): # first turtle makes small move t1.left(10) t1.forward(10) # second turtle makes small move t2.right(10) t2.forward(10) turtle.done() If you want to move all the time (and do other things at the same

Turtle-graphics keypress event not repeating

寵の児 提交于 2019-12-24 09:37:27
问题 The following code behaves differently in different environments. On my Windows machine (Windows 10, Python 3.6), each keypress creates a response and then nothing happens until I press a key again. On "Python Trinkets" (https://trinket.io/python) I don't need to repeat the keypress, as holding the key down creates repeat events. I know that the Trinket version is a JS implementation, but does that explain the difference entirely? Would the program behave the same on Linux or OS? More

How to move multiple turtles at the same time in python?

情到浓时终转凉″ 提交于 2019-12-24 07:13:02
问题 Hi I have an assignment which is asked to set two turtles in a race track(same size but separate track). I can able to make them move but the second one move only when the first one moved a half of the track. I'm not sure how to make the turtles move at the same time. Here is my code, please help me if you have any idea about it. Thank you! import turtle import random import time wn = turtle.Screen() wn.bgcolor("lightgreen") t = turtle.Turtle() t.shape('turtle') t.color('red') t2 = turtle

Python Turtle unit of measurement

时光总嘲笑我的痴心妄想 提交于 2019-12-23 07:00:30
问题 When we instantiate a turtle object, we can draw a circle. I wonder about the radius parameter of the circle() method. import turtle myTurtle = turtle.Turtle() myTurtle.circle(50) What is the unit of measurement of this parameter? Does the radius equal to 50 pixels or 50 inches? 回答1: the documentation for turtle.setup indicates that size parameters, if expressed as integers, are pixels, if expressed as floats, are fractions of the screen. 回答2: As you can see from the first few lines from the

Multithreading With Python Turtle

与世无争的帅哥 提交于 2019-12-23 01:57:10
问题 Is there a way to use two turtles at the same time to draw two circles at the same time in one window? I tried this code but two turtles draw in separated windows from multiprocessing import Process import turtle t1=turtle.Turtle() t2=turtle.Turtle() def tes1(): t1.speed(0) i=0 while i < 360: t1.forward(1) t1.left(1) i+=1 def tes2(): t2.speed(0) i=0 while i < 360: t2.forward(1) t2.right(1) i+=1 if __name__ == '__main__': p1 = Process(target=tes1) p1.start() p2 = Process(target=tes2) p2.start(

How do I control turtle's self._newline()?

佐手、 提交于 2019-12-23 01:45:30
问题 I need to figure out how to control the self._newline(), in turtle.py. I found out about this during my python Mandelbrot set program, when it started doing weird things; see Why is turtle lightening pixels? for more details. However, when I tried to make an extremely similar program that graphed the tangent of complex numbers, the same thing did not happen...but the program slowed down considerably over time. Basically, I am asking 3 questions: What is the difference between these programs

Problem when resizing and saving a turtle screen

假装没事ソ 提交于 2019-12-22 21:21:54
问题 So I could save a big drawing and see its full size in an image visualizer, I resized my turtle window bigger then my monitor size. But the saved image is not being resized, so the drawing is being truncated: from turtle import Screen, Turtle import random screen = Screen() screen.setup(width=1200, height=2700, startx=None, starty=None) t = Turtle(visible=False) t.speed('fastest') # because I have no patience t2 = Turtle(visible=False) t2.speed('fastest') # because I have no patience t3 =