arc_en_ciel.py

Created by ph-moutou

Created on May 18, 2018

615 Bytes

Programme qui dessine un dégradé circulaire en bombardant l’écran au hasard


from kandinsky import *
from random import *
from math import *
def degrade(c1,c2,k):
  dr=c2[0]-c1[0]
  dg=c2[1]-c1[1]
  db=c2[2]-c1[2]
  return color(c1[0]+int(k*dr),
  c1[1]+int(k*dg),c1[2]+int(k*db))

def couleur(x,y):
  d=sqrt((x-160)**2+(y-111)**2)/32.5
  return degrade(c[int(d)],
  c[(int(d)+1)%6],d-int(d))

def tirage():
  for i in range(n):
    x=randint(0,320)
    y=randint(0,222)
    c=couleur(x,y)
    set_pixel(x,y,c)
    set_pixel(x+1,y,c)
    set_pixel(x,y+1,c)
    set_pixel(x+1,y+1,c)
    
c=[[255,0,0],[255,255,0],[0,255,0],
[0,255,255],[0,0,255],[255,0,255]]
n=5000
tirage()