turtle-graphics

Is there any way to resize a gif shape with turtle in Python?

廉价感情. 提交于 2019-12-02 08:06:05
I'm using turtle to make a little game and realized I could use image files with turtle.registershape(filename) . I know you can resize the default shapes with turtle.shapesize or turtle.resizemode("auto") and changing pensize , but is there any way to resize a gif file using these methods? import turtle turtle.addshape("example.gif") t = turtle.Turtle() t.shape("example.gif") t.resizemode("auto") t.pensize(24) t.stamp() turtle.exitonclick() I want something like this to work, but the turtle is displayed normally, not resized. I reviewed the applicable turtle code and I believe the answer is,

Difference between turtle and Turtle?

橙三吉。 提交于 2019-12-02 07:54:04
问题 How turtle and Turtle is diffrent from each other in python 2.7 ? import turtle star = turtle.Turtle() for i in range(50): star.forward(50) star.right(144) turtle.done() 回答1: The turtle module is unusual. To make it easier for beginning programmers, all methods of the Turtle class are also available as top level functions that operate on the default (unnamed) turtle instance. All methods of the Screen class are also available as top level functions that operate on the default (sole) screen

Logic error in python turtle

会有一股神秘感。 提交于 2019-12-02 06:30:26
I am coding in python 3.2 turtle and I have this beautiful drawing of a tank. and I know how to move it left and write. However, when trying to make the tank move up and down. I am faced with the problem that it goes up but if I let go and press the up button again. It turns to the left. It might be hard to explain so I included code. """ Programmer: Bert Tank Run 1 """ #------------------------------------------------------------------------------ #Importing random modules geddit from turtle import * from turtle import Turtle import turtle import random #Welcome Statement and story input(

How to bind several key presses together in turtle graphics?

情到浓时终转凉″ 提交于 2019-12-02 05:24:43
问题 I'm trying to make a connect-the-dot python game. I want the game to register 2 button presses. Example: if the user presses Up and Right arrow key, the turtle goes 45 degrees north east. here is my code: import turtle flynn=turtle.Turtle() win=turtle.Screen() win.bgcolor("LightBlue") flynn.pensize(7) flynn.pencolor("lightBlue") win.listen() def Up(): flynn.setheading(90) flynn.forward(25) def Down(): flynn.setheading(270) flynn.forward(20) def Left(): flynn.setheading(180) flynn.forward(20)

Reading two separate values in one line in python

前提是你 提交于 2019-12-02 05:19:49
I need your help. This is my program so far import turtle turtle.showturtle() def turtle_interface(): while True : n = 0 instructions = input().split() i = instructions[0] if len(instructions) > 1: n = int(instructions[1]) if i == 'forward' : turtle.forward(n) elif i == 'backward' : turtle.backward(n) elif i == 'left' : turtle.left(n) elif i == 'right' : turtle.right(n) elif i == 'quit' : break elif i == 'new' : turtle.reset() else : continue print('Control the turtle!') turtle_interface() As you can see, when the string has no [n] after it, it's being ignored. How can I fix this? I think it

How Do You Make Python Turtle Stop Moving?

試著忘記壹切 提交于 2019-12-02 04:49:26
I've tried to do turtle.speed(0) , and I've tried turtle.goto(turtle.xcor(), turtle.ycor()) nothing is seeming to work. This Is The Code: import turtle def stopMovingTurtle(): ## Here I Need To Stop The Turtle ## turtle.listen() turtle.onkey(stopMovingTurtle, 'Return') turtle.goto(-200, 0) turtle.goto(200, 0) So how do I stop it? The problem here isn't the order of turtle.listen() vs. turtle.onkey() , it's that the key event isn't being processed until the current operation completes. You can improve this by segmenting your long turtle.goto(-200, 0) motion into smaller motions, each of which

Turtle graphics drawing over itself

核能气质少年 提交于 2019-12-02 04:42:24
This should be a very simple question, however, it is proving difficult for me. I'm rather new to turtle graphics, and so, I am trying to get a simple drawing done. My turtle will draw a row, pick the pen up, move up one pixel, place the pen down, and keep drawing. Here's my code so far: for y in range(height): turtle.pendown() for x in range(width): detLand(y, x) # Set the color, works just fine turtle.setx(x) turtle.sety(y) turtle.penup() I figured this would be easy, however, it's still drawing over top of my lines. I believe the problem is that you're accidentally drawing on the backstroke

TurtleGraphics Python: Bouncing turtle off the walls?

我怕爱的太早我们不能终老 提交于 2019-12-02 03:26:50
So, I am trying to make a realistic bouncing function, where the turtle hits a wall and bounces off at the corresponding angle. My code looks like this: def bounce(num_steps, step_size, initial_heading): turtle.reset() top = turtle.window_height()/2 bottom = -top right = turtle.window_width()/2 left = -right turtle.left(initial_heading) for step in range(num_steps): turtle.forward(step_size) x, y = turtle.position() if left <= x <= right and bottom <= y <= top: pass else: turtle.left(180-2 * (turtle.heading())) So, this works for the side walls, but I don't get how to make it bounce correctly

How to make the turtle follow the mouse in Python 3.6

丶灬走出姿态 提交于 2019-12-02 03:14:50
I'm assigned to create a similar version of slither.io in python. I planned on using Turtle . How do I make the turtle follow my mouse without having to click every time? This is how I would do it when clicking, but I would rather not have to click: from turtle import * turtle = Turtle() screen = Screen() screen.onscreenclick(turtle.goto) turtle.getscreen()._root.mainloop() The key to it is to use the ondrag() event handler on a turtle. A short and not so sweet solution: import turtle turtle.ondrag(turtle.goto) turtle.mainloop() which will likely crash shortly after you start dragging. A

How to bind several key presses together in turtle graphics?

杀马特。学长 韩版系。学妹 提交于 2019-12-02 00:05:21
I'm trying to make a connect-the-dot python game. I want the game to register 2 button presses. Example: if the user presses Up and Right arrow key, the turtle goes 45 degrees north east. here is my code: import turtle flynn=turtle.Turtle() win=turtle.Screen() win.bgcolor("LightBlue") flynn.pensize(7) flynn.pencolor("lightBlue") win.listen() def Up(): flynn.setheading(90) flynn.forward(25) def Down(): flynn.setheading(270) flynn.forward(20) def Left(): flynn.setheading(180) flynn.forward(20) def Right(): flynn.setheading(0) flynn.forward(20) def upright(): flynn.setheading(45) flynn.forward(20