from kandinsky import * from random import randint, random def distance(xa, ya, xb, yb): return ((xa - xb) ** 2+ (ya - yb) ** 2) ** .5 def val(t): t %= 180 if (t<120): return int((1/14.1) * t * (120-t)) else : return 0 def couleur(pos): return (val(pos+60),val(pos+120),val(pos)) def arc_en_ciel(xc,yc,R,e): for x in range(xc - R, xc + R): for y in range(yc - R, yc): dist=distance(x, y, xc, yc) if (1-e) * R <= dist <= R: if get_pixel(x,y) == (248,252,248): value=(dist - (1 - e) * R)/( e * R) set_pixel(x,y,nmToRGB(380 + 400 * value)) def nmToRGB(wavelength): Gamma = 0.80 IntensityMax = 255 if((wavelength >= 380) and (wavelength<440)): R,V,B = -(wavelength - 440) / (440 - 380), 0, 1 elif((wavelength >= 440) and (wavelength<490)): R,V,B = 0, (wavelength - 440) / (490 - 440), 1 elif((wavelength >= 490) and (wavelength<510)): R, V, B = 0, 1, -(wavelength - 510) / (510 - 490) elif((wavelength >= 510) and (wavelength<580)): R,V,B = (wavelength - 510) / (580 - 510), 1, 0 elif((wavelength >= 580) and (wavelength<645)): R, V, B = 1.0, -(wavelength - 645) / (645 - 580), 0.0 elif((wavelength >= 645) and (wavelength<781)): R, V, B = 1.0, 0.0, 0.0 else : R, V, B = 0, 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 (R != 0) : R = round(IntensityMax * (R * factor) ** Gamma) if (V != 0) : V = round(IntensityMax * (V * factor) ** Gamma) if (B != 0) : B = round(IntensityMax * (B * factor) ** Gamma) return (R,V,B) def motif(R): compteur = 1 for x in range(320 // (2*R)): for y in range(224 // (1 + R)): arc_en_ciel(2 * x * R, (y * R), R, compteur / ((320 // (2*R))*(224 // (1 + R)))) compteur += 1 motif(30)