rvb.py

Created by schraf

Created on August 19, 2021

597 Bytes


from math import *
from kandinsky import set_pixel, fill_rect, get_pixel

# Rayon (au carré) des 3 disques
R = 180*180
# Précision du tracé (mettre 1 par exemple)
pas = 4

def synthese(sous = 1):
  # Fond blanc si synthèse soustrative sinon noir	
  fill_rect(0,0,320,222,(255 * sous,) * 3)
  # On dessine les 3 disques centrés en (0,50), etc.
  for i, m in enumerate([[0,50],[320,50],[160,290]]):
    # On parcourt tous les pixels de l'écran
    for c in range(0,320,pas):
      for l in range(0,222,pas):
      	# Distance au carré entre le point (c,l) et le centre du disque
        d = (m[0] - c) ** 2 + (m[1] - l) ** 2
        # On est dans le disque ?
        if d < R:  
          # Couleur actuelle du pixel en (c,l)
          # On transforme en liste car un tuple n'est pas modifiable
          p = list(get_pixel(c,l))
          # Synthèse soustractive
          if sous:
            p[i] = int(max(p[i] - 255 * sqrt(d / R), 0))  
          # Synthèse additive
          else:
            p[i] = int(min(p[i] + 255 * sqrt(d / R), 255))  
          # On dessine le rectangle avec la précision voulue
          fill_rect(c,l,pas,pas,tuple(p))


from math import *
from kandinsky import set_pixel, fill_rect, get_pixel

R = 180*180
pas = 4

def synthese(sous = 1):
  fill_rect(0,0,320,222,(255 * sous,) * 3)
  for i, m in enumerate([[0,50],[320,50],[160,290]]):
    for c in range(0,320,pas):
      for l in range(0,222,pas):
        d = (m[0] - c) ** 2 + (m[1] - l) ** 2
        if d < R:  
          p = list(get_pixel(c,l))
          if sous:
            p[i] = int(max(p[i] - 255 * sqrt(d / R), 0))  
          else:
            p[i] = int(min(p[i] + 255 * sqrt(d / R), 255))  
          fill_rect(c,l,pas,pas,tuple(p))

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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.