dessin6.py

Created by mathieu-croslacoste

Created on January 04, 2025

2.66 KB

Script pour pixel art. peut etre affiché avec “dessin6” (ce script, donc)

Flèches pour bouger. Alpha pour sélectionner une couleur déja enregistrée

Copier le code (toute les lignes si plus qu’une) dans un fichier nommé “image_test2” affiché à la fin du programme, sous la forme de ‘im=”[votre code]”’.

ATTENTION !

Si vous avez enregistrés de nouvelles couleurs, copiez aussi la palette (le truc avec pleins de nombres et de parenthèses), sous la forme de ‘pal=[votre palette ici]’


from kandinsky import fill_rect as fr,draw_string as ds
from random import choice as rch,randint as ra;from ion import keydown as kd;from time import sleep as sl
pal,im,screen,sel,osel,color=[(255,)*3],'A4480',[],0,0,0
try:size=int(input('Pixel size ? (4 (small) to 50 (big))\n'))
except:size=4
if size<4:size=4
if size>50:size=50
w,h=320/size,222/size
z=[0,0]
if int(w)!=w:z[0]=1
if int(h)!=h:z[1]=1
w,h=int(w),int(h)
w+=z[0];h+=z[1]
del z
def gm_i(l=0):
 r,i,t=0,0,size
 while r<len(im):
  s,n=im[r],'';r+=1
  while r<len(im)and'9'>=im[r]>='0':n+=im[r];r+=1
  nb=1 if n==''else int(n)
  if s!="A"or l:
   c=pal[ord(s)-65]
   for j in range(nb):fr(t*(i%w),t*(i//w),t,t,c);i+=1
  else:i+=nb
def load(im,t=4,po=0,py=0):
 r,i=0,0
 while r<len(im):
  s,n=im[r],'';r+=1
  while r<len(im)and'9'>=im[r]>='0':n+=im[r];r+=1
  nb=1 if n==''else int(n)
  for j in range(nb):screen.append(ord(s)-65);i+=1
def col():
 global pal
 try:
  r=int(input('COLOR(r,g,b)\nR : '));g=int(input('G : '));b=int(input('B : '))
  if((r,g,b)in pal)^1:pal.append((r,g,b))
  try:fr(0,0,-10,-10,(r,g,b))
  except:return-1
  return pal.index(r,g,b)
 except:ds("error",0,0);sl(.4);return-1
def update():fr(size*(osel%w),size*(osel//w),size,size,(255,)*3);gm_i();fr(size*(sel%w),size*(sel//w),size,size,(255,0,0))
def select(add):
 new=sel+add
 if new>w*h:new-=w*h
 if new<0:new+=w*h
 return new
def mod():global screen;screen[sel]=color;compress()
def compress():
 global im;letters,im,r,nb=('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'),'',0,0
 while r<len(screen):
  new,nb=screen[r],0
  while r<len(screen)and screen[r]==new:nb+=1;r+=1
  if nb==1:nb=""
  im+=letters[new]+str(nb)
def pal_sel():
 global color;fr(0,0,320,222,(255,)*3)
 while kd(4)^1:
  ds("[-]    [+]",110,103);fr(149,99,22,22,(0,)*3);fr(150,100,20,20,pal[color])
  while(kd(45)|kd(46)|kd(4))^1:0
  if not kd(4):color+=kd(45)-kd(46)
  if color<0:color=len(pal)-1
  if color>=len(pal):color=0
  while kd(45)|kd(46):0
 gm_i(1)
if input("load ? y/n\n")=="y":from image_test2 import*;load(im)
else:
 for i in range(w*h):screen.append(0)
try:
 while kd(52)^1:
  update();osel=sel
  while(kd(0)|kd(1)|kd(2)|kd(3)|kd(4)|kd(12)|kd(13)|kd(52))^1:0
  if kd(12):
   new=col()
   if new!=-1:color=new
   sl(.3)
  if kd(13):pal_sel();sl(.4)
  else:
   for i in range(5):
    if kd(i):
     if i==4:
      if len(pal):mod()
     else:sel=select([-1,-w,w,1][i])
     sl(.065+kd(4)/13)
  sl(.001)
except KeyboardInterrupt:0
j=1
while j:
 try:
  txt,off=[""],0
  while len(im)>0:
   if len(txt[off])>218:txt.append("");off+=1
   txt[off]+=im[0];im=im[1:]
#  print('size :',size,"\n"+str(pal))
  for i in txt:print(i)
  j=0
 except:0

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.