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:04] – [Code] Mushussu | figure_de_lichtenberg [2020/10/28 12:22] – ↷ Liens modifiés en raison d'un déplacement. serge | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Figures de Lichtenberg ====== | ====== Figures de Lichtenberg ====== | ||
- | https:// | + | Définition sur [[https:// |
En mode analogique : | En mode analogique : | ||
- | https://www.youtube.com/watch?v=1jhqZg8UBJU | + | |
+ | [[https://youtu.be/1jhqZg8UBJU?t=145|Dangerous! Electrifying Woodworking!]] | ||
Sinon d’autres renseignements : | Sinon d’autres renseignements : | ||
- | http:// | ||
+ | [[http:// | ||
+ | |||
+ | ==== Illustration ==== | ||
+ | |||
+ | {{media_07: | ||
==== Théorie ==== | ==== Théorie ==== | ||
- | http:// | + | [[http:// |
+ | |||
+ | ===== Simulation ===== | ||
+ | |||
+ | ==== Résultat ==== | ||
+ | {{media_03: | ||
+ | ==== 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; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Processing 3D ==== | ||
+ | |||
+ | Voici le code avec exportation .png et .stl : | ||
+ | <code java> | ||
+ | import java.io.*; | ||
+ | import peasy.PeasyCam; | ||
+ | |||
+ | PeasyCam cam; | ||
+ | File repertoire; | ||
+ | |||
+ | |||
+ | ArrayList< | ||
+ | ArrayList< | ||
+ | int nombreMarcheurs = 1000; | ||
+ | int limite = 800; | ||
+ | int rangMax = 0; | ||
+ | |||
+ | public void settings() { | ||
+ | size(1000, 1000, P3D); | ||
+ | arbre = new ArrayList< | ||
+ | arbre.add(new Marcheur(0, 0, 0, limite)); | ||
+ | marcheurs = new ArrayList< | ||
+ | for (int i = 0; i < nombreMarcheurs; | ||
+ | marcheurs.add(new Marcheur(limite)); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public void setup() { | ||
+ | cam = new PeasyCam(this, | ||
+ | repertoire = new File(sketchPath()); | ||
+ | |||
+ | } | ||
+ | |||
+ | public void draw() { | ||
+ | lights(); | ||
+ | scale(1); | ||
+ | rotateX(PI/ | ||
+ | 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 (dist3DSq(m.position, | ||
+ | if (m.position.z > ma.position.z) { | ||
+ | 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 = pourtour(limite); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | affichageArbre(arbre); | ||
+ | if (marcheurs.size() == 0) { | ||
+ | println(rangMax); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void affichageArbre(ArrayList< | ||
+ | background(0); | ||
+ | for (int j = 1; j < a.size(); j++) { | ||
+ | Marcheur ma1 = a.get(j); | ||
+ | Marcheur ma2 = ma1.parent; | ||
+ | stroke(255); | ||
+ | strokeWeight(ma2.rayon / 3.5); | ||
+ | line(ma1.position.x, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void keyPressed() { | ||
+ | if (key == ' ') { | ||
+ | saveFrame(" | ||
+ | } | ||
+ | if (key == ' | ||
+ | exporterSTL(arbre); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void exporterSTL(ArrayList< | ||
+ | String ligne = " | ||
+ | for (int j = 1; j < a.size(); j++) { | ||
+ | if (j != 1) { | ||
+ | ligne += ","; | ||
+ | } | ||
+ | Marcheur ma1 = a.get(j); | ||
+ | Marcheur ma2 = ma1.parent; | ||
+ | String p1 = " | ||
+ | String p2 = " | ||
+ | ligne += " | ||
+ | } | ||
+ | ligne += " | ||
+ | println(ligne); | ||
+ | String[] cmd = {"/ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "u = " + ligne, | ||
+ | " | ||
+ | |||
+ | Process p; | ||
+ | try { | ||
+ | p = Runtime.getRuntime().exec(cmd, | ||
+ | p.waitFor(); | ||
+ | float error = p.exitValue(); | ||
+ | println(" | ||
+ | } | ||
+ | catch (InterruptedException e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | catch (IOException e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | class Marcheur { | ||
+ | PVector position; | ||
+ | Marcheur parent; | ||
+ | float rayon; | ||
+ | int rang; | ||
+ | int limite; | ||
+ | |||
+ | Marcheur(int l) { | ||
+ | limite = l; | ||
+ | position = pourtour(limite); | ||
+ | rayon = 15; | ||
+ | rang = 0; | ||
+ | } | ||
+ | |||
+ | Marcheur(int x, int y, int z, int l) { | ||
+ | limite = l; | ||
+ | position = new PVector(x, y, z); | ||
+ | rayon = 30; | ||
+ | rang = 1; | ||
+ | } | ||
+ | |||
+ | void rafraichir() { | ||
+ | PVector vitesse = PVector.random3D().setMag(30); | ||
+ | position.add(vitesse); | ||
+ | position.setMag(constrain(position.mag(), | ||
+ | } | ||
+ | |||
+ | void afficher(int r) { | ||
+ | noStroke(); | ||
+ | int teinte = (int)map(rang, | ||
+ | fill(teinte); | ||
+ | pushMatrix(); | ||
+ | translate(position.x, | ||
+ | sphere( 2 * rayon); | ||
+ | popMatrix(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | PVector pourtour(int l) { | ||
+ | PVector v = PVector.random3D().setMag(l); | ||
+ | v.z = abs(v.z); | ||
+ | return v; | ||
+ | } | ||
+ | |||
+ | float dist3DSq(PVector a, PVector b) { | ||
+ | float dx = b.x - a.x; | ||
+ | float dy = b.y - a.y; | ||
+ | float dz = b.z - a.z; | ||
+ | return dx * dx + dy * dy + dz * dz; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Pour la partie OpenSACD de l' | ||
+ | <code c> | ||
+ | $fn = 15; | ||
+ | |||
+ | u = [[[[10, 10, 10], 30], [[30, 20, 40], 20]], [[[30, 20, 40], 20], [[60, 30, 45], 10]]]; | ||
+ | for (i = [0:len(u) - 1]) { | ||
+ | element(u[i]); | ||
+ | } | ||
+ | module element(e) { | ||
+ | a = e[0]; | ||
+ | b = e[1]; | ||
+ | hull() { | ||
+ | translate(a[0]) sphere(d = a[1]); | ||
+ | translate(b[0]) sphere(d = b[1]); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
==== Code ==== | ==== Code ==== | ||
=== Heightmap === | === Heightmap === | ||
- | https:// | + | [[https:// |
=== Agrégation limitée par la diffusion (DLA) === | === Agrégation limitée par la diffusion (DLA) === | ||
- | https:// | + | [[https:// |
- | https:// | + | [[https:// |
- | https:// | + | [[https:// |
- | {{tag> | + | {{tag> processing sylvain}} |
figure_de_lichtenberg.txt · Dernière modification : 2021/04/21 10:48 de Mushussu