galaxie.py

Created by schraf

Created on October 15, 2024

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

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