univers.py

Created by schraf

Created on October 15, 2024

1.03 KB

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

Ma chaine Youtube Maths-info


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),(255,0,0),(255,255,0),(255,255,255)]


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)

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 cookies policy.