txt_color.py

Created by schraf

Created on October 11, 2018

540 Bytes

txt("Bonjour",10,20,color(255,0,0)) met le texte “Bonjour” en rouge à la position (10,20)
L’idée est de récupérer les valeurs Rouge-Vert-Bleu des pixels du texte écrit en noir et gris et de les convertir dans la couleur voulue. Chaque lettre fait 10*18 pixels


from kandinsky import *

def txt(t,x,y,c=0):
  draw_string(t,x,y)
  for i in range(180*len(t)):
      u = get_pixel(x+i//18,y+i%18)
      b = 8*max(u%32, c%32)
      v = 4*max((u>>5)%64, (c>>5)%64)
      r = 8*max(u>>11, c>>11)
      set_pixel(x+i//18,y+i%18,color(r,v,b))
        
txt("En rouge ! &",10,20,63488)
txt("En VERT #2016",10,40,2016)
txt("Bleu /:8*",10,60,color(0,0,255))
txt("MAGENTA",10,80,color(255,0,255))
txt(">>azur<<",10,100,color(0,127,255))
txt("OrAnGe",10,120,color(255,127,0))
txt("Noir...=>",10,140)

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.