< Back

Activity 12: Graphic Conditionals

Conditionals

In order to create animations where images can interact with each other, we need to understand how to move images and to test where images are in relation to each other. In this activity you will explore animation velocity and graphical conditionals.

    For each of the following questions, specify which direction the image will move:

  1.  
    for i in range(100):
        x += 10
        y += 10
        graphics.clear()
        graphics.draw_image('image.gif', x, y)
  2.  
    for i in range(100):
        x += 6
        y -= 8
        graphics.clear()
        graphics.draw_image('image.gif', x, y)
  3.  
    for i in range(100):
        x -= 4
        y += 3
        graphics.clear()
        graphics.draw_image('image.gif', x, y)
  4.  
    for i in range(100):
        x -= 1
        y -= 2
        graphics.clear()
        graphics.draw_image('image.gif', x, y)
  5. Consider the following code:

    for i in range(1000):
        x += delta_x
        y += delta_y
    
        if x > window_width:
            delta_x = 0
            delta_y = 0
        if x < 0:
            x = window_width / 2
            y = window_height / 2
        if y > window_height:
            delta_y *= -1
        if y < 0:
            y = window_height
    
        graphics.clear()
        graphics.draw_image('image.gif', x, y)
    1. What will happen if the image's center goes past the top side of the window?
    2. What will happen if the image's center goes past the right side of the window?
    3. What will happen if the image's center goes past the bottom side of the window?
    4. What will happen if the image's center goes past the left side of the window?