turtle-graphics

How to start moving a turtle via space bar with python

走远了吗. 提交于 2020-05-29 11:54:46
问题 I'm trying to set up a simple turtle program in python where I can start moving the turtle with a press of the space bar, and he keeps moving until I hit the space bar again. I can get him to move a fixed distance with the space press but can't get it to continue. Here is what I'm working with: from turtle import * # PUT YOUR CODE HERE setup(800,600) home() pen_size = 2 color("blue") title("Turtle") speed("fastest") drawdist= 25 current_state = penup next_state = pendown #Button Instructions

How to start moving a turtle via space bar with python

不羁的心 提交于 2020-05-29 11:53:05
问题 I'm trying to set up a simple turtle program in python where I can start moving the turtle with a press of the space bar, and he keeps moving until I hit the space bar again. I can get him to move a fixed distance with the space press but can't get it to continue. Here is what I'm working with: from turtle import * # PUT YOUR CODE HERE setup(800,600) home() pen_size = 2 color("blue") title("Turtle") speed("fastest") drawdist= 25 current_state = penup next_state = pendown #Button Instructions

Python: How to reset the turtle graphics window

半腔热情 提交于 2020-05-25 05:13:57
问题 I am a making a blackjack game with cards using turtle and each time I play a hand turtle just prints over the last game instead of clearing the window. Is there a method that closes the window when it is called or is there another why of doing this? 回答1: With turtle, it is turtle.done() . If you are using graphics for python I recommend John Zelle's Graphics Library. To close a window use window.close() . I have linked the documentation for the graphics library in case you are interested.

Python time delay

十年热恋 提交于 2020-05-24 05:11:32
问题 Alright, I want to know how to delay a portion of a program without pausing the entire program. I'm not necessarily good at python so if you could give me a relatively simple answer if possible, that would be great. I want to have a turtle draw a circle on screen every time this function is called, this is what I have: import time from random import randint turtle5 = turtle.Turtle() coinx = randint(-200, 200) coiny = randint(-200, 200) turtle5.pu() turtle5.goto(coinx, coiny) turtle5.pd()

Python time delay

a 夏天 提交于 2020-05-24 05:10:03
问题 Alright, I want to know how to delay a portion of a program without pausing the entire program. I'm not necessarily good at python so if you could give me a relatively simple answer if possible, that would be great. I want to have a turtle draw a circle on screen every time this function is called, this is what I have: import time from random import randint turtle5 = turtle.Turtle() coinx = randint(-200, 200) coiny = randint(-200, 200) turtle5.pu() turtle5.goto(coinx, coiny) turtle5.pd()

How can I change the size of my python turtle window?

隐身守侯 提交于 2020-03-05 06:04:08
问题 I am currently trying to draw a Mandelbrot set in python with turtle. However, my problem has nothing to do with the Mandelbrot. I can't change the size of my turtle window. How can I do that? I tried to initialize a screen and set the screen size with the screensize method. Nothing changes if I do this. This is my code for drawing the set. I pasted the whole code because I don't know what I did wrong that the screen size doesn't change. from turtle import * height = 360 width = 360 screen =

How do i make colour detection in turtle

你。 提交于 2020-02-26 01:03:52
问题 I have a python turtle program which is displayed below. i want to be able to stop game when turtle touches black or touches line but i cant find any help online!!! import logging from datetime import datetime import time from turtle import * import winsound #while True: # player1 = input("enter player1 name\n") # break #while True: # player2 = input("enter player2 name\n") # print("Please click on window titled pacman") # break setup(600, 600) Screen() title("Rendering") horse2 = Turtle()

Building a built-in text field for turtle, while statement doesn't work

你离开我真会死。 提交于 2020-02-05 09:54:46
问题 I have built a text field module that has one problem: why does Python IDLE not work for while...break statements? Originally I didn't have a break statement and this didn't work so I added the break statement and the same problems persisted. This is a long script. You will need everything in it. Do not run in repl.it, as it will not run. However it does run on IDLE. https://repl.it/@SUPERMECHM500/TextField As commented in the script, the while statement at line 610 doesn't load on IDLE, and

Turtle graphics, draw a star?

穿精又带淫゛_ 提交于 2020-01-30 06:16:19
问题 I want to draw a filled-in star, such as: I have this code so far: def draw_star(size,color): count = 0 angle = 144 while count <= 5: turtle.forward(size) turtle.right(angle) count += 1 return draw_star(100,"purple") I want to fill in the star with whatever color the function is passed. How can I do this? 回答1: To get a 5 pointed star, you should draw 2 lines for each side. The angles need to add to 72 (360/5) import turtle def draw_star(size, color): angle = 120 turtle.fillcolor(color) turtle

Hilbert curve using turtle graphics and recursion

杀马特。学长 韩版系。学妹 提交于 2020-01-25 11:15:06
问题 I'm trying to implement an L-System generated Hilbert curve ,making use of python turtle graphics and recursion. My code seems to be working for the first two levels of recursion n=1 and n=2 but beyond that , the graphics just entangled (although I´m able to observe further modules within them), and I can´t seem to grasp what might be wrong here, do I need some intermediate steps to regenerate the Hilbert modules for deeper levels of recursion? Please see my code below , its relatively simple