''' In this exercise, you'll be simulating the movement of objects through 2D space, such as a bouncing ball as well as random diffusion. The code below simulates a ball moving from the left to the right side of the graphical window: ''' from NaNoPy import Canvas, Color, Writer x_size = 800 y_size = 600 ball_x = 1 ball_y = 300 dx = 1.0 n_steps = 1000 c = Color.green screen = Canvas("title", x_size, y_size) pen = Writer(screen) for i in range(n_steps): ball_x = ball_x + dx pen.draw_circle(ball_x, ball_y, 5, c, True) screen.update() screen.pause(5) screen.clear() screen.keep_window() ''' Exercise A: Run the code above and observe the result. Then increase and decrease the speed at which the ball moves by modifying the value for `dx`. Exercise B: Extend the code such that the ball initially moves very fast, then gradually slows down before finally stopping at the right border of the graphical window, by making `dx` depend on the position of the ball within the graphical window. Exercise C: Extend the code such that the ball moves from top to bottom. Add a variable named `dy`. Exercise D: Extend the code such that the ball moves in a diagonal line over the graphical window. '''