using this example CREATE: Build your own custom Codesters version of the classic…
- User
using this example CREATE: Build your own custom Codesters version of the classic Etch-a-Sketch toy! Have users direct the pointer to draw with the up, down, left and right keys, and change colors or add shapes with other key events!
------------------------------ ### ### MINIMUM TECHNICAL REQUIREMENTS ### ### ------------------------------ ### # 1) Use a point Shape block stage.set_background_color("black") sprite = codesters.Point(50, 100) sprite.pen_down() sprite.set_color("red") # 2) Allow the user to move the point right, left, up, down def left_key(): sprite.move_left(20) stage.event_key("left", left_key) def right_key(): sprite.move_right(20) stage.event_key("right", right_key) def down_key(): sprite.move_down(20) stage.event_key("down", down_key) def up_key(): sprite.move_up(20) stage.event_key("up", up_key) # 3) Use the pen_down() Action block # 4) Allow the user to change the color of the pen randomly def space_bar(): colors = ["green", "red", "yellow", "orange", "pink", "lightblue"] color_num = random.randint(0, len(colors) - 1) color = colors[color_num] sprite.set_color(color) sprite.set_say_color("white") sprite.say("Space bar!", 0.2) stage.event_key("space", space_bar) # 5) Allow the user to change the width of the pen randomly def click(): numbers = [1, 2, 3, 4] rand_num = random.randint(1, len(numbers) - 1) width = numbers[rand_num] sprite.pen_width(width) sprite.set_say_color("white") sprite.say("Stage click!", 0.2) stage.event_click(click)
- Assistant