visible_spectrum.py

Created by uncurieux

Created on May 29, 2019

677 Bytes

Ce script trace le spectre visible de 400 à 700 nm. Vous appelez la variable spectrum() ou vous écrivez spectrum(), puis EXE (spectrum() sans argument). Une fois le spectre tracé vous pouvez écrire 550 par exemple pour voir la couleur associée à une longueur d’onde de 550 nm. Vous pouvez voir jusqu’à 10 longueurs d’ondes, utilisez la flèche pour quitter.

Draw the visible spectrum : 400-700 nm. The variable name is spectrum(), without argument. Then you can type for example “550”to see the color corresponding to 550 nm, until 10 times. To exit : the arrow.


from kandinsky import *
def spectrum():
  r,g,b=255,0,255
  for i in range(320):
    if i<54:
        r-=int(255/53)
    elif i>85 and i<102:
        g+=int(255/16)
    elif i>101 and i<123:
        b-=int(255/21)
    elif i>170 and i<194:
        r+=int(255/30)
    elif i>194 and i<235:
        g-=int(255/43)
        r=255
    elif i>233:
        g=0
    for j in range(100):
      set_pixel(i,j,color(r,g,b))
  m=0
  draw_string("nm",190,150)
  for n in range(10):
   l=input("l")
   for k in range(100,150):
     set_pixel(int(((int(m)-400)*320)/300),k,65535)
     set_pixel(int(((int(l)-400)*320)/300),k,0)
   draw_string(str(l),150,150)
   m=l
  

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.