turtle-graphics

How Can I Fill These Squares in Turtle - Python

杀马特。学长 韩版系。学妹 提交于 2019-12-22 10:27:13
问题 I am trying to fill the color in these squares: Right now the turtle only fills the corners of theses squares, not the entire square. Here is my code: import turtle import time import random print ("This program draws shapes based on the number you enter in a uniform pattern.") num_str = input("Enter the side number of the shape you want to draw: ") if num_str.isdigit(): squares = int(num_str) angle = 180 - 180*(squares-2)/squares turtle.up x = 0 y = 0 turtle.setpos(x,y) numshapes = 8 for x

Python Turtle window with scrollbars

 ̄綄美尐妖づ 提交于 2019-12-21 02:31:11
问题 I am new to Python, and have written a simple program in Python 2.7 using turtle graphics, which draws a fractal shape. The problem I have is that the turtle window doesn't have scrollbars, so if the shape is too large for the window, it is impossible to see all of it. Have googled but found no answer. Can anyone help? 回答1: Finally found some code at http://www.python-forum.de/viewtopic.php?f=1&t=24823&start=0 which provides a scrolled canvas for the turtle: import turtle import Tkinter as

How to save animated GIF images drawing in Python turtle module?

南楼画角 提交于 2019-12-20 06:37:07
问题 I am new to Python turtle module, I wrote a very easy code, like, from turtle import * import turtle forward(100) right(90) forward(200) circle(10) ts = turtle.getscreen() turtle.getcanvas().postscript(file = "duck.eps") I got a .eps image, it looks well, but what I want is an animated image in .gif . However, when I try to say, turtle.getcanvas().postscript(file = "duck.gif") I got the duck.gif, but I cannot open it !! What should I do now? 来源: https://stackoverflow.com/questions/40650099

Turtle Graphics - Extract Color from onscreenclick

回眸只為那壹抹淺笑 提交于 2019-12-20 06:26:45
问题 I am using Turtle Graphics in Python for a larger program. I am able to return the point that the user clicks on using turtle.onscreenclick However, I would like to extract the RGB color of the point that the user clicks on. Can this even be done in turtle graphics and how can this be accomplished? Thank you! import turtle # Global variables specifying the point clicked xclick = 0 yclick = 0 # Draw a rectangle that is red height = float(50) length = height *(1.9) length = round(length,2)

Python Turtle Speed

99封情书 提交于 2019-12-20 04:22:22
问题 My friend and I are working on a Python Game using turtles. Our issue is in the section where it defines the turtles. We are trying to speed each turtle up, but when we do, the default speed runs. Why is this issue occurring? import turtle turtle.setup(1000,1000) wn=turtle.Screen() wn.title("Snake Game!") #defines first turtle t1=turtle.Turtle() t1.pensize(2) t1.speed(3) t1.penup() t1.goto(0,100) t1.color("blue", "blue") t1.pendown() #defines second turtle t2=turtle.Turtle() t2.pensize(2) t2

PyCharm false syntax error using turtle

旧街凉风 提交于 2019-12-20 01:55:12
问题 The code below works perfectly, however, PyCharm complains about syntax error in forward(100) #!/usr/bin/python from turtle import * forward(100) done() Since turtle is a stanrd library I don't think that I need to do additional configuration, am I right? 回答1: The forward() function is made available for importing by specifying __all__ in the turtle module, relevant part from the source code: _tg_turtle_functions = [..., 'forward', ...] __all__ = (_tg_classes + _tg_screen_functions + _tg

Why is turtle lightening pixels?

為{幸葍}努か 提交于 2019-12-19 17:45:12
问题 My program for creating a Mandelbrot set has a bug: whenever the pen changes colors, and every 42nd pixel after that, is lighter. This is, rather coincidentally, a mandelbug (yes, I just learned that term), as it is inconsistent for many pixels near an "edge" (it might actually be blurred between the color it's supposed to be and the color the last, or next, pixel is supposed to be), but it's always the 42nd pixel after that one until the next color change. I am using OSX 10.6.8, PYTHON 2.7.

Python turtle set start position

风流意气都作罢 提交于 2019-12-19 11:33:12
问题 How do I set the startpos (topleft of my turtle square) when starting my code? And I don't mean that it starts from the middle and then goes to that position. I want the turtle to start there. 回答1: You can set the world coordinates to something else. For example, to start near the lower left corner, do: turtle.setworldcoordinates(-1, -1, 20, 20) This will make the entire window be 21x21 "units" and place the origin one unit from the bottom and left edges. Whatever position you command will

How do I make an object disappear after some time?

微笑、不失礼 提交于 2019-12-19 11:18:01
问题 I am trying to make a game where I can press space to shoot my bullet. There is a lot of lag. I am trying to figure out how to make the bullet disappear after it exits the screen. There is also a lot of lag. I am pretty sure the lag is from the bullet not resetting the screen after reaching the end. I imported time but I just can't seem to figure out how to use time. This is what I tried: # Importing GUI library import turtle import time bullets = [] bullets2 = [] # Set speed, GUI, creates

How do I make an object disappear after some time?

徘徊边缘 提交于 2019-12-19 11:17:26
问题 I am trying to make a game where I can press space to shoot my bullet. There is a lot of lag. I am trying to figure out how to make the bullet disappear after it exits the screen. There is also a lot of lag. I am pretty sure the lag is from the bullet not resetting the screen after reaching the end. I imported time but I just can't seem to figure out how to use time. This is what I tried: # Importing GUI library import turtle import time bullets = [] bullets2 = [] # Set speed, GUI, creates