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)

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.