Ενότητα 6 - Τμήμα 1 - Επαναλήψεις και κινούμενα σχέδια

6.1.6 - It's snowing once

Starting from the script that creates 50 snow flakes open it inside Thonny and save it as snow_flakes_drop_once. If you don't have it  you can download it from here.

For every pair inside the snow_list list a snow flake appears in the specified by the pair coordinates. The first number of the pair is coordinate X (pixels from the left margin) and the second number of the pair is coordinate Y (pixels from the top margin).

Which of these two number we must change to move the snow flake down?

Change the code after the drawing area, taking care of identation, to this:

for i in range(len(snow_list)): if i == 20: pygame.draw.circle(screen, RED, snow_list[i] , 2) print (snow_list[i]) else: pygame.draw.circle(screen, WHITE, snow_list[i] , 2)

What is the purpose of this code? What does this code print in CLI area?

Stop the script pressing the  button and in the CLI area write:

>>> print(snow_list[20])

>>> print(snow_list[20][0])

>>> print(snow_list[20][1])

What are these numbers?

Which of these numbers and how must we change to move the snow flake down?

Change the code after the drawing area, taking care of identation, to this:

for i in range(len(snow_list)): if i == 20: pygame.draw.circle(screen, RED, snow_list[i] , 2) print (snow_list[i]) snow_list[i][1] += 1 else: pygame.draw.circle(screen, WHITE, snow_list[i] , 2)

One moving RED snow flake.

Change the code to have every snowflake dropping.

Why we have used a list instead of tuples for the coordinates of the snow flakes?