lumiere.py

Created by dkfe123

Created on September 24, 2025

1.49 KB

Juste une lumière, un vieux truc


from math import *
from kandinsky import *
from ion import *
from random import randint
la,q=floor(int(input("Largeur de l eclairage ="))),float(input("Qualite ?(1 a 2)="))
lx,ly,c=100,100,[]
for i in range(randint(5,6)):
  c.append(randint(0,300))
  c.append(randint(0,200))
  c.append(floor(5*randint(2,10)))
  c.append(floor(5*randint(2,10)))
def to(c,x,y):
  if x>320 or x<0 or y>220 or y<0:
    return True
  for w in range(0,len(c),4):
    if x>c[w] and x<c[w]+c[w+2]:
      if y>c[w+1] and y<c[w+1]+c[w+3]:
        return True
  return False
def tour(x,y,c,d,la,n):
  for i in range(floor(q*la)):
    x,y=x+sin(radians(d))/q,y+cos(radians(d))/q
    if to(c,x,y):
      return n+1,i
    else:
      v=round(255-255*i/(la*q))
      set_pixel(floor(x),floor(y),(v,v,v))
  return 0,0
fill_rect(0,0,320,240,(0,0,0))
n,ch=0,0
while True:
  if keydown(KEY_RIGHT):
    ch,lx=0,lx+30
    while keydown(KEY_RIGHT):
      pass
  elif keydown(KEY_LEFT):
    ch,lx=0,lx-30
    while keydown(KEY_LEFT):
      pass
  if keydown(KEY_UP):
    ly,ch=ly-30,0
    while keydown(KEY_UP):
      pass
  elif keydown(KEY_DOWN):
    ch,ly=0,ly+30
    while keydown(KEY_DOWN):
      pass
  if ch==0:
    ch=1
    fill_rect(0,0,320,240,(0,0,0))
    for d in range(360):
      x,y=lx,ly
      n,i=tour(x,y,c,d,la,n)
    for j in range(0,len(c),4):
      for x in range(c[j],c[j]+c[j+2]):
        for y in range(c[j+1],c[j+1]+c[j+3]):
          di=round(0.6*255*(1-((sqrt((x-lx)**2+(y-ly)**2)/la))))
          set_pixel(x,y,(di,di,di))

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.