draw_functions.py

Created by ziii

Created on December 20, 2023

638 Bytes

Two function to use the paint.py output, the function decode takes the tuple with the encoded drawing and gives you a decoded drawing, the second one takes the position at which you want to draw it, the color, in option the upscaling, the decoded drawing and draws it.


from math import log2
from kandinsky import fill_rect
def decode(encoded_drawing):
    drawing=0
    q=1
    for i in range(len(encoded_drawing[0])):
      drawing+= (ord(encoded_drawing[0][i]) -35) * q
      q *= 92
    return (drawing,encoded_drawing[1],encoded_drawing[2])
def draw(x,y,color,drawing,scale=1):
    for i in range(int(log2(drawing[0]))+2):
      if (drawing[0] >> i) & 1:
        fill_rect(x+(i%drawing[1])*scale,y+(i//drawing[1])*scale,scale,scale,color)
exemple=("t7K7cD`d$(:`TX3?RJvGJ<'.Xf#Pi<Q7+MMU)g#@+bn}Uo?#yN2RT^T;>KxF2UVe~EAcHPsUT5$",22,22)
draw(80,10,(0,149,255),decode(exemple),scale=9)