Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Tentakelornament

26. Oktober 2011

Dieses Skript ist eine Weiterentwicklung des "Tentakelbaums". Anstelle einer Baumstruktur werden "nur" einzelne Ranken beim Klicken an der aktuellen Mausposition erzeugt. Durch eine Zufallszahl wird festgelegt, wie viele Ranken vom Mittelpunkt aus erzeugt werden und wie in welchem Winkel. Da der Hintergrund nicht neu gefüllt wird, können ganze Bilder so "gezeichnet" werden.
// Settings
color FLOWER_FILL  = color(180, 183, 245);
color FLOWER_STROKE = color(53, 0, 180);



// STACK OVERWRITE
// adjust this value to whatever depth is actually necessary
public final int STACK_DEPTH = 512;
public float[][] matrixStack = new float[STACK_DEPTH][6];
public int matrixStackDepth;
 
// this version will override the built-in version pushMatrix function
public void pushMatrix() {
  if (matrixStackDepth == 512) {
    throw new RuntimeException("too many calls to pushMatrix()");
  }
  this.g.getMatrix().get(matrixStack[matrixStackDepth]);
  matrixStackDepth++;
}
 
// this version will override the built-in version popMatrix function
public void popMatrix() {
  if (matrixStackDepth == 0) {
    throw new RuntimeException("too many calls to popMatrix()" +
                               "(or too few to pushMatrix)");
  }
  matrixStackDepth--;
  PMatrix2D m = new PMatrix2D();
  m.set(matrixStack[matrixStackDepth]);
  this.g.setMatrix(m);
}



// SKRIPT
void setup() {
  size(600, 600);
  randomSeed(millis()+100);
  smooth();
  strokeWeight(3); 
  background(255);
}
 
void draw() {

 
}

// Mouseclick -> Redraw
void mousePressed() {
  pushMatrix();
    translate(mouseX, mouseY);
    struct(2);
  popMatrix();
}

// Shortcuts
void keyPressed() {
  switch(key) {
    
  // Save as Image
  case 's':
    saveFrame("TREE-####.PNG");
    println("IMAGE SAVED!");
    break;
  case 'r':
    background(255);
    break;
    
  }
}

void struct(int tiefe) {
  
  if (tiefe <= 0) {
    return;
  }
  
  int rand =(int) (random(1, 4) + .5);
  
  
  pushMatrix();
    
    switch(rand) {
    case 1:
      for (int i = 1; i < (int) random(3, 8); i++) {
        rotate(radians(random(-180, 180)));
        wurzel(100, 0, -20, 0);
      }
      break;
    case 2:
      for (int i = 1; i < (int) random(3, 8); i++) {
        rotate(radians(random(-180, 180)));
        wurzel(100, 0, -20, 0, -1);
      }
      break;
    case 3:
    for (int i = 1; i < (int) random(3, 8); i++) {
        rotate(radians(random(-180, 180)));
        wurzel(100, 0, -20, 0);
      wurzel(100, 0, -20, 0, -1);
      }      
      break;
    }
        
  popMatrix();
  
}

// Wurzel Preset
void wurzel(int tiefe, int x, int y, int rad){
  wurzel(tiefe, x, y, rad, 1);
}

// Wurzel
void wurzel(int tiefe, int x, int y, int rad, int turn) {

  if (tiefe <=0) {
    fill(FLOWER_FILL);
    stroke(FLOWER_STROKE);
    strokeWeight(2);
    //ellipse(0,0,50,50);
    stroke(0);
    strokeWeight(10);
    return;
  }

  line(0, 0, x, y);
  float factor =  tiefe / 10;
  if (random(1, 30) < factor) {
    wurzel(6, x, y, 0, turn * -1);
  }
 
  pushMatrix();
    translate(x, y);
    rotate(radians(rad * turn));
    scale(random(0.7, 0.9));
    x += 5 * turn;
    y -= 2;
    rad += 3;
    wurzel(tiefe - 1, x, y, rad, turn);
  popMatrix();

}