Logique
Boucles
Math
Texte
Listes
Données
Variables
Fonctions
Programmation
p5.js
Objets web
Propriétés
Formes
Tortue
Apparence
GeoGebra
var canevas, Px, Py, Ax, Ay, Bx, By, Cx, Cy, choix; /** * Fonction exécutée une fois, au départ */ function actions_initiales() { choixAxes("MATH"); canevas=creerCanvas(600,600); canvas=canevas; Ax = 0; Ay = 300; Bx = -300; By = -300; Cx = 300; Cy = -300; Px = 0; Py = 0; point_(Px,Py); } function mathRandomInt(a, b) { if (a > b) { // Swap a and b to ensure a is smaller. var c = a; a = b; b = c; } return Math.floor(Math.random() * (b - a + 1) + a); } /** * Fonction exécutée périodiquement, de façon répétée */ function actions_en_boucle() { for (var count = 0; count < 1000; count++) { choix = mathRandomInt(1, 3); if (choix == 1) { Px = (Ax + Px) / 2; Py = (Ay + Py) / 2; stroke_('#ff0000'); point_(Px,Py); } if (choix == 2) { Px = (Bx + Px) / 2; Py = (By + Py) / 2; stroke_('#33cc00'); point_(Px,Py); } if (choix == 3) { Px = (Cx + Px) / 2; Py = (Cy + Py) / 2; stroke_('#33ccff'); point_(Px,Py); } } }