from math import sqrt from random import randint from kandinsky import fill_rect from ion import keydown, KEY_HOME from time import sleep def rock(x, y, c=(255, 255, 255)): fill_rect(x - 8, y - 8, 16, 16, c) fill_rect(x - 4, y - 10, 8, 20, c) fill_rect(x - 10, y - 4, 20, 8, c) def truc(n): x = [randint(10, 310) for _ in range(n)] y = [randint(-40, 40) for _ in range(n)] vx = [randint(1, 15) for _ in range(n)] vy = [randint(-10, 10) for _ in range(n)] colors = [(randint(0, 255), randint(0, 255), randint(0, 255)) for _ in range(n)] fill_rect(0, 0, 320, 222, (255, 255, 255)) while not keydown(KEY_HOME): draw_logo() for i in range(n): rock(x[i], y[i], (255, 255, 255)) x[i] += vx[i] y[i] += vy[i] vy[i] += 1 # Simule la gravité if y[i] > 210: vy[i] = -vy[i] * 0.99 + 1 y[i] = 189 if x[i] > 310: vx[i] = -vx[i] * 0.99 x[i] = 309 if x[i] < 10: vx[i] = -vx[i] * 0.99 x[i] = 11 for j in range(i + 1, n): dx, dy = x[i] - x[j], y[i] - y[j] dist_sq = dx**2 + dy**2 if dist_sq < 410: factor = 0.7 / sqrt(dist_sq) vx1, vy1 = factor * dx * sqrt(vx[i]**2 + vy[i]**2), factor * dy * sqrt(vx[i]**2 + vy[i]**2) vx2, vy2 = factor * -dx * sqrt(vx[j]**2 + vy[j]**2), factor * -dy * sqrt(vx[j]**2 + vy[j]**2) vx[i], vy[i] = vx1, vy1 vx[j], vy[j] = vx2, vy2 rock(x[i], y[i], colors[i]) sleep(0.02) def draw_logo(): color = [(0, 0, 0), (255, 0, 0), (255, 180, 0), (255, 255, 0), (0, 255, 0), (0, 0, 255)] logo = [1, 1, 0, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 0, 5, 5, 1, 0, 1, 0, 2, 0, 2, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 1, 1, 0, 0, 2, 2, 2, 0, 3, 0, 0, 4, 0, 0, 0, 5, 0, 1, 0, 1, 0, 2, 0, 2, 0, 3, 0, 0, 4, 0, 0, 0, 0, 5, 1, 1, 1, 0, 2, 0, 2, 0, 3, 3, 0, 4, 4, 0, 5, 5, 0] a = 0 for b in range(10, 60, 10): for c in range(75, 170 + 75, 10): if logo[a] != 0: fill_rect(c, b, 10, 10, color[logo[a]]) a += 1 #truc(int(input("How many balls?\n→"))) truc(2)