1

This is my code to make a rocket move around in a turtle screen:

import turtle
s = turtle.Screen()
image = "rocket.gif"
s.addshape(image)
turtle.shape(image)
s.bgcolor("black")

def fd():
  turtle.fd(5)

def bk():
  turtle.bk(10)

def lt():
  turtle.lt(5)

def rt():
  turtle.rt(5)

turtle.penup()
turtle.speed(0)
turtle.home()

s.listen()
s.onkeypress(fd, "Up")
s.onkeypress(bk, "Down")
s.onkeypress(lt, "Left")
s.onkeypress(rt, "Right")

When I press the up button the rocket moves forward, and when I press the right button, the rocket image does not turn, but when it moves forward again the direction of the movement does change.

I read this at the help() section at Python3 IDLE:

Image shapes do not rotate when turning the turtle, so they do not display the heading of the turtle!

But, I do not understand is this for turtle.rt() or turtle.setheading()? Even if it is for both, how do I rotate the image?

Note: Surprisingly it works with trinket.io

ggorlen
  • 44,755
  • 7
  • 76
  • 106
  • That puzzled me too at first, and I conclude that trinket took this obvious problem with turtle, about which dozens of questions have been asked in the past 5 years, and wrote a little wrapper script to accomplish the shape substitution (or perhaps even on-demand rotation) which stays behind the scenes and which the user does not see. – J B Aug 12 '22 at 19:30
  • Does this answer your question? [how to rotate turtle shape in python](https://stackoverflow.com/questions/11277518/how-to-rotate-turtle-shape-in-python) – ggorlen Mar 03 '23 at 05:45

2 Answers2

0

We can make a shape appear to rotate by telling a turtle to switch between different related shapes. use setshape (setsh) and setheading (seth).For more details Visit http://mia.openworldlearning.org/howdoi/ftn.htm

0

Try using Numpy to semi-automatically generate 256 dirction spritepacks.(You can do this by saving a image like this: pxr pxr pxy pxw pxr pxn pxr pxr pxn into

[[pxr,pxr,pxy],
[pxw,pxr,pxn],
[pxr,pxr,pxn]]

then using calculations to slant the pixels, so for degree 1 it slants right 1 pixel every 64 pixls,for degree 2 it slants right 2 pixelx every 64 pixls, so on