bouncing.py

Created by schraf

Created on February 24, 2024

877 Bytes

Découvrez ma chaine YouTube (Jeux pour la NUMWORKS, Python…)


from kandinsky import *
from time import *
from random import randint

def init():
 global x,y,t,dx,dy,i   
 x, y = randint(20,300), randint(20,200)
 t = 4
 dx = -2 * randint(0,1) + 1
 dy = -2 * randint(0,1) + 1
 i = 0

red, green, blue = 255, 0, 0
colors = []
for j in range(0, 255 * 6 + 1, 10):
 if 255 >= j > 0: blue += 10
 elif 255 * 2 >= j > 255: red -= 10
 elif 255 * 3 >= j > 255 * 2: green += 10
 elif 255 * 4 >= j > 255 * 3: blue -= 10
 elif 255 * 5 >= j > 255 * 4: red += 10
 elif 255 * 6 >= j > 255 * 5: green -= 10
 colors.append((red, green, blue))

init()
while True:
 fill_rect(x,y,2*t,2*t,colors[i%154])
 sleep(.001)
 x += dx
 y += dy
 if x < -t or x + t > 320: 
    dx = -dx
    x += dx * t
 if y < -t or y + t > 222:
    dy = -dy
    y += dy * t
 i += 1
 if i % 100 == 0: t += 1
 if t > 120:
    fill_rect(0,0,320,222,colors[i%154])
    init()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.