Hi, can you add a winter background to my Turtle from python program. Please tur
ID: 3875625 • Letter: H
Question
Hi, can you add a winter background to my Turtle from python program. Please turn all the turtles in the program to skaters.(People who skate). Add a normal game menu that asks if you want to play and that's all! Thanks!
#!/bin/python3
from turtle import *
from random import randint
speed(0)
penup()
goto(-140, 140)
for step in range(15):
write(step, align='center')
right(90)
for num in range(8):
penup()
forward(10)
pendown()
forward(10)
penup()
backward(160)
left(90)
forward(20)
ada = Turtle()
ada.color('red')
ada.shape('turtle')
ada.penup()
ada.goto(-160, 100)
ada.pendown()
for turn in range(10):
ada.right(36)
bob = Turtle()
bob.color('blue')
bob.shape('turtle')
bob.penup()
bob.goto(-160, 70)
bob.pendown()
for turn in range(72):
bob.left(5)
ivy = Turtle()
ivy.shape('turtle')
ivy.color('green')
ivy.penup()
ivy.goto(-160, 40)
ivy.pendown()
for turn in range(60):
ivy.right(6)
jim = Turtle()
jim.shape('turtle')
jim.color('orange')
jim.penup()
jim.goto(-160, 10)
jim.pendown()
for turn in range(30):
jim.left(12)
for turn in range(100):
ada.forward(randint(1,5))
bob.forward(randint(1,5))
ivy.forward(randint(1,5))
jim.forward(randint(1,5))
Explanation / Answer
First of all, you would have to download the two pics which you want to set as the background and the skater one.
Now changing to the image of your choice is not an easy task. There are two functions for this in python one is bgpic() and the other is bgcolor() and addshape() is you randomly pass bgcolor("red") it would change your background to red. But for your program, you have to change these functions in the turtle.py program which you would find as stated-
Go to the directory where python is installed on your computer the look for the lib folder and you would find the turtle.py program in it. Then look for the definition of those two functions and change the source destination to the one you have downloaded your image. Then using bgpic you would be able to change the background.
Similarly, do for the addshape() function and then you can use this addshape() function to change your turtle to a skater or anything..!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.