nsi:langages:processing:solutions:vol_nuee_oiseaux
Différences
Ci-dessous, les différences entre deux révisions de la page.
| nsi:langages:processing:solutions:vol_nuee_oiseaux [2022/11/02 11:15] – créée goupillwiki | nsi:langages:processing:solutions:vol_nuee_oiseaux [2022/11/02 11:22] (Version actuelle) – goupillwiki | ||
|---|---|---|---|
| Ligne 3: | Ligne 3: | ||
| Solution du TD [[nsi: | Solution du TD [[nsi: | ||
| + | <WRAP tip>'' | ||
| <code java> | <code java> | ||
| - | final int N = 200; | + | final int N = 200; // nombre total d' |
| - | final int V = 2; | + | final int V = 2; // vitesse de chaque oiseau |
| - | final int Rmax = 30; | + | final int Rmax = 30; // rayon pour le voisinage |
| - | final float s = 0.3; | + | final float s = 0.3; // coefficient pour adoucir l' |
| - | Bird[] birds = new Bird[N]; | + | Bird[] birds = new Bird[N]; |
| void setup() { | void setup() { | ||
| Ligne 32: | Ligne 33: | ||
| class Bird { | class Bird { | ||
| + | /* classe décrivant un oiseau */ | ||
| float x, y, angle; | float x, y, angle; | ||
| Bird() { | Bird() { | ||
| + | /* un oiseau est initialisé aléatoirement sur la fenêtre */ | ||
| x = random(width); | x = random(width); | ||
| y = random(width); | y = random(width); | ||
| Ligne 40: | Ligne 43: | ||
| | | ||
| void display() { | void display() { | ||
| - | // un cercle | + | /* l' |
| + | pour donner l' | ||
| + | */ | ||
| circle(x, y, 5); | circle(x, y, 5); | ||
| float dx = 10*cos(radians(angle)); | float dx = 10*cos(radians(angle)); | ||
| Ligne 48: | Ligne 53: | ||
| | | ||
| void update() { | void update() { | ||
| + | /* met à jour la position de l' | ||
| + | | ||
| + | si l' | ||
| + | il réapparaît à l' | ||
| + | */ | ||
| float vx = V*cos(radians(angle)); | float vx = V*cos(radians(angle)); | ||
| float vy = V*sin(radians(angle)); | float vy = V*sin(radians(angle)); | ||
| Ligne 65: | Ligne 75: | ||
| | | ||
| float d2(Bird b){ | float d2(Bird b){ | ||
| - | // renvoie la distance | + | /* renvoie la distance**2 de self |
| + | avec l' | ||
| + | */ | ||
| return (x - b.x)*(x - b.x) + (y - b.y)*(y-b.y); | return (x - b.x)*(x - b.x) + (y - b.y)*(y-b.y); | ||
| } | } | ||
| | | ||
| float ecartAngle(Bird b) { | float ecartAngle(Bird b) { | ||
| - | // renvoie | + | /* mesure |
| + | | ||
| + | */ | ||
| float ecart = b.angle - angle; | float ecart = b.angle - angle; | ||
| if (ecart > 180) { | if (ecart > 180) { | ||
| Ligne 83: | Ligne 97: | ||
| | | ||
| void align(Bird[] birds){ | void align(Bird[] birds){ | ||
| - | /* parmi les position à moins de Rmax, | + | /* parmi l' |
| - | prend l' | + | cherche les oiseaux qui sont dans le voisinage |
| - | et fait la moyenne | + | pour chacun d'eux cumule |
| - | | + | de calculer |
| + | | ||
| */ | */ | ||
| float a = 0; | float a = 0; | ||
nsi/langages/processing/solutions/vol_nuee_oiseaux.1667384157.txt.gz · Dernière modification : de goupillwiki
