figure_de_lichtenberg
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédenteProchaine révisionLes deux révisions suivantes | ||
figure_de_lichtenberg [2019/11/07 18:06] – [Figures de Lichtenberg] Mushussu | figure_de_lichtenberg [2019/11/17 11:51] – Mushussu | ||
---|---|---|---|
Ligne 2: | Ligne 2: | ||
https:// | https:// | ||
- | |||
En mode analogique : | En mode analogique : | ||
https:// | https:// | ||
Ligne 9: | Ligne 8: | ||
http:// | http:// | ||
+ | ==== Illustration ==== | ||
+ | |||
+ | {{: | ||
==== Théorie ==== | ==== Théorie ==== | ||
Ligne 14: | Ligne 16: | ||
http:// | http:// | ||
+ | ===== Simulation ===== | ||
+ | ==== Processing ==== | ||
+ | <code java> | ||
+ | ArrayList< | ||
+ | ArrayList< | ||
+ | int nombreMarcheurs = 2000; | ||
+ | int rangMax = 0; | ||
+ | |||
+ | |||
+ | void setup() { | ||
+ | size(1600, 1000); | ||
+ | arbre = new ArrayList< | ||
+ | arbre.add(new Marcheur(width / 2, height)); | ||
+ | marcheurs = new ArrayList< | ||
+ | for (int i = 0; i < nombreMarcheurs; | ||
+ | marcheurs.add(new Marcheur()); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | background(0); | ||
+ | for (int i = marcheurs.size() - 1; i >= 0; i--) { | ||
+ | Marcheur m = marcheurs.get(i); | ||
+ | m.rafraichir(); | ||
+ | // | ||
+ | for (int j = 0; j < arbre.size(); | ||
+ | Marcheur ma = arbre.get(j); | ||
+ | if (m.position.dist(ma.position) < (2 * ma.rayon - 4)) { | ||
+ | if (m.position.y < ma.position.y) { | ||
+ | marcheurs.remove(m); | ||
+ | m.rayon = ma.rayon * 0.97; | ||
+ | m.rang = ma.rang + 1; | ||
+ | m.parent = ma; | ||
+ | if (m.rang > rangMax) { | ||
+ | rangMax = m.rang; | ||
+ | } | ||
+ | arbre.add(m); | ||
+ | break; | ||
+ | } else { | ||
+ | m.position = haut(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | for (int i = arbre.size() - 1; i >= 0; i--) { | ||
+ | Marcheur ma = arbre.get(i); | ||
+ | ma.afficher(rangMax); | ||
+ | } | ||
+ | if (marcheurs.size() == 0) { | ||
+ | affichageArbre(); | ||
+ | println(rangMax); | ||
+ | saveFrame(" | ||
+ | noLoop(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void affichageArbre() { | ||
+ | background(0); | ||
+ | for (int j = 1; j < arbre.size(); | ||
+ | Marcheur ma1 = arbre.get(j); | ||
+ | Marcheur ma2 = ma1.parent; | ||
+ | stroke(255); | ||
+ | strokeWeight(ma2.rayon / 3.5); | ||
+ | line(ma1.position.x, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | class Marcheur { | ||
+ | PVector position; | ||
+ | Marcheur parent; | ||
+ | float rayon; | ||
+ | int rang; | ||
+ | |||
+ | Marcheur() { | ||
+ | position = haut(); | ||
+ | rayon = 15; | ||
+ | rang = 0; | ||
+ | } | ||
+ | |||
+ | Marcheur(int x, int y) { | ||
+ | position = new PVector(x, y); | ||
+ | rayon = 30; | ||
+ | rang = 0; | ||
+ | } | ||
+ | |||
+ | void rafraichir() { | ||
+ | PVector vitesse = PVector.random2D().setMag(30); | ||
+ | position.add(vitesse); | ||
+ | position.x = constrain(position.x, | ||
+ | position.y = constrain(position.y, | ||
+ | } | ||
+ | |||
+ | void afficher(int r) { | ||
+ | noStroke(); | ||
+ | int teinte = (int)map(rang, | ||
+ | fill(teinte); | ||
+ | ellipse(position.x, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | PVector pourtour() { | ||
+ | int a = (int)random(3); | ||
+ | if (a == 0) { | ||
+ | float r = random(width); | ||
+ | return new PVector(r, 0); | ||
+ | } else if (a == 1) { | ||
+ | float t = random(height); | ||
+ | return new PVector(0, t); | ||
+ | } else { | ||
+ | float u = random(width); | ||
+ | return new PVector(width, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | PVector haut() { | ||
+ | float r = random(width); | ||
+ | return new PVector(r, 0); | ||
+ | } | ||
+ | |||
+ | float distSq(PVector a, PVector b) { | ||
+ | float dx = b.x - a.x; | ||
+ | float dy = b.y - a.y; | ||
+ | return dx * dx + dy * dy; | ||
+ | } | ||
+ | </ | ||
==== Code ==== | ==== Code ==== |
figure_de_lichtenberg.txt · Dernière modification : 2021/04/21 10:48 de Mushussu