turtle-graphics

How to initialize multiple turtles in Python with classes

 ̄綄美尐妖づ 提交于 2021-01-28 06:59:26
问题 I am a beginner at Python and I'm new to Stack Exchange. I'm trying to write a program that has 5 turtles moving within a square. I've got code that does what I want, but it's tedious and I'd like to initialize all my turtles using classes instead of doing it one by one. I just want them to start out at random coordinates and with a random heading. The problems with my code: Only one turtle is shown on screen. Two are defined in the code below. The turtle's heading and coordinates aren't

Rounded edge rectangles with Python turtle

為{幸葍}努か 提交于 2021-01-28 06:09:43
问题 Is there another way to add a rounded edge to square/rectangle shapes apart from drawing a circle and drawing a square over it? I am trying to make the YouTube logo using only Python turtle. I didn't use absolute position functions like home(), as I need replicate this at different locations later on. from turtle import * def placement(): penup() setheading(0) forward(5) setheading(90) forward(20) setheading(0) pendown() def youtube(): placement() #Custom Starting poisition hideturtle()

Turtle graphic begin_fill() function does not work correctly on MAC

蹲街弑〆低调 提交于 2021-01-27 23:18:48
问题 I am trying to draw a "Yellow" star by using module turtle. When I run my program on Windows OS, it works correctly. However, when I run it on macOS, the graphic is wrong. Result on macOS Result on Windows OS import turtle # Setup a screen and a turtle win = turtle.Screen() bob = turtle.Turtle() # set the background color for the flag win.bgcolor("red") # Draw a star # change the turtle color to yellow bob.color("yellow") # to center we have to go backward for half of a side length bob.penup(

Turtle graphic begin_fill() function does not work correctly on MAC

a 夏天 提交于 2021-01-27 21:55:43
问题 I am trying to draw a "Yellow" star by using module turtle. When I run my program on Windows OS, it works correctly. However, when I run it on macOS, the graphic is wrong. Result on macOS Result on Windows OS import turtle # Setup a screen and a turtle win = turtle.Screen() bob = turtle.Turtle() # set the background color for the flag win.bgcolor("red") # Draw a star # change the turtle color to yellow bob.color("yellow") # to center we have to go backward for half of a side length bob.penup(

Filling rectangles with colors in python using turtle

无人久伴 提交于 2021-01-27 11:22:40
问题 How can I draw a rectangle where: the smallest is 5 in height and each consecutive rectangle adds the first rectangles height, i.e. 5, 10, 15, …. The width of each rectangle is 200. The color of the lines are blue and the fill color, from top to bottom is grey0, grey14, grey28, …. How can I do this and make sure the picture fits onto the screen? (Each new rectangle goes below the previous one) This is what I have so far, but I don't know how I can fill it: import turtle def rectangle(t, l, w)

Python Terminator Error

馋奶兔 提交于 2021-01-19 09:37:29
问题 I'm working on a Python project with a friend of mine for school. We have imported Turtle and Math. My problem is that when I use the "Esc" button to close the window, I get an error saying "Terminator Error"... I've asked the teachers but even they don't know what the problem is because they aren't very familiar with Turtle. Could any of you guys tell me what I'm doing wrong ? btw : I'm using EduPython on Windows 10. Here is the code : import turtle import math fn = turtle.Screen() fn

Python Terminator Error

时光总嘲笑我的痴心妄想 提交于 2021-01-19 09:37:06
问题 I'm working on a Python project with a friend of mine for school. We have imported Turtle and Math. My problem is that when I use the "Esc" button to close the window, I get an error saying "Terminator Error"... I've asked the teachers but even they don't know what the problem is because they aren't very familiar with Turtle. Could any of you guys tell me what I'm doing wrong ? btw : I'm using EduPython on Windows 10. Here is the code : import turtle import math fn = turtle.Screen() fn

Problem with onkeypress() and listen() in Python Turtle

北城以北 提交于 2021-01-05 13:14:59
问题 I have a problem with one function. I use Python 3.7, and when I try to use the onkeypress() function, nothing happens. I try to check it, but the turtle module doesn't react when I press keys. I try to move my paddle up using the 'w' key. But it doesn't work. Below are my *.py files: main.py import elements import turtle #Windows settings window = turtle.Screen() window.title("Pong game by Kosa") window.bgcolor('black') window.setup(width=800, height=600) window.tracer(0) paletka_1 =

name 'turtle' is not defined on line 4 in main.py

混江龙づ霸主 提交于 2021-01-05 07:16:47
问题 Sorry for dumb question, new to python. I have the following code, running python 3.7: from turtle import * color('blue', 'red') turtle.pu() turtle.goto(0,0) turtle.pd() begin_fill() forward(55) left(90) forward(110) When I click run, it says I have an error on line three and four, but I can't figure out what's wrong. I tried searching everywhere but I can't find anything that helps me figure out what I did wrong. 回答1: You need to create an instance of a Turtle object to use it from turtle

Point a Python Turtle towards certain coordinates

筅森魡賤 提交于 2020-12-26 09:23:05
问题 Is there any way to point the Turtle towards certain coordinates Any help with this with be appreciated. 回答1: What you're looking for is the turtle.towards() method, which returns the angle from the turtle's position to a target. It can be used in combination with the turtle.setheading() method: turtle.setheading(turtle.towards(x, y)) The turtle.towards() method is flexible with respect to it arguments. It can take separate x and y values, a combined (x, y) tuple, or another turtle whose