turtle-graphics

Get smooth motion by multi-threading Python turtle graphics

北城以北 提交于 2019-12-13 05:16:15
问题 This is my first question! I finished making a simple space invaders game in Python turtle graphics and noticed an annoying problem: the more objects I have on my screen, the slower the program runs. My friend told me that I need to use multi-threading so that all the commands will run concurrently, and that way, the game will run smooth. I added only the relevent code for my problem which is to move two enemy invaders from side to side of the screen. I think this will be enough to help me

Python: Drawing in Turtle window says 'Not Responding'

杀马特。学长 韩版系。学妹 提交于 2019-12-13 03:49:10
问题 I am trying to draw a square using Python turtle graphics using a for loop. I am able to draw the square but the turtle window says 'Not Responding'. Adding my code below: import turtle; Bq = turtle.Turtle() Bq.shape("turtle") for i in range(4): Bq.fd(100) Bq.lt(90) Bq.done() 回答1: Have you tried this one? I created a function named draw_square : def draw_square(some_turtle): for i in range(1, 5): some_turtle.forward(100) some_turtle.right(90) Then in your main function you can invoke the draw

Tic Tac Toe Game using Turtle

▼魔方 西西 提交于 2019-12-13 03:28:13
问题 This is for an extra credit assignment in Python. I've finished most until the last part where I have to determine the area of the tictactoe box chosen. Edit: Update, I can only detect diagonal boxes, used from combining both code reply's below. I can detect those 3 boxes but the rest still show as none and most logic is used with loop so I can understand where I am going wrong. import turtle from time import sleep import sys CURSOR_SIZE = 20 SQUARE_SIZE = 99 FONT_SIZE = 40 FONT = ('Arial',

Use a while loop to control game in Python turtle

故事扮演 提交于 2019-12-13 00:24:46
问题 I am trying to make a random game in which whichever character reaches the end first wins. I have basically the entire code made, but I need help with the end to determine who crosses the finish line first. So how would I do that? My code is: from turtle import Turtle from random import randint t = Turtle() t.speed(0) t.up() t.goto(-200,0) t.down() t.forward(900) t.up() t.goto(-200,100) t.down() t.forward(900) t.up() t.goto(-200,200) t.down() t.forward(1000) t.up() t.goto(-200,-100) t.down()

Change appearance of turtle

淺唱寂寞╮ 提交于 2019-12-12 19:43:14
问题 I am programming in python 3.2.2 turtle. I am able to make the turtle follow my cursor when I clack but now I have trouble changing the appearance of the turtle. In my code you will see a tank, and I want the image of the tank to be my turtle. Here is my code: #importing modules from turtle import Turtle from turtle import * #Setting up variables unVar1 = 25 unVar2 = 100 unVar3 = 90 unVar4 = 150 unVar5 = -30 unVar6 = 75 unVar7 = 50 screen = Screen() # create the screen #first part in making

Moving turtle according to the arrow keys

纵饮孤独 提交于 2019-12-12 19:36:42
问题 I am trying to make my turtle move according to the arrow keys on my keyboard. Does anybody know how to make a turtle in python 3.2.2 move according to the command of my arrow keys? By the way, my turtle is in the form of a tank if that affects anything. Here is my code: import turtle unVar1 = 25 unVar2 = 100 unVar3 = 90 unVar4 = 150 unVar5 = -30 unVar6 = 75 unVar7 = 50 def polySquare(t, x, y, length): t.goto(x, y) t.setheading(270) t.begin_poly() for count in range(4): t.forward(length) t

Don't understand this AttributeError: module 'turtle' has no attribute 'Turtle' [duplicate]

风格不统一 提交于 2019-12-12 19:14:09
问题 This question already has answers here : Importing installed package from script raises “AttributeError: module has no attribute” or “ImportError: cannot import name” (2 answers) Closed 7 months ago . #archimedes spiral by rays import math import turtle def spiral(t, a, b): diff=5 number=500 for i in range(number): t.penup() t.fd(a+b*i*diff*math.pi/180) t.pendown() t.lt(90) t.fd(10) t.bk(10) t.rt(90) t.penup() t.bk(a+b*i*diff*math.pi/180) t.lt(diff) bob=turtle.Turtle() bob.speed(1000) spiral

How to read pixel colours using Python turtle.py

家住魔仙堡 提交于 2019-12-12 17:27:07
问题 I'm preparing exercises for school classes involving Python's turtle library. The students are already drawing terrific pictures, but I want them to be able to detect existing pictures and colours in order to modify the behaviour of their program. For example I would like to provide them with code which draws a maze using turtle, and then they can write the code to navigate the turtle around the maze (don't worry, I'll start simpler). Is there a way to detect the colour of the pixels already

Pick up pen when turtle is not at coordinate

一笑奈何 提交于 2019-12-12 16:19:57
问题 My program draws images that already have coordinates attach to them. I want my turtle to be able to pick up the pen when not at the coordinate. Right now the turtle continues to write before getting to the coordinate. code: with open('output.txt', 'r') as f: data = ast.literal_eval(f.read()) tony = turtle.Turtle() for z in data: position = tony.pos() tony.goto(z) output 1: As you can see the turtle continues to draw even before getting to the coordinate. Here's something I think may work but

Turtle make triangle different color

旧城冷巷雨未停 提交于 2019-12-12 06:56:36
问题 Hi guys I'm trying to replicate this image: It's almost done I just have one issue, where the triangle is supposed to be yellow it isn't seeming to work. Mine: Code: fill(True) fillcolor('green') width(3) forward(200) left(120) forward(200) left(120) forward(200) fill(False) right(180) forward(100) right(60) forward(100) left(120) fill(True) fillcolor('red') forward(200) left(120) forward(200) left(120) forward(200) fill(False) Any help would be appreciated. (I can't add yellow to the second