Outils pour utilisateurs

Outils du site


figure_de_lichtenberg

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
Prochaine révisionLes deux révisions suivantes
figure_de_lichtenberg [2019/11/18 01:11] Mushussufigure_de_lichtenberg [2019/11/24 09:13] – [Processing 3D] Mushussu
Ligne 149: Ligne 149:
  
 ==== Processing 3D ==== ==== Processing 3D ====
-<code java> 
  
 +Voici le code avec exportation .png et .stl :
 +<code java>
 +import java.io.*;
 import peasy.PeasyCam; import peasy.PeasyCam;
  
 PeasyCam cam; PeasyCam cam;
 +File repertoire;
 +
  
 ArrayList<Marcheur> arbre; ArrayList<Marcheur> arbre;
 ArrayList<Marcheur> marcheurs; ArrayList<Marcheur> marcheurs;
-int nombreMarcheurs = 2000;+int nombreMarcheurs = 1000;
 int limite = 800; int limite = 800;
 int rangMax = 0; int rangMax = 0;
Ligne 173: Ligne 177:
 public void setup() { public void setup() {
   cam = new PeasyCam(this, 400);   cam = new PeasyCam(this, 400);
 +    repertoire = new File(sketchPath());
 +
 } }
  
Ligne 203: Ligne 209:
     }     }
   }   }
-  affichageArbre();+  affichageArbre(arbre);
   if (marcheurs.size() == 0) {   if (marcheurs.size() == 0) {
     println(rangMax);     println(rangMax);
Ligne 209: Ligne 215:
 } }
  
-void affichageArbre() {+void affichageArbre(ArrayList<Marcheur> a) {
   background(0);   background(0);
-  for (int j = 1; j < arbre.size(); j++) { +  for (int j = 1; j < a.size(); j++) { 
-    Marcheur ma1 = arbre.get(j);+    Marcheur ma1 = a.get(j);
     Marcheur ma2 = ma1.parent;     Marcheur ma2 = ma1.parent;
     stroke(255);     stroke(255);
Ligne 224: Ligne 230:
     saveFrame("images/DLA3D-######.png");     saveFrame("images/DLA3D-######.png");
   }   }
 +  if (key == 'e') {
 +    exporterSTL(arbre);
 +  }
 +}
 +
 +void exporterSTL(ArrayList<Marcheur> a) {
 +  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 = "[" + ma1.position.x + "," + ma1.position.y + "," + ma1.position.z + "]";
 +      String p2 = "[" + ma2.position.x + "," + ma2.position.y + "," + ma2.position.z + "]";
 +      ligne += "[[" + p1 + "," + ma1.rayon / 3.5 + "]," + "[" + p2 + "," + ma2.rayon / 3.5 + "]]";
 +    }
 +    ligne += "]";
 +    println(ligne);
 +    String[] cmd = {"/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD", 
 +      "-o", 
 +      "Arbre.stl", 
 +      "-D", 
 +      "u = " + ligne, 
 +      "Arbre.scad"};
 +      
 +    Process p;
 +    try {
 +      p = Runtime.getRuntime().exec(cmd, new String[0], repertoire);
 +      p.waitFor();
 +      float error = p.exitValue();
 +      println("Erreur = " + error);
 +    } 
 +    catch (InterruptedException e) {
 +      e.printStackTrace();
 +    } 
 +    catch (IOException e) {
 +      e.printStackTrace();
 +    }
 } }
  
Ligne 275: Ligne 320:
   float dz = b.z - a.z;   float dz = b.z - a.z;
   return dx * dx + dy * dy + dz * dz;   return dx * dx + dy * dy + dz * dz;
 +}
 +</code>
 +
 +Pour la partie OpenSACD de l'exportation .stl :
 +<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>
figure_de_lichtenberg.txt · Dernière modification : 2021/04/21 10:48 de Mushussu