turtle-graphics

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

五迷三道 提交于 2019-12-07 16:03:27
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 that causes this discrepancy? (intellectual inquiry) How do I activate/stop self._newline()? (Necessary,

How to make items draw at the same time in python using turtle?

試著忘記壹切 提交于 2019-12-07 09:46:38
问题 I have a homework assignment, and I have to make four different turtles move like they are planets around the sun. I have it all written, its just a matter of making the turtles draw at the same time. I was wondering if there was a relatively easy way to make them start around the same time (within reason)? Anyway, here's the code: def planets(): """simulates motion of Mercury, Venus, Earth, and Mars""" import turtle mercury = turtle.Turtle() venus = turtle.Turtle() earth = turtle.Turtle()

How to close the Python turtle window after it does its code?

无人久伴 提交于 2019-12-06 21:17:57
问题 I'm working on a simple program in Python 3.5 that contains turtle graphics and I have a problem: after the turtle work is finished the user has to close the window manually. Is there any way to program the window to close after the turtle work is done? Any help is appreciated. 回答1: turtle.bye() , aka turtle.Screen().bye() , closes a turtle graphics window. Usually, a lack of turtle.mainloop() , or one of its variants, will cause the window to close because the program will exit, closing

How to draw a checkered flag to the Python screen?

一个人想着一个人 提交于 2019-12-06 16:32:54
问题 QUESTION: Implement the following pseudocode to draw a checkered flag to the screen. 1. Ask the user for the size of the checkered flag (n). 2. Draw an n x n grid to the screen. 3. For i = 0,2,4,...,62: 4. row = i // n 5. offset = row % 2 6. col = (i % n) + offset Please copy and paste the link see the ouput: http://www.awesomescreenshot.com/image/45977/12eaef67de44c2b291ecd47fe8d10135 I implemented the pseudocode, but I need some help. I am keep getting this error: row, col = findGrid(x)

How to stop turtle from drawing even with pen up?

烈酒焚心 提交于 2019-12-06 13:33:56
问题 I am using the turtle module in python. the problem is that whenever I have the turtle move i will draw even if the pen is up. for example if I run this program: import turtle turtle.penup turtle.goto(0,50) the turtle will still draw a line when it moves to (0,50) why is this and how can it be prevented? 回答1: It looks like you're not actually calling turtle.penup. Try this: import turtle turtle.penup() turtle.goto(0,50) 回答2: You have a typo, you aren't calling the penup method: import turtle

Snake game in Python using Turtle graphics

非 Y 不嫁゛ 提交于 2019-12-06 12:03:57
So I've been working on a few games in Python (battleships, tic-tac-toe etc.) and this week's project is Snake. I've got a basic set-up going; the snake can move and eats the food but I haven't programmed in collision detection or going off the edge yet. The problem is response time. If you run the code below, you'll see that the snake responds to key presses, but not for a couple of - I'll call them frames - after the press. I don't quite understand how the listen() method works; am I using it properly? If not, how should I use it, and if so, how can I fix the delay? I know about Pygame, but

Function missing 2 required positional arguments: 'x' and 'y'

拟墨画扇 提交于 2019-12-06 02:08:23
I am trying to write a Python turtle program that draws a Spirograph and I keep getting this error: Traceback (most recent call last): File "C:\Users\matt\Downloads\spirograph.py", line 36, in <module> main() File "C:\Users\matt\Downloads\spirograph.py", line 16, in main spirograph(R,r,p,x,y) File "C:\Users\matt\Downloads\spirograph.py", line 27, in spirograph spirograph(p-1, x,y) TypeError: spirograph() missing 2 required positional arguments: 'x' and 'y' >>> This is the code: from turtle import * from math import * def main(): p= int(input("enter p")) R=100 r=4 t=2*pi x= (R-r)*cos(t)-(r+p)

How Can I Fill These Squares in Turtle - Python

巧了我就是萌 提交于 2019-12-05 18:36: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 in range(numshapes): turtle.color(random.random(),random.random(), random.random()) x += 5 y += 5 turtle

Turtle Module in python not importing

依然范特西╮ 提交于 2019-12-05 16:08:09
this is my fist time using the turtle module in python but i can't seem to import it? Here's my code: from turtle import * pen1 = Pen() pen2 = Pen() pen1.screen.bgcolour("#2928A7") and here is the error I get: Traceback (most recent call last): File "C:\Python34\Python saves\turtle.py", line 2, in <module> from turtle import * File "C:\Python34\Python saves\turtle.py", line 5, in <module> pen1 = Pen() NameError: name 'Pen' is not defined Can anyone tell me what I did wrong? The problem is that you've named your program "turtle.py". So when Python sees the statement from turtle import * the

How to make items draw at the same time in python using turtle?

三世轮回 提交于 2019-12-05 15:52:08
I have a homework assignment, and I have to make four different turtles move like they are planets around the sun. I have it all written, its just a matter of making the turtles draw at the same time. I was wondering if there was a relatively easy way to make them start around the same time (within reason)? Anyway, here's the code: def planets(): """simulates motion of Mercury, Venus, Earth, and Mars""" import turtle mercury = turtle.Turtle() venus = turtle.Turtle() earth = turtle.Turtle() mars = turtle.Turtle() mercury.shape('circle') venus.shape('circle') earth.shape('circle') mars.shape(