pixelart.py

Created by wperez274

Created on April 04, 2023

1.76 KB

locate x,y coordinates


from kandinsky import *
from ion import *
from time import sleep

BL = (248,255,248)
NR = (0,)*3
GR = (220,)*3
d = 18

ALLPIX=[]
  




def grille():
  
  for i in range(320//d):
    fill_rect(d*i,0,1,d*(220//d),GR)
    if d*i <= 220:
      fill_rect(0,d*i,320,1,GR)

def dec(c,n):
  v = list(c)
  if n == 4:
    v = [max(0, e - 51) for e in v]
  elif n == 6:
    v = [min(255, e + 51) for e in v]
  else: 
    v[n] = v[n] + 51 % 306
  return tuple(v)
  
  
#*******************************
def touche(x,y,e,coul):
  
  global d
  px=x
  py=y
  pw=d
  ph=d
  pc=coul
  
  n=[px,py,pw,ph,pc]
  
  
  
  
  c = coul if e else get_pixel(x+1,y+1)
  etat = 0
  while not keydown(KEY_BACKSPACE):
    sleep(.08)
    dx,dy = keydown(KEY_RIGHT)-keydown(KEY_LEFT), keydown(KEY_DOWN)-keydown(KEY_UP)
    if keydown(KEY_ZERO): e = 0 
    if keydown(KEY_ONE): e,c = 1,(255,0,0)
    if keydown(KEY_TWO): e,c = 1,(0,255,0)
    if keydown(KEY_THREE): e,c = 1,(0,0,255)
    if keydown(KEY_FOUR): e,c = 1,dec(c,4)
    if keydown(KEY_SIX): e,c = 1,dec(c,6)
    if keydown(KEY_SEVEN): e,c = 1,dec(c,0)
    if keydown(KEY_EIGHT): e,c = 1,dec(c,1)
    if keydown(KEY_NINE): e,c = 1,dec(c,2)
    if keydown(KEY_OK): e,c = 1,BL
  
    if dx != 0 or dy != 0:
      rect(x,y,c)
      return [dx, dy, e, c]
      etat = 1 - etat
    if e:rect(x,y,c)
     
    else:rect(x,y,c if etat else GR)
    
def rect(x,y,c):
  fill_rect(x+1,y+1,d-1,d-1,c)

def pixelart():
  grille()
  x,y,t = d*(160//d),d*(100//d),0
  ecrire, coul = 0, NR
  while not keydown(KEY_EXE): 
    draw_string(str(x)+","+str(y),260,0,"blue")
    draw_string("ALLPIX:"+str(ALLPIX),2,0,"blue")
    fill_rect(140,2,20,18,coul)
    t = touche(x,y,ecrire,coul)
    x += d * t[0]
    y += d * t[1]
    ecrire = t[2]
    coul = t[3]
    
pixelart()

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.