def return_trajectory(speed, angle):
radians = math.radians(angle)
x_velocity = speed * math.cos(radians)
y_velocity = speed * math.sin(radians)
return (x_velocity, y_velocity)
stage.set_background_color("black")
amount = 10
speed = 5
color_list = ["purple", "yellow", "red"]
stage.disable_all_walls()
def click():
x = stage.click_x()
y = stage.click_y()
particle_list = []
for color in color_list:
for counter in range(amount):
sprite = codesters.Circle(x, y, 10, color)
particle_list.append(sprite)
sprite.pen_down()
angle = 0
for count, p in enumerate(particle_list):
count += 1
speed_values = return_trajectory(speed, angle)
p.set_x_speed(speed_values[0])
p.set_y_speed(speed_values[1])
angle += 360/amount
if count % amount == 0:
stage.wait(.1)
stage.wait(0.5)
# add other actions...
stage.event_click(click)
stage.set_gravity(3)
t = codesters.Teacher()
waits = t.find_text('wait')
for_text = t.find_text('for')
removes = t.get_parameters_for_function('remove_sprite')
try:
tval0 = waits[1][0]
tval1 = t.get_indent_at_line(tval0)
except:
tval0 = 0
tval1 = -1
try:
tval2 = for_text[3][0]
tval3 = t.get_indent_at_line(tval2)
except:
tval2 = -0
tval3 = -1
try:
tval4 = for_text[3][1].lower().replace(" ", "")
except:
tval4 = "DNE"
try:
tval5 = removes[0][0]
except:
tval5 = "DNE"
t1 = TestObjective()
t1.add_success(tval2 == tval0+1 and tval3 == 4 and tval4 == 'forpinparticle_list:', "Great job!")
t1.add_failure(tval1 == 0, "Did you add a Loop through List command?")
t1.add_failure(tval2 != tval0+1 and tval2 != tval0+2, "Did you add the loop in the correct place?")
t1.add_failure(tval3 != 4, "Oops! Make the loop is indented only once!")
t1.add_failure('value' in tval4, "Did you change value to p?")
t1.add_failure('my_list' in tval4, "Did you change my_list to particle_list?")
t1.add_failure(tval4 != 'forpinparticle_list:', "Did you change the loop correctly?")
t2 = TestObjective()
t2.add_success(tval5 == 'p', "Great job!")
t2.add_failure(tval5 == "DNE", "Did you add Remove Sprite?")
t2.add_failure(tval5 != 'p' and tval5 != 'DNE', "Did you change sprite to p?")
################################################
# Pass test code
# - set pass_required to True if pass is required to prevent bad input error
# - include tpass before t1 in the test list
pass_required = False
passes = t.find_text("pass")
num_pass_only = 0
for p in passes:
if p[1].lower().replace(' ','') == "pass":
num_pass_only += 1
tpass = TestObjective()
if not pass_required:
tpass.add_success(num_pass_only == 0, "Great job!")
tpass.add_creative(num_pass_only > 0, "Great job! Feel free to delete pass statements now.")
################################################
tester = TestManager()
tester.add_test_list([tpass, t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)