degrade.py

Created by loic-azavant

Created on December 07, 2022

876 Bytes

En exécutant la fonction main(), avec comme argument le nombre de point, le script vous demande ensuite le les coordonnées de chaque point et leur couleur, puis donne un dégradé progressif


from math import *
from kandinsky import *
from random import *

def dist(x1,y1,x2,y2):
  return sqrt((x1-x2)**2+(y1-y2)**2)

  

def main(nbrCoord,res=4):
  res = res
  
  coords = []
  colors = []

  for i in range(nbrCoord):
    coords.append(eval(input(str(i+1)+"e coordonnee: ")))
    colors.append(eval(input(str(i+1)+"e couleur: ")))

  for i in range(int(320/res)+1):
    for j in range(int(222/res)+1):
      distances = []
      for k in coords:
        distances.append(dist(i*res,j*res,k[0],k[1]))
      somme = 389
      for k in distances:
        somme += k
      r,g,b = 0,0,0
      for k in range(len(distances)):
        r += colors[k][0]*(389-distances[k])
        g += colors[k][1]*(389-distances[k])
        b += colors[k][2]*(389-distances[k])
      r /= somme
      g /= somme
      b /= somme
      fill_rect(i*res,j*res,res,res,(r,g,b))

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.