alphabet.py

Created by schraf

Created on April 03, 2023

629 Bytes

La fonction aff affiche du texte (txt) à la position (x,y), de taille t, de couleur fg (ex : (255,0,0) pour du rouge). Les 3 derniers paramètres sont optionnels et permettent d’ajouter une couleur de fond bg, d’avoir des traits verticaux (a=1,b=0), horizontaux (a=0,b=1), unis (a=0,b=0) ou carrés (a=1,b=1)

Attention ! Le programme a besoin d’utiliser les pixels entre (0,0) et (8,17), il ne faut donc rien afficher dans cette zone ou alors la déplacer (lignes 6 et 12)

Vous pouvez donner d’autres valeurs à a et b, voici un exemple avec le résultat obtenu :

aff('Score',20, -5, 6, BL,GR,a=3,b=-2)
aff('0123456789',20,85,3,RE,a=2,b=2)
for i in range(26):
  aff(chr(97+i),25+10*i,132,1,BL,GR,-2,0)
  aff(chr(65+i),25+10*i,172+30*(i%2)-15,2,[BL,RE][i%2],a=-1,b=-2)


from kandinsky import *

BL,WH,GR,RE = (0,0,0),(255,255,255),(230,)*3,(255,0,0)

def dot(x,y,c,fg,bg,t,a,b):
  draw_string(c,0,0,GR,WH)
  fill_rect(x,y,9*t,18*t,bg)
  for v in range(18):
    for u in range(9):
      if get_pixel(u,v)!=WH:
        fill_rect(x+u*t,y+v*t,t-a,t-b,fg)
  draw_string(" ",0,0,WH,WH)        

def aff(txt,x,y,t,fg,bg=WH,a=1,b=1):
  for (i,c) in enumerate(txt):
    dot(x+i*t*9,y,c,fg,bg,t,a,b)

# Exemples
aff('Score',20,-5,6,BL,GR)
aff('0123456789',20,85,3,RE,b=0)
for i in range(26):
  aff(chr(97+i),25+10*i,132,1,BL,GR,0,0)
  aff(chr(65+i),25+10*i,172+30*(i%2)-15,2,[BL,RE][i%2],a=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.