paint.py

Created by ississkerrouche67

Created on April 09, 2024

2.87 KB

Ce programme vous permet de dessiner sur Numworks. Il y a plusieurs fonctionnalité comme la taille du pinceau, la couleur, la vitesse, retour à l’origine ou encore la possibilité de lever le pinceau.

Touches : Flèche : Pour se déplacer. Ok : Retour à l’origine du pinceau. Point : Lever/Reposer le pinceau (petit point pour se guider). + / - : Changer la vitesse. x / ÷ : Changer la luminosité. ( / ) : Changer la taille.

Couleur:

0 : Blanc. 1 : Beige. 2 : Gris. 3 : Noir. 4 : Rouge. 5 : Vert. 6 : Bleu. 7 : Orange. 8 : Jaune. 9 : Violet.


from kandinsky import * 
from math import * 
from ion import * 

x= 190 
y=120 
speed=5 
radius=3 
col = (255,255,255) 
brightness = 0
temp = [255,255,255]
state = False
last = [x,y,col]



def deg(col): 
  for x in range(320):
    c1 = 128
    c2 = 240
    c3 = 170
    if keydown(KEY_SQUARE):
        return
    for y in range(220):
      
      if x % 2 == 0:
        c1-=1
      c2 -=1
      c3 -=1
      if col == 1:
        set_pixel(x,y,(c2,c2,c2))
      if col == 2:
        set_pixel(x,y,(c1,c2,255))
      if col == 3:
        set_pixel(x,y,(c2,c1,255))
      if col == 4:
        set_pixel(x,y,(170,c3,190))
      if col == 5:
        set_pixel(x,y,(255,c2,c2))

def sceau(origin,color,x,y):
  for sx in range(320):
    for sy in range(250):
      if get_pixel(sx,sy) == origin:
        set_pixel(sx,sy,color)


while True: 
  #degradé
  if keydown(KEY_SINE):
    deg(1)
  if keydown(KEY_COSINE):
    deg(2)
  if keydown(KEY_TANGENT):
    deg(3)
  if keydown(KEY_PI):
    deg(4)
  if keydown(KEY_SQRT):
    deg(5)
  #déplacement
  if keydown(KEY_RIGHT): 
    x+= speed 
  if keydown(KEY_LEFT): 
    x-= speed 
  if keydown(KEY_UP): 
    y-= speed 
  if keydown(KEY_DOWN): 
    y+= speed 
    
  if keydown(KEY_ZERO):
    col = (255,255,255)
  if keydown(KEY_ONE): 
    col = (245,245,220) 
  if keydown(KEY_TWO): 
    col = (128,128,128) 
  if keydown(KEY_THREE): 
    col = (0,0,0) 
  if keydown(KEY_FOUR): 
    col = (255,0,0) 
  if keydown(KEY_FIVE): 
    col = (0,255,0) 
  if keydown(KEY_SIX): 
    col = (0,0,255) 
  if keydown(KEY_SEVEN): 
    col = (255,128,0)
  if keydown(KEY_EIGHT):
    col = (255,255,0)
  if keydown(KEY_NINE): 
    col = (255,0,255)
    
  if keydown(KEY_PLUS):
    if speed < 14:
      speed += 1
  if keydown(KEY_MINUS):
    if speed > 1:
      speed -= 1
      
  if keydown(KEY_DIVISION):
    if brightness <= 120:
      brightness += 10
  if keydown(KEY_MULTIPLICATION):
    if brightness >= -120:
      brightness -= 10
      
  if keydown(KEY_RIGHTPARENTHESIS):
    if radius < 14:
      radius += 1
  if keydown(KEY_LEFTPARENTHESIS):
    if radius > 1:
      radius -= 1
  
  if keydown(KEY_OK):
    x,y = 190,120
  
  if keydown(KEY_DOT):
    last = [500,500,col]
    while keydown(KEY_DOT) == True:
      pass
    if state == False:
      state = True
    else:
      state = False
  
    
  for x1 in range(x-radius,x+radius): 
    for y1 in range(y-radius,y+radius):
      for loop in range(3):
        if col[loop]+brightness >= 255:
          temp[loop] = 255
        elif (col[loop]+brightness) <= 0:
          temp[loop] = 0
        else:
          temp[loop] = col[loop]+brightness
      color = (temp[0],temp[1],temp[2])
      
  
      if state:
        set_pixel(last[0],last[1],last[2])
        last = [x,y,get_pixel(x,y)]
        set_pixel(x,y,(128,128,128))
      else:
        set_pixel(x1,y1,color)
  if keydown(KEY_POWER):
    sceau(get_pixel(x,y),color,x,y)

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.