microtext.py

Created by tristan-lusson

Created on November 10, 2022

2.1 KB

“draw_string”, but smaller.


from kandinsky import *

ref = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?!.,:;%+-*/=<>'_→[](){}"
font = "2jg02oN06Fd07AE04l907dE07dl079907gl07h906lj06kl03aZ06jk07dd07da03bh05lj07IN079h05kj04ad05zj01li03jk06la06jwG6kj03YE07II05jl05jg05jz05gj05gI07Ad003l04cl003d01Bl007p03ca003lE4cj026N0119g4br04aZ007z006j007l006la03l907a003M04dZ005l005g005?005L005hE07AO7A202I200020002W0220022W5Ab00NG007000ge01AKW0uu01KH04HK02G00000u4NK03IJ06IM01IH04IK03MJ06JM0"
mods = [0,0]

def dml(l,x=1,y=1):
  for seq in range(4):
    v=ref.index(font[(ref.index(l)*4)+seq])
    b = 32
    for i in range(6):
      if v>=b:
        set_pixel(i%3+x,i//3+(2*seq)+y,(0,0,0))
        v-=b
      b = b//2
      

def dms(s,x=1,y=1):
  global mods
  mod = False
  for l in range(len(s)):
    if mod:
      if s[l]=="_":mods[0]=1
      if s[l]==".":mods[0]=2
      if s[l]=="-":mods[0]=3
      if s[l]=="0":mods[0]=0
      if s[l]=="→":
        dml("→",x,y)
        x +=4
      mod = False
    else:
      if s[l]=="→":
        mod = True
      else:
        if mods[0]==1:fill_rect(x-1,y+7,5,1,(150,150,150))
        if mods[0]==2:fill_rect(x+1,y+7,2,1,(150,150,150))
        if mods[0]==3:fill_rect(x-1,y+4,5,1,(150,150,150))
        if not s[l]==" ":
          dml(s[l],x,y)
        x +=4
        
def how_microtext():
  dms("The microtext script is a compact way to draw text in python.")
  dms("The calculator screen can hold 2358 characters instead of 419 with the default",1,9)
  dms("font. That 6.5 times more !",1,17)
  dms("To use the script, use the fonction as shown below:",1,33)
  dms(">>> from microtext import →.dms→0",1,41)
  dms(">>> dms(→_str(text)→0, →_int(x)→0, →_int(y)→0)",1,49)
  dms("But there's more... By using the arrow '→→' on the 'F' key folowed by an other",1,65)
  dms("character, you can modify the following text:",1,73)
  dms("-'→→_' to →_underline→0.",9,89)
  dms("-'→→.' to →.underline with dots→0.",9,97)
  dms("-'→→-' to →-crros→0 cross.",9,105)
  dms("-'→→0' to disable modification.",9,113)
  dms("-'→→→→' to display the arrow.",9,121)
  dms("That's all for now; Might update later for colors.",1,137)