dessine une explosion de feu d’artifice
from kandinsky import * import math import random import time class ray: def __init__(self, v0, y0, x0, alpha, beta, col): self.v = v0 self.vx = self.v * cos(alpha) * sin(beta) self.vy = self.v * sin(alpha) self.y = y0 self.x = x0 self.alpha = alpha self.beta = beta self.col = col self.grad = ((255-col[0])/50,(255-col[1])/50,(255-col[2])/50) self.col_actuelle = (255,255,255) self.t = 0 def dessine(self): set_pixel(int(self.x), int(self.y), self.col_actuelle) def move(self): self.y += self.vy self.x += self.vx self.vx *= 0.95 self.vy = 0.95*self.vy +g self.col_actuelle = tuple([int(self.col_actuelle[i]-self.grad[i]) for i in range(3)]) def cos(x): return math.cos(math.pi*x/180) def sin(x): return math.sin(math.pi*x/180) def nmToRGB(wavelength): Gamma = 0.80 IntensityMax = 255 if((wavelength >= 380) and (wavelength<440)): red = -(wavelength - 440) / (440 - 380) green = 0.0 blue = 1.0 elif((wavelength >= 440) and (wavelength<490)): red = 0.0 green = (wavelength - 440) / (490 - 440) blue = 1.0 elif((wavelength >= 490) and (wavelength<510)): red = 0.0 green = 1.0 blue = -(wavelength - 510) / (510 - 490) elif((wavelength >= 510) and (wavelength<580)): red = (wavelength - 510) / (580 - 510) green = 1.0 blue = 0.0 elif((wavelength >= 580) and (wavelength<645)): red = 1.0 green = -(wavelength - 645) / (645 - 580) blue = 0.0 elif((wavelength >= 645) and (wavelength<781)): red = 1.0 green = 0.0 blue = 0.0 else: red = 0.0 green = 0.0 blue = 0.0 # Let the intensity fall off near the vision limits if((wavelength >= 380) and (wavelength<420)): factor = 0.3 + 0.7*(wavelength - 380) / (420 - 380) elif((wavelength >= 420) and (wavelength<701)): factor = 1.0 elif((wavelength >= 701) and (wavelength<781)): factor = 0.3 + 0.7*(780 - wavelength) / (780 - 700) else: factor = 0.0 if (red != 0): red = round(IntensityMax * ((red * factor) ** Gamma)) if (green != 0): green = round(IntensityMax * ((green * factor) ** Gamma)) if (blue != 0): blue = round(IntensityMax * ((blue * factor) ** Gamma)) return int(red), int(green), int(blue) v0 = 5 x0 = 160 y0 = 100 g = 0.05 while True: feu = [] color = nmToRGB(random.randint(400,700)) for beta in range(0,360,2): for alpha in range(0,360,2): if random.random() < 0.003: feu.append(ray((1-0.2*random.random())*v0, y0, x0, alpha, beta, color)) fill_rect(0,0,320,224,(0,0,0)) for t in range(50): for rayon in feu: rayon.move() if random.random() > 0.3 : rayon.dessine()