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>
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()
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]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: ')
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)
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
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
Ich habe ein Programm erstellt, um die Schildkrötenposition durch Drücken der Tastatur zu verschieben, aber gibt es eine Möglichkeit, sie in kleineren Pixelschritten zu verschieben?
Und ist das auch...
Ich erstelle ein Spiel mit der Ursina -Engine. Ich fügte meinem Charakter eine einfache glattfolie hinzu. Bei SmoothFollow bemerkte ich, dass Objekte, die an den X- und Y -Koordinaten der Kamera...
Wie werde ich diese blaue Unterstreichung los, die nur angezeigt wird, wenn ich in den Eintrag
klicke
i already tried to make a grey boxview above it but its still visiable and editing the...
Ich mache eine analoge Uhr in Python mit Schildkröte. Es muss alle t Sekunden erneuert werden. Dafür zeichne ich es alle t Sekunden neu. Ich muss es sofort neu gezeichnet werden (jetzt platziert es...