galaxie.py

Created by schraf

Created on July 23, 2022

718 Bytes

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

Ma chaine Youtube Maths-info


from math import log,sin,cos,exp
from random import random,randint
from kandinsky import fill_rect,set_pixel,get_pixel

coul = [(0,0,0),(248,0,0),(248,252,0),(248,252,248)]
fill_rect(0,0,320,222,coul[0])

r1,r2,t2 = 60,50,3

for _ in range(50000):
    s = log(random())
    t = 300 * random()
    u = s * r1 * sin(t)
    v = s * r2 * cos(t)
    p = s * t2
    c, s = cos(p), sin(p)
    x = u * c + v * s
    y = - u * s + v * c
    r = x * x + y * y
    z = 80 * exp( -r / 10)
    z *= random() -.5
    y += z + randint(1, 40)
    x += -z * .3 * randint(1, 20)
    x = int(160 + x * .7 + y * .3)
    y = int(90 + x * .1 + y * .4)
    p = min(3, coul.index(get_pixel(x,y)) + 1)
    set_pixel(x,y,coul[p])