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()

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