Ενότητα 6 - Τμήμα 1 - Επαναλήψεις και κινούμενα σχέδια
Ενότητα 6 - Τμήμα 1 - Επαναλήψεις και κινούμενα σχέδια
- δημιουργούν τυχαία κινούμενα σχήματα
- ξαναγράφουν τον κώδικα χρησιμοποιώντας βρόχους
- χρησιμοποιούν εμφωλευμένους βρόχους για συνεχή κίνηση
- προβλέψουν και να διορθώσουν τον κώδικα έτσι ώστε τα αντικείμενα να επανεμφανίζονται σε τυχαίες θέσεις
6.1.7 - It's snowing for ever
The problem with the previous code is that the snow dissapears at the bottom of the screen when coordinate Y is greater than 500.
Can you think of a way to move the snowflakes from the bottom to the top of the screen when dissapear?
Starting from the script that creates the animated snow flakes open it inside Thonny and save it as snow_flakes_drop_all. If you don't have it you can download it from here and save it in your project's folder.
We need a condition to check if coordinate Y is greater than 500 (or 502 to be sure that the snowflake completely dissapeared). And then, change coordinate Y so it is redrawn on top of the screen (coordinate Y is less than 0). This is one way to do things but it is better to reinitialize both X and Y coordinates to random values. In this way the snow flakes appear random and not in the same X coordinate.
The commands that we have to add are:
if snow_list[i][1] > 502:
snow_list[i][0] = random.randrange(10,690)
snow_list[i][1] = random.randrange(-50,-20)
Think where you should write them. After succeding, change the negative numbers to positive to see the difference.
The complete script (with minor) changes can be downloaded from here.