Wie kann ich die blaue Schildkröte auf x = 280 bewegen, indem ich in Python Turtle wiederholte halbkreisförmige „Hopfen“

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie kann ich die blaue Schildkröte auf x = 280 bewegen, indem ich in Python Turtle wiederholte halbkreisförmige „Hopfen“

by Anonymous » 23 Aug 2025, 23:02

Ich baue ein Turtle -Rennen. Ich möchte, dass sich die blaue Schildkröte zu x = 280 bewegt, indem dieses Muster wiederholt wird: < /p>

Zeichnen Sie einen Abwärts -Semicircle („Schüssel“) < /p>
< />
Dann ein kurzes, nach rechts nach rechts. x = 280 < /p>
< /li>
< /ul>
Was ich ausprobiert habe, macht entweder schrägige Linien oder Stapelschalen vertikal. Wie implementiere ich den Hop sauber? < /P>

Code: Select all

from turtle import Turtle, Screen
import random

# These are the Functions that are later used in the code to call and make changes in the track of the turtles
def move_right(color, angle):
for turtle in all_turtles:
if turtle.pencolor() == color:
turtle.right(angle)
turtle.fd(10)
turtle.setheading(0)

def move_back(color):
for turtle in all_turtles:
if turtle.pencolor() == color:
turtle.setheading(-180)
turtle.fd(15)
turtle.seth(0)

def move_in_circle(color, angle):
for turtle in all_turtles:
if turtle.pencolor() == color:
turtle.circle(50, angle)
turtle.setheading(0)

# Now adding a pop up of taking user entry in a pop up window.
# will be using above Screen pop up as eg.

is_race_on = False
scn = Screen()
scn.setup(width=900, height=700)
user_bet = scn.textinput(title='Make your Bet',
prompt='What color Turtle would you like? \nEnter Please: ')

colors = ['red', 'orange', 'black', 'blue', 'yellow', 'pink']
y_pos = [-70, -10, -40, 20, 50, 80]
all_turtles = []
start_x, finish_x = -280, 280

for c in range(0, 6):
new_turtle = Turtle(shape='turtle')
new_turtle.speed('fastest')
new_turtle.color(colors[c])
new_turtle.penup()
new_turtle.goto(x=start_x, y=y_pos[c])
all_turtles.append(new_turtle)

if user_bet:
is_race_on = True

red_count = 0
blu_count = 0
blue_nudged_back = False

while is_race_on:
for turtles in all_turtles:
if turtles.xcor() >= finish_x:
is_race_on = False
winning_color = turtles.pencolor()

if winning_color == user_bet:
print(f"You've Won!!! {winning_color} is the winner")
break
else:
print(f"You've Lost, Sorry {winning_color} is the winner")
break

rand_distance = random.randint(0, 10)
turtles.forward(rand_distance)

if turtles.pencolor() == 'red':
turtles.forward(1)

if red_count < 3:
move_right(color='red', angle=45)
red_count += 1
if red_count == 3:
turtles.pendown()

if turtles.pencolor() == 'blue' and blu_count < 1:
if not blue_nudged_back:
move_back('blue')
blue_nudged_back = True
move_in_circle('blue', 90)
blu_count += 1

scn.exitonclick()

Top