PASO 16: Para hacer que nuestros sprites se muevan alrededor de la Tierra, rotaremos alrededor del centro.
Haga clic en la pestaña ASUNTO, luego haga clic en . Arrastre Rotate about Origin hasta la parte inferior de su código, dentro del bucle. Cambie el número en el .rotate_origin() de 45 a la variable rotate . ¡Observe que todos los sprites giran 90 grados alrededor de la Tierra! A continuación, haremos que los sprites se extiendan por la Tierra.
To navigate the page using the TAB key, first press ESC to exit the code editor.
stage.set_background_color("lightblue")
# sprite = codesters.Rectangle(x, y, width, height, "color")
sprite = codesters.Rectangle(0, 0, 700, 100, "gold")
sprite.turn_left(45)
# sprite = codesters.Rectangle(x, y, width, height, "color")
sprite = codesters.Rectangle(0, 0, 700, 100, "gold")
sprite.turn_right(45)
sprite = codesters.Sprite("earth")
people_sprites = ['person1', 'person2', 'person3', 'person4', 'person5', 'person6',
'person7', 'person8','person9', 'person10', 'person11', 'person12']
rotate = 90
for value in people_sprites:
# add code here
sprite = codesters.Sprite(value)
stage.wait(0.5)
sprite.set_size(0.3)
sprite.set_speed(5)
sprite.move_forward(120)
sprite.turn_right(90)
t = codesters.Teacher()
try:
params = t.get_parameters_for_function('rotate_origin')
tval1 = params[0][0]
except:
tval1 = "DNE"
try:
rotate_params = t.find_function('rotate_origin')
tval2 = t.get_indent_at_line(rotate_params[0][0])
except:
tval2 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == "rotate", "Great job!")
t1.add_failure(tval1 == "45", "Did you change the number in .rotate_origin() to the variable rotate?")
t1.add_failure(tval1 == "DNE", "Did you drag out Rotate about Origin?")
t2 = TestObjective()
t2.add_success(tval2 == 4, "Great job!")
t2.add_failure(tval2 == 0, "Did you indent .rotate_origin() under the for loop?")
t2.add_failure(tval2 > 4 and tval2 != "DNE", "You indented .rotate_origin() too far.")
t2.add_failure(tval2 == "DNE", "Did you drag out Rotate about Origin?")
tester = TestManager()
tester.add_test_list([t1,t2])
tester.run_tests()
tester.display_first_feedback()
Run Code
Activity Submitted!
Enviar Trabajo
Actividad Siguiente
Stop Running Code
Show Chart
Show Console
Reset Code Editor
Codesters How To (opens in a new tab)