Ligne 213 : |
Ligne 213 : |
| Il est assez facile de créer et afficher une icône. | | Il est assez facile de créer et afficher une icône. |
| | | |
− | La fonction `draw_icon()`. | + | L'icône est définie avec un 1 pour un point allumé et un 0 pour un point éteint: |
| + | |
| + | <syntaxhighlight lang="python">HEART_ICON = [ |
| + | [0,0,0,0,0,0,0,0,0,0,0], |
| + | [0,0,1,1,1,0,1,1,1,0,0], |
| + | [0,1,1,0,1,1,1,1,1,1,0], |
| + | [0,1,0,1,1,1,1,1,1,1,0], |
| + | [0,1,1,1,1,1,1,1,1,1,0], |
| + | [0,0,1,1,1,1,1,1,1,0,0], |
| + | [0,0,0,1,1,1,1,1,0,0,0], |
| + | [0,0,0,0,1,1,1,0,0,0,0], |
| + | [0,0,0,0,0,1,0,0,0,0,0], |
| + | [0,0,0,0,0,0,0,0,0,0,0] ]</syntaxhighlight> |
| + | |
| + | La fonction {{fname|draw_icon()}} permet de dupliquer le contenu d'un "pseudo tableau" (l'icône) sur l'écran aux coordonnées x,y. |
| | | |
| <syntaxhighlight lang="python">def draw_icon( lcd, from_x, from_y, icon ): | | <syntaxhighlight lang="python">def draw_icon( lcd, from_x, from_y, icon ): |
Ligne 222 : |
Ligne 236 : |
| lcd.pixel( from_x+x, | | lcd.pixel( from_x+x, |
| from_y+y, | | from_y+y, |
− | color ) | + | color )</syntaxhighlight> |
− | </syntaxhighlight> | + | |
| + | Le code est prévu pour définir des icônes avec un Canal Alpha (avec des 1, 0 et None). |
| + | * Les points marqués 1 sont allumés. |
| + | * Les points marqués 0 sont éteints. |
| + | * Les points marqués None sont ignorés (donc non modifiés sur l'affichage). |
| + | |
| + | Dans l'exemple ci-dessous, la variable {{fname|a}} est assignée a {{fname|None}} et utilisé comme valeur de Canal Alpha. |
| + | |
| + | <syntaxhighlight lang="python">a = None |
| + | FB_ICON = [ |
| + | [a,a,a,a,a,a,a,a,a,a,0,0,a,a,a,a,a], |
| + | [a,a,a,a,a,a,a,a,a,0,0,0,0,a,a,a,a], |
| + | [a,a,a,a,a,a,a,a,0,0,1,1,0,0,a,a,a], |
| + | [a,a,a,a,a,a,a,0,0,1,0,1,0,0,a,a,a], |
| + | [a,a,a,a,a,a,a,0,0,1,0,1,0,0,a,a,a], |
| + | [a,a,a,a,a,a,a,0,0,1,0,1,0,0,a,a,a], |
| + | [a,a,a,a,a,a,0,0,1,0,0,1,0,0,0,0,a], |
| + | [0,0,1,1,1,1,1,1,0,0,0,1,1,1,1,0,0], |
| + | [0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,1,1,1,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,0,a,0,1,1,1,1,1,0,0,a], |
| + | [a,0,0,0,0,0,0,a,0,0,0,0,0,0,0,a,a], |
| + | [a,0,0,0,0,0,a,a,a,0,0,0,0,0,0,a,a] ]</syntaxhighlight> |
| + | |
| + | |
| + | |
| + | Le script ci-dessous exploite l'affichage d'icône sous différentes formes: |
| + | # Affichage d'une icône simple. |
| + | # Affichage aléatoire d'une icône de façon aléatoire. |
| + | # Affichage d'une icône avec Canal Alpha. |
| | | |
− | Mise en place en dessinant une croix noir sur fond blanc.
| |
| <syntaxhighlight lang="python">cat icon.py | | <syntaxhighlight lang="python">cat icon.py |
| from machine import Pin, I2C | | from machine import Pin, I2C |