Console
Clique sur « Exécuter » pour lancer le programme.
Code CoddyRun
// === Triangle de Sierpinski ===
frac est une toile
dimension(frac, 400, 360)
remplir(frac, #1F2937)
fonction hexa(val)
retourne vers_hexadecimal(val, '', 2)
fin fonction
procédure sierpinski(frac, ax, ay, bx, by, cx, cy, niveau)
si niveau <= 0 alors
cgx est un nombre
cgx vaut (ax + bx + cx) / 3
// teinte 0..360 selon la position gauche->droite
teinte est un nombre
teinte vaut 360 * cgx / 400
coul est un texte
coul vaut teinte_vers_hex(teinte)
polygone(frac, ax, ay, bx, by, cx, cy, coul)
sinon
mabx, maby est un nombre
mbcx, mbcy est un nombre
macx, macy est un nombre
mabx vaut (ax + bx) / 2
maby vaut (ay + by) / 2
mbcx vaut (bx + cx) / 2
mbcy vaut (by + cy) / 2
macx vaut (ax + cx) / 2
macy vaut (ay + cy) / 2
appelle sierpinski(frac, ax, ay, mabx, maby, macx, macy, niveau - 1)
appelle sierpinski(frac, mabx, maby, bx, by, mbcx, mbcy, niveau - 1)
appelle sierpinski(frac, macx, macy, mbcx, mbcy, cx, cy, niveau - 1)
fin si
fin procédure
// Teinte (0..360) -> couleur hex arc-en-ciel pleine saturation
fonction teinte_vers_hex(h)
secteur, f est un nombre
r, v, b est un nombre
secteur vaut arrondi_inferieur(h / 60)
f vaut h / 60 - secteur
si secteur = 0 alors
r vaut 255
v vaut arrondi(255 * f)
b vaut 0
sinon si secteur = 1 alors
r vaut arrondi(255 * (1 - f))
v vaut 255
b vaut 0
sinon si secteur = 2 alors
r vaut 0
v vaut 255
b vaut arrondi(255 * f)
sinon si secteur = 3 alors
r vaut 0
v vaut arrondi(255 * (1 - f))
b vaut 255
sinon si secteur = 4 alors
r vaut arrondi(255 * f)
v vaut 0
b vaut 255
sinon
r vaut 255
v vaut 0
b vaut arrondi(255 * (1 - f))
fin si
retourne '#' + hexa(r) + hexa(v) + hexa(b)
fin fonction
appelle sierpinski(frac, 200, 20, 30, 330, 370, 330, 6)
affiche frac