# univers.py

Created by schraf

Created on July 22, 2022

1.03 KB

Adaptation d’un programme de Paul Malin pour la calculatrice Numworks.

```from math import *
from random import random,randint
from kandinsky import fill_rect,set_pixel,get_pixel
from time import sleep

coul = [(0,0,0),(248,0,0),(248,252,0),(248,252,248)]

def alea(): return pi * random()

while True:
fill_rect(0,0,320,222,(0,0,0))
for g in range(200):
A = 5 * random()
R = 40 / randint(1,35)
Q = 1 + R * (.5 + random() / 2)
u, v = randint(0,320), randint(0,222)
s, t, q = alea(), alea(), alea()
a = int(1 + 3 * random() ** 2)
C = int(R * Q * 3 * random() ** 2)
for i in range(C):
S = -log(random())
T = 2 * alea()
U = S * R * sin(T)
V = S * Q * cos(T)
T = s + S * A
X = U * cos(T) + V * sin(T)
Y = -U * sin(T) + V * cos(T)
D = (X * X + Y * Y) / (R * R + Q * Q)
Z = 99 * ((2.7 ** (-D)) + .1)
Z *= (random() - .5) ** 3
y = Y * cos(t) + Z * sin(t)
Z = -Y * sin(t) + Z * cos(t)
x = int(u + X * cos(q) + y * sin(q))
y = int(v - X * sin(q) + y * cos(q))
p = min(3, coul.index(get_pixel(x,y)) + a)
set_pixel(x,y,coul[p])
sleep(1)```