Digital fabrication

Aus Entropie

Wechseln zu: Navigation, Suche

Digitale Technologien wie Rapid Prototyping, Laser Cutting und CNC Fräsen ermöglichen den Wandel industrieller Produktionsprozesse weg von Massenproduktion zur Fertigung nach Mass mit individuellen Anpassungen. Das Verwenden dieser Technologien erlaubt es programmbasierte Gestaltungstechniken auf physische Formen zu übertragen und die Grenzen des virtuellen Raumes zu verlassen.

Der Kurs vermittelt technische Grundlagen zur computergestützten Fertigung physikalischer Objekte. Untersucht werden neue Ansätze zur Individualisierung von Form und Funktionalität durch parametrisierte Gestaltungsprozesse und modularisierte Einzelkomponenten.


Inhaltsverzeichnis

[bearbeiten] Teilnehmer

Benjamin Frenzel
Benjamin Maus
Frederic Gmeiner
Moritz Greiner-Petter
Hanna Wiesener
Fabian Brunsing
Torsten Posselt
Clemens Jahn
Tim Horntrich
Dominik Wagner
Florian Kühnle
Georg Werner
Holger Frey
Constantin Engelmann
Clemens Winkler
Martin Luge
Sebastian Schmieg
Akitoshi Honda
Stefan Stubbe
Vera Albers
Michael Wamposzyc
Josephin Ritschel
Anne-Jan Reijn
Julius von Bismarck
Frédéric Eyl
Korbinian Polk
Daniel Schulze
Marek Straszak

[bearbeiten] Inhalt

[bearbeiten] Times:

Wednesday: 12:00 to 15:00

Da meine Freundin und ich Nachwuchs erwarten bin ich für den Rest des Semesters nur noch Mittwochs im Kurs. Sobald es wirklich losgeht kann es kurzfristig zu Änderungen kommen, ich werde euch dann per Rundmail informieren. Bis dahin stehen neben der Fertigstellung eurer Projekte noch folgende Themen auf dem Programm:

Mittwoch 26.06. Verwendung von Transformationmatrizen platzsparendes Platzieren von Objekten mit Binacking berechnen der ungefähren Cut dauer

Mittwoch 03.07. Einführung Lasercutter, Cutten des exportierten Kontouren

[bearbeiten] Exercises

The solution to every exercise has to be uploaded to the course site. For the upload you have to loggin. The default loggin follows this scheme

  • name: Christian Riekoff
  • loggin: christianR
  • password: christianR

To upload your sketch go to upload sketch in the admin menue, click on add new work and select the exercise and your files.

[bearbeiten] Links

Please add links relevant to the theme

digital fabrication at flickr

[bearbeiten] day 01 23.04.08

Übung 01 Pyramide

import processing.opengl.*;

void setup(){
  size(400,400,OPENGL);
}

float angle = 0;

void draw(){
  background(200);
  angle += 0.01;
  translate(width/2,height/2);
  rotateX(angle);
  pyramide(200);
}

void pyramide(float scale){
  float x1 =  0,           y1 =  0.5 * scale, z1 =  0;
  float x2 =  0,           y2 = -0.5 * scale, z2 =  0.5 * scale;
  float x3 =  0.5 * scale, y3 = -0.5 * scale, z3 = -0.5 * scale;
  float x4 = -0.5 * scale, y4 = -0.5 * scale, z4 = -0.5 * scale;
 
  beginShape(TRIANGLES);
  vertex(x2,y2,z2);
  vertex(x3,y3,z3);
  vertex(x4,y4,z4);
  
  vertex(x3,y3,z3);
  vertex(x1,y1,z1);
  vertex(x2,y2,z2);
  
  vertex(x2,y2,z2);
  vertex(x1,y1,z1);
  vertex(x4,y4,z4);
  
  vertex(x1,y1,z1);
  vertex(x3,y3,z3);
  vertex(x4,y4,z4);
  endShape();
}

Einbinden von Bibliotheken für einen besseren Workflow

arcball Die Arcball Bibliothek ermöglicht ein Einfaches Navigieren von 3D Elementen.

import com.processinghacks.arcball.*;
import processing.opengl.*;

void setup() {
  size(600,400,OPENGL);
  ArcBall arcball = new ArcBall(this);
}

void draw() {
  lights();
  background(255);

  translate(width/2,height/2,-height/2);
  box(100); 

}

controlP5 Mit Hilfe von controlP5 können sehr einfach Benutzeroberflächen gestaltet werden mit denen sich Programmparameter ändern lassen.

import controlP5.*;
import com.processinghacks.arcball.*;
import processing.opengl.*;

ControlP5 controlP5;
ControlWindow controlWindow;

float xTranslation = 40;
float xRotation = 0.3;
float yRotation = 0.6;
float scal = 1.2;

void setup() {
  size(600,400,OPENGL);
  ArcBall arcball = new ArcBall(this);

  controlP5 = new ControlP5(this);
  controlP5.hide();
  
  controlWindow = controlP5.addControlWindow("controlP5window",100,100,400,200);
  controlWindow.setBackground(color(40));
  
  Controller mySlider = controlP5.addSlider("xTranslation",0,100,xTranslation,40,40,100,10);
  mySlider.setWindow(controlWindow);
  
  controlP5.addSlider("xRotation",0,PI,xRotation,40,70,100,10).setWindow(controlWindow);
  controlP5.addSlider("yRotation",0,PI,yRotation,40,100,100,10).setWindow(controlWindow);
  controlP5.addSlider("scal",0.5,2,scal,40,130,100,10).setWindow(controlWindow);
}

void draw() {
  lights();
  background(255);

  translate(width/2,height/2,-height/2);
  translate(-200,0);

  for(int i = 0; i < 10; i++){
    translate(xTranslation,0);
    rotateX(xRotation);
    pushMatrix();
    rotateY(yRotation);
    scale(pow(scal,i+1));
    box(30); 
    popMatrix();
  }

}

[bearbeiten] Exercise 1

Write a small program that creates an object consisting of a number of primitives. Use a for loop and the translate, scale and rotate methods of processing to change the position, scale and rotation of each object. Make at least 3 parameters of your program editable using the controlP5 library. Also integrate at least one of the math functions of processing like sin, random and noise.

import controlP5.*;
import com.processinghacks.arcball.*;
import processing.opengl.*;

//Objects to open the window with the sliders
ControlP5 controlP5;
ControlWindow controlWindow;

// declare parameters to control the sketch
float translateX = 40;
float rotateX = QUARTER_PI;
float scale = 1.1;
int numberOfBoxes = 10;

void setup(){
  size(400,400,OPENGL);
  
  //initialize controlP5 and window
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);
  
  //create slider to control translation
  Controller mySlider = controlP5.addSlider("translateX",0,100,translateX,40,40,100,10);
  mySlider.setWindow(controlWindow);
  
  // create slider to control rotation
  Controller mySlider2 = controlP5.addSlider("rotateX",0,PI,rotateX,40,70,100,10);
  mySlider2.setWindow(controlWindow);
  
  // create slider to change number of boxes
  Controller mySlider3 = controlP5.addSlider("numberOfBoxes",0,30,numberOfBoxes,40,100,100,10);
  mySlider3.setWindow(controlWindow);
  
  //create slider to modify scale
  Controller mySlider4 = controlP5.addSlider("scale",0.7,1.3,scale,40,130,100,10);
  mySlider4.setWindow(controlWindow);
  new ArcBall(this);
}

void draw(){
  lights();
  background(200);
  
  translate(width/2, height/2, -height/2);
  translate(-250,0);
  for(int i = 0; i < numberOfBoxes;i++){
    box(20);
    translate(translateX,sin(i * 0.1)*translateX);
    rotateX(rotateX);
    scale(scale);
  }
}

[bearbeiten] Exercise 2

Same as Exercise 1, but now use two nested for loops and pushMatrix and popMatrix to create an Object.

import controlP5.*;
import com.processinghacks.arcball.*;
import processing.opengl.*;

ControlP5 controlP5;
ControlWindow controlWindow;

float translateX = 40;
float rotateX = QUARTER_PI;
float scale = 1.1;
int numberOfBoxes = 10;

void setup(){
  size(400,400,OPENGL);
  
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);
  
  Controller mySlider = controlP5.addSlider("translateX",0,100,translateX,40,40,100,10);
  mySlider.setWindow(controlWindow);
  
  Controller mySlider2 = controlP5.addSlider("rotateX",0,PI,rotateX,40,70,100,10);
  mySlider2.setWindow(controlWindow);
  
  Controller mySlider3 = controlP5.addSlider("numberOfBoxes",0,30,numberOfBoxes,40,100,100,10);
  mySlider3.setWindow(controlWindow);
  
  Controller mySlider4 = controlP5.addSlider("scale",0.7,1.3,scale,40,130,100,10);
  mySlider4.setWindow(controlWindow);
  new ArcBall(this);
}

void draw(){
  lights();
  background(200);
  
  translate(width/2, height/2, -height/2);
  
  //calculate the size of the grid according to 
  //thenumber of boxes and the translation value
  float gridsize = numberOfBoxes*translateX;
  
  //use this value to center the grid
  translate(
    -gridsize/2,
    -gridsize/2
  );
  
  for(int x = 0; x < numberOfBoxes;x++){
    for(int y = 0; y < numberOfBoxes;y++){
      pushMatrix();
      //translate to gridposition
      translate(translateX*x,translateX*y,0);
      
      //rotate according to to x and y 
      //values are devided by numberofboxes so that the
      //angles do not get to big 
      rotateX(x/(float)numberOfBoxes*rotateX);
      rotateY(y/(float)numberOfBoxes*rotateX);
      //scale according to the sin of the x and y
      //this way we create a wave pattern
      scale(
        scale*sin(x/(float)numberOfBoxes*TWO_PI)+
        scale*sin(y/(float)numberOfBoxes*TWO_PI)+
        0.9
      );
      box(20);
      popMatrix();
    }
  }
}

[bearbeiten] Day 02 25.04.08

[bearbeiten] Default Sketch for 3D Navigation

At the start a small default sketch, that initializes arcball and controlP5 and simplifies adding sliders using an extra function. You can save it in your sketch folder and open everytime you create a new sketch.

import controlP5.*;
import com.processinghacks.arcball.*;
import processing.opengl.*;

ControlP5 controlP5;
ControlWindow controlWindow;

int sliderY = 40;

/**
 * simplifies adding sliders
 **/
void addSlider(String parameter, float start, float end, float init){
   Controller mySlider = controlP5.addSlider(parameter,start,end,init,10,sliderY,100,10);
  mySlider.setWindow(controlWindow);
  
  sliderY += 30;
}

void setup(){
  size(400,400,OPENGL);
  
  /* initialize control */
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);
  
  /* add sliders */
  addSlider("slider1",0,100,20);
  addSlider("slider2",0,PI,0);
  addSlider("slider3",0,30,0);
  addSlider("slider4",0.7,1.3,1);
  
  /* init arcball */
  new ArcBall(this);
}

void draw(){
  lights();
  background(200);
  
  translate(width/2, height/2, -height/2);
  
  // draw your object
}

[bearbeiten] Using the circle function

Code for drawing a circle

void setup(){
  size(400,400);
  strokeWeight(10);
}

float radius = 100;
float resolution = 20;

void draw(){
  background(200);
  
  beginShape();
  
  for(int i = 0; i < resolution;i++){
    float angle = i/resolution * TWO_PI;
    float x = 200 + radius * cos(angle); 
    float y = 200 + radius * sin(angle); 
    vertex(x,y);
    println(i+" : "+angle+" : "+" : "+x+" : "+y);
  }
  endShape(CLOSE);
}

code for drawing 3d ring

import controlP5.*;
import com.processinghacks.arcball.*;
import processing.opengl.*;

ControlP5 controlP5;
ControlWindow controlWindow;

int sliderY = 10;

/**
 * simplifies adding sliders
 **/
void addSlider(String parameter, float start, float end, float init){
   Controller mySlider = controlP5.addSlider(parameter,start,end,init,10,sliderY,100,10);
  mySlider.setWindow(controlWindow);
  
  sliderY += 30;
}

float noiseFreq = 30;
float noiseAmp = 50;
float offset = 1;

float sinFreq = 5;
float sinAmp = 50;

float gridSize = 50;

void setup(){
  size(400,400,OPENGL);
  
  /* initialize control */
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);
  
  /* add sliders */
  addSlider("resolution",5,50,resolution);
  addSlider("radius",0,200,radius);
  addSlider("ringWidth",10,50,ringWidth);

  new ArcBall(this);
  
  //noStroke();
}

float equation(float x, float y){
  float normX = x / 400;
  float normY = y / 400;
  return 
    sin(normX * TWO_PI * sinFreq) * sinAmp +
    sin(normY * TWO_PI * sinFreq) * sinAmp +
    noise(normX * noiseFreq + offset,normY * noiseFreq) * noiseAmp;
}
int resolution = 20;
float radius = 100;
float ringWidth = 20;

void draw(){
 // lights();
  background(200);

  translate(width/2, height/2, -height/2);

  beginShape(TRIANGLE_STRIP);
  
  for(int i = 0; i <= resolution; i++){
    float angle = TWO_PI/resolution * i;
    
    float x = sin(angle) * radius;
    float y = cos(angle) * radius;
    
    vertex(x,y,-ringWidth/2);
    vertex(x,y,ringWidth/2);
  }
  endShape();
}

[bearbeiten] Mesh

code for drawing a mesh

import controlP5.*;
import com.processinghacks.arcball.*;
import processing.opengl.*;

ControlP5 controlP5;
ControlWindow controlWindow;

int sliderY = 40;

/**
 * simplifies adding sliders
 **/
void addSlider(String parameter, float start, float end, float init){
  Controller mySlider = controlP5.addSlider(parameter,start,end,init,10,sliderY,100,10);
  mySlider.setWindow(controlWindow);

  sliderY += 30;
}

void setup(){
  size(400,400,P3D);

  /* initialize control */
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);

  /* add sliders */
  addSlider("slider1",0,100,20);
  addSlider("slider2",0,PI,0);
  addSlider("slider3",0,30,0);
  addSlider("slider4",0.7,1.3,1);

  /* init arcball */
  new ArcBall(this);
}

float gridSize = 50;

void draw(){
  lights();
  background(200);

  translate(width/2, height/2, -height/2);

  for(int x = -100; x < 100; x += gridSize){
    beginShape(TRIANGLE_STRIP);
    for(int y = -100; y < 100; y += gridSize){
      vertex(x,y,0);
      vertex(x + gridSize,y,0);
    }
    endShape();
  }
  // draw your object
}

[bearbeiten] Working with Signals

code for drawing a sinus signal

import controlP5.*;
import processing.opengl.*;

ControlP5 controlP5;
ControlWindow controlWindow;

int sliderY = 40;

/**
 * simplifies adding sliders
 **/
void addSlider(String parameter, float start, float end, float init){
   Controller mySlider = controlP5.addSlider(parameter,start,end,init,10,sliderY,100,10);
  mySlider.setWindow(controlWindow);
  
  sliderY += 30;
}

float sinAmp = 50;

void setup(){
  size(400,400,P3D);
  
  /* initialize control */
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);
  
  /* add sliders */
  addSlider("sinAmp",0,100,sinAmp);
  addSlider("slider2",0,PI,0);
  addSlider("slider3",0,30,0);
  addSlider("slider4",0.7,1.3,1);
  
  noFill();
}

void draw(){
  lights();
  background(200);
  
  translate(0,height/2);
  
  beginShape(POINTS);
  for(float x = 0; x < width; x +=3){
    float y = sin(map(x,0,width,0,TWO_PI))*sinAmp;
    vertex(x,y);
  }
  endShape();
  // draw your object
}

combining signals

import controlP5.*;
import processing.opengl.*;

ControlP5 controlP5;
ControlWindow controlWindow;

int sliderY = 40;

/**
 * simplifies adding sliders
 **/
void addSlider(String parameter, float start, float end, float init){
   Controller mySlider = controlP5.addSlider(parameter,start,end,init,10,sliderY,100,10);
  mySlider.setWindow(controlWindow);
  
  sliderY += 30;
}

float sinAmp = 50;
float sinFreq = 3;

float noiseAmp = 50;
float noiseFreq = 10;
float noiseOffset = 1;

void setup(){
  size(400,400,OPENGL);
  
  /* initialize control */
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,400);
  
  /* add sliders */
  addSlider("sinAmp",0,100,sinAmp);
  addSlider("sinFreq",0,5,sinFreq);
  addSlider("noiseAmp",0,100,noiseAmp);
  addSlider("noiseFreq",0,10,noiseFreq);
  addSlider("noiseOffset",0,2,noiseOffset);
  
  noFill();
}

void draw(){
  lights();
  background(200);
  
  translate(0,height/2);
  
  beginShape();
  for(float x = 0; x < width; x +=3){
    float sinValue = sin(map(x,0,width,0,TWO_PI) * sinFreq)*sinAmp;
    float noiseValue = noise(map(x,0,width,0,1) * noiseFreq + noiseOffset);
    noiseValue = map(noiseValue,0,1,-1,1) * noiseAmp;
    
    float y = sinValue + noiseValue;
    vertex(x,y);
  }
  endShape();
  // draw your object
}


signal combined with mesh

import controlP5.*;
import com.processinghacks.arcball.*;
import processing.opengl.*;

ControlP5 controlP5;
ControlWindow controlWindow;

int sliderY = 40;

/**
 * simplifies adding sliders
 **/
void addSlider(String parameter, float start, float end, float init){
  Controller mySlider = controlP5.addSlider(parameter,start,end,init,10,sliderY,100,10);
  mySlider.setWindow(controlWindow);

  sliderY += 30;
}

float sinAmp = 50;
float sinFreq = 3;

float noiseAmp = 50;
float noiseFreq = 10;
float noiseOffset = 1;

void setup(){
  size(400,400,P3D);

  /* initialize control */
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);

  /* add sliders */
  addSlider("sinAmp",0,100,sinAmp);
  addSlider("sinFreq",0,5,sinFreq);
  addSlider("noiseAmp",0,100,noiseAmp);
  addSlider("noiseFreq",0,10,noiseFreq);
  addSlider("noiseOffset",0,2,noiseOffset);

  /* init arcball */
  new ArcBall(this);
  
  noStroke();
}

float gridSize = 5;

float equation(float x, float y){
  float sinValueX = sin(map(x,0,width,0,TWO_PI) * sinFreq)*sinAmp;
  float sinValueY = sin(map(y,0,width,0,TWO_PI) * sinFreq)*sinAmp;
  
  float noiseX = map(x,0,width,0,1) * noiseFreq;
  float noiseY = map(y,0,height,0,1) * noiseFreq;
  float noiseValue = noise(noiseX + noiseOffset,noiseY);
    noiseValue = map(noiseValue,0,1,-1,1) * noiseAmp;
  return sinValueX + sinValueY + noiseValue;
}

void draw(){
  lights();
  background(200);

  translate(width/2, height/2, -height/2);

  for(int x = -100; x < 100; x += gridSize){
    beginShape(TRIANGLE_STRIP);
    for(int y = -100; y < 100; y += gridSize){
      float z = equation(x,y);
      vertex(x,y,z);
      z = equation(x + gridSize,y);
      vertex(x + gridSize,y,z);
    }
    endShape();
  }
  // draw your object
}

[bearbeiten] Exercise 03

Write a function that creates a unique 3d object. The function should work similar to the box function of processing, so you have to ensure that the object is centered in the origin of the coordinate system and and has a size of 1 so that it can easily be scaled with a parameter that is passed to the function. Copy exercise 01 or 02 and paste the function for your primitive now change the calls to box with your primitive function.

import controlP5.*;
import com.processinghacks.arcball.*;
import processing.opengl.*;

ControlP5 controlP5;
ControlWindow controlWindow;

float translateX = 40;
float rotateX = QUARTER_PI;
float scale = 1.1;
int numberOfBoxes = 10;

void setup(){
  size(400,400,P3D);
  
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);
  
  Controller mySlider = controlP5.addSlider("translateX",0,100,translateX,40,40,100,10);
  mySlider.setWindow(controlWindow);
  
  Controller mySlider2 = controlP5.addSlider("rotateX",0,PI,rotateX,40,70,100,10);
  mySlider2.setWindow(controlWindow);
  
  Controller mySlider3 = controlP5.addSlider("numberOfBoxes",0,30,numberOfBoxes,40,100,100,10);
  mySlider3.setWindow(controlWindow);
  
  Controller mySlider4 = controlP5.addSlider("scale",0.7,1.3,scale,40,130,100,10);
  mySlider4.setWindow(controlWindow);
  new ArcBall(this);
}

void draw(){
  lights();
  background(200);
  
  translate(width/2, height/2, -height/2);
  
  //calculate the size of the grid according to 
  //thenumber of boxes and the translation value
  float gridsize = numberOfBoxes*translateX;
  
  //use this value to center the grid
  translate(
    -gridsize/2,
    -gridsize/2
  );
  
  for(int x = 0; x < numberOfBoxes;x++){
    for(int y = 0; y < numberOfBoxes;y++){
      pushMatrix();
      //translate to gridposition
      translate(translateX*x,translateX*y,0);
      
      //rotate according to to x and y 
      //values are devided by numberofboxes so that the
      //angles do not get to big 
      rotateX(x/(float)numberOfBoxes*rotateX);
      rotateY(y/(float)numberOfBoxes*rotateX);
      //scale according to the sin of the x and y
      //this way we create a wave pattern
      scale(
        scale*map(sin(x/(float)numberOfBoxes*TWO_PI),-1,1,0.5,2)+
        scale*map(sin(y/(float)numberOfBoxes*TWO_PI),-1,1,0.5,2)
      );
      pyramide(20);
      popMatrix();
    }
  }
}

/**
 * Function to draw a pyramide
 **/
void pyramide(float scale){
  float x1 =  0,           y1 =  0.5 * scale, z1 =  0;
  float x2 =  0,           y2 = -0.5 * scale, z2 =  0.5 * scale;
  float x3 =  0.5 * scale, y3 = -0.5 * scale, z3 = -0.5 * scale;
  float x4 = -0.5 * scale, y4 = -0.5 * scale, z4 = -0.5 * scale;
 
  beginShape(TRIANGLES);
  vertex(x2,y2,z2);
  vertex(x3,y3,z3);
  vertex(x4,y4,z4);
  
  vertex(x3,y3,z3);
  vertex(x1,y1,z1);
  vertex(x2,y2,z2);
  
  vertex(x2,y2,z2);
  vertex(x1,y1,z1);
  vertex(x4,y4,z4);
  
  vertex(x1,y1,z1);
  vertex(x3,y3,z3);
  vertex(x4,y4,z4);
  endShape();
}

[bearbeiten] Day 03 30.04.08

Using a recursive function to draw a tree.

void setup(){
  size(400,400);
  noLoop();
  
  PFont font = loadFont("arial.vlw");
  textFont(font,12);
}

void draw(){
  tree(width/2,height,6);
}

void tree(float x, float y, int depth){
  float nextY = y - random(height/8,height/4);
  strokeWeight(depth * 2);
  line(x,y,x,nextY);
  branches(x,nextY,depth);
}

void branches(float x, float y, int depth){
  int numberOfBranches = (int)random(2,3);
  for(int i = 0; i < numberOfBranches; i++){
    float nextX = x + random(-40,40);
    float nextY = y - random(40);
    
    strokeWeight(depth * 2);
    line(x,y,nextX,nextY);
    text(depth,x,y);
    if(depth > 0){
      branches(nextX,nextY,depth - 1);
    }
  }
}

[bearbeiten] Day 04 07.05.08

Using classes to create 3d Objects.

import com.processinghacks.arcball.*;
import processing.opengl.*;


Cube cube = new Cube();

void setup(){
  frameRate(20);
  size(400,400,OPENGL);
  new ArcBall(this);
}

void draw(){
  background(200);
  translate(width/2, height/2, -height/2);
  scale(100);
  cube.draw();
}

Point class

class Point{
  float x;
  float y;
  float z;
  
  Point(float _x, float _y, float _z){
    x = _x;
    y = _y;
    z = _z;
  }
  
  Point(){
    this(0,0,0);
  }
  
  void add(float _x,float _y, float _z){
    x = x + _x;
    y = y + _y;
    z = z + _z;
  }
  
  void draw(){
    point(x,y,z);
  }
}

Triangle class

class Triangle{
  Point p1;
  Point p2;
  Point p3;
  
  Triangle(Point _p1, Point _p2, Point _p3){
    p1 = _p1;
    p2 = _p2;
    p3 = _p3;
  }
  
  void draw(){
    beginShape(TRIANGLES);
    vertex(p1.x,p1.y,p1.z);
    vertex(p2.x,p2.y,p2.z);
    vertex(p3.x,p3.y,p3.z);
    endShape();
  }
}

Surface class

class Surface{
  Point[] points;
  Triangle[] triangles;
  
  Surface(){
    points = new Point[20];
    triangles = new Triangle[20];
  }
  
  void draw(){
    for(int i = 0; i < triangles.length;i++){
      triangles[i].draw();
    }
  }
  
  
}

Cube class

class Cube extends Surface{
  Cube(){
    points = new Point[]{
      new Point( 0.5,  0.5,  0.5),
      new Point( 0.5,  0.5, -0.5),
      new Point( 0.5, -0.5,  0.5),
      new Point( 0.5, -0.5, -0.5),
      new Point(-0.5,  0.5,  0.5),
      new Point(-0.5,  0.5, -0.5),
      new Point(-0.5, -0.5,  0.5),
      new Point(-0.5, -0.5, -0.5)
    };
    triangles = new Triangle[]{
      new Triangle(points[0], points[1], points[4])
    };
  }
}

[bearbeiten] Day 06 14.05.2008

Create a surface based on beziercurves

import controlP5.*;
import com.processinghacks.arcball.*;
import processing.opengl.*;

ControlP5 controlP5;
ControlWindow controlWindow;

int sliderY = 40;

/**
 * simplifies adding sliders
 **/
void addSlider(String parameter, float start, float end, float init){
  Controller mySlider = controlP5.addSlider(parameter,start,end,init,10,sliderY,100,10);
  mySlider.setWindow(controlWindow);
  sliderY += 30;
}



void setup(){
  size(400,400,OPENGL);
  //noFill();

  /* initialize control */
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,600);

  /* add sliders */
  addSlider("z1",-1,1,20);
  addSlider("z2",-1,1,20);
  addSlider("cx1",-1,1,20);
  addSlider("cy1",-1,1,20);
  addSlider("cz1",-1,1,20);
  addSlider("cx2",-1,1,20);
  addSlider("cy2",-1,1,20);
  addSlider("cz2",-1,1,20);
  addSlider("cx3",-1,1,20);
  addSlider("cy3",-1,1,20);
  addSlider("cz3",-1,1,20);
  addSlider("cx4",-1,1,20);
  addSlider("cy4",-1,1,20);
  addSlider("cz4",-1,1,20);

  /* init arcball */
  new ArcBall(this);
}



float x1=0;
float y1=1;
float z1=0;
float cx1=-1;
float cy1=0;
float cz1=0;

float x2=0;
float y2=-1;
float z2=0;
float cx2=-1;
float cy2=0;
float cz2=0;

float cx3=1;
float cy3=0;
float cz3=0;

float cx4=1;
float cy4=0;
float cz4=0;

int steps = 100;

void draw(){
  noStroke();
lights();
  background(150);

  pushMatrix();
  translate(width/2,height/2);
  scale(200);
  bezier(x1,y1,z1,cx1,cy1,cz1,cx2,cy2,cz2,x2,y2,z2);
  bezier(x1,y1,z1,cx3,cy3,cz3,cx4,cy4,cz4,x2,y2,z2);

  float stepSize = 1.0/steps;

  for(int i = 0; i < steps;i++){
    float px1 = bezierPoint(x1, cx1, cx2, x2, stepSize * i);
    float py1 = bezierPoint(y1, cy1, cy2, y2, stepSize * i);
    float pz1 = bezierPoint(z1, cz1, cz2, z2, stepSize * i);

    float px2 = bezierPoint(x1, cx3, cx4, x2, stepSize * i);
    float py2 = bezierPoint(y1, cy3, cy4, y2, stepSize * i);
    float pz2 = bezierPoint(z1, cz3, cz4, z2, stepSize * i);

    float px3 = bezierPoint(x1, cx1, cx2, x2, stepSize * (i+1));
    float py3 = bezierPoint(y1, cy1, cy2, y2, stepSize * (i+1));
    float pz3 = bezierPoint(z1, cz1, cz2, z2, stepSize * (i+1));

    float px4 = bezierPoint(x1, cx3, cx4, x2, stepSize * (i+1));
    float py4 = bezierPoint(y1, cy3, cy4, y2, stepSize * (i+1));
    float pz4 = bezierPoint(z1, cz3, cz4, z2, stepSize * (i+1));


    bezier(px1,py1,pz1,px1,py1,pz1 + 1 ,px2,py2,pz2 + 1,px2,py2,pz2);

    beginShape(TRIANGLE_STRIP);
    for(int j = 0; j <= steps;j++){
      float qx1 = bezierPoint(px1,px1,px2,px2, stepSize * j);
      float qy1 = bezierPoint(py1,py1,py2,py2, stepSize * j);
      float qz1 = bezierPoint(pz1,pz1 + 1,pz2 + 1,pz2, stepSize * j);
      
      float qx2 = bezierPoint(px3,px3,px4,px4, stepSize * j);
      float qy2 = bezierPoint(py3,py3,py4,py4, stepSize * j);
      float qz2 = bezierPoint(pz3,pz3 + 1,pz4 + 1,pz4, stepSize * j);

      vertex(qx1,qy1,qz1);
      vertex(qx2,qy2,qz2);
    }
    endShape();
  }
  popMatrix();
}

[bearbeiten] Day 10 30.05.2008

import controlP5.*;

import org.texone.geometry.test.*;
import org.texone.geometry.formular.*;
import org.texone.geometry.*;
import org.texone.geometry.bool.*;
import org.texone.geometry.primitive.*;
import org.texone.geometry.formular.calculation.*;

ArcBall myArcBall;
Box box;

ControlP5 controlP5;
ControlWindow controlWindow;

int sliderY = 40;

/**
 * simplifies adding sliders
 **/
void addSlider(String parameter, float start, float end, float init){
   Controller mySlider = controlP5.addSlider(parameter,start,end,init,10,sliderY,100,10);
  mySlider.setWindow(controlWindow);
  
  sliderY += 30;
}

void setup(){
  size(400,400,OPENGL);
  
  /* initialize control */
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);
  
  /* add sliders */
  addSlider("sinAmp",0,100,0);
  addSlider("slider2",0,PI,0);
  addSlider("slider3",0,30,0);
  addSlider("slider4",0.7,1.3,1);
  
  myArcBall = new ArcBall(this);
  box = new Box(100,100,100);
}

void draw(){
  background(200);
  myArcBall.begin();
  box.draw(this);
  myArcBall.end();
}

Create a rotational solid and export slices to pdf

import processing.pdf.*;

import processing.opengl.*;

import controlP5.*;

import org.texone.geometry.test.*;
import org.texone.geometry.formular.*;
import org.texone.geometry.*;
import org.texone.geometry.bool.*;
import org.texone.geometry.primitive.*;
import org.texone.geometry.formular.calculation.*;

ArcBall myArcBall;
Box box;

ControlP5 controlP5;
ControlWindow controlWindow;

int sliderY = 40;

PGraphicsPDF pdf;

/**
 * simplifies adding sliders
 **/
void addSlider(String parameter, float start, float end, float init){
  Controller mySlider = controlP5.addSlider(parameter,start,end,init,10,sliderY,100,10);
  mySlider.setWindow(controlWindow);

  sliderY += 30;
}

float radius = 100;
float cylHeight = 200;
int resolution = 20;
int printResolution = 200;
float noiseFreq = 0.1;
float noiseAdd = 0;

void setup(){
  size(400,400,OPENGL);

  pdf = (PGraphicsPDF)createGraphics(width, height, PDF, "pause-resume.pdf");

  /* initialize control */
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);

  /* add sliders */
  addSlider("radius",50,200,radius);
  addSlider("cylHeight",0,500,cylHeight);
  addSlider("resolution",0,100,resolution);
  addSlider("printResolution",0,1000,printResolution);
  addSlider("noiseFreq",0.01,0.2,noiseFreq);
  addSlider("noiseAdd",0,100,noiseAdd);

  myArcBall = new ArcBall(this);
  box = new Box(100,100,100);
  noFill();
}

void draw(){
  background(200);
  myArcBall.begin();

  float angle = TWO_PI/resolution;
  float yAdd = cylHeight/resolution;

  for(float y = -cylHeight/2; y <= cylHeight/2;y +=yAdd ){
    beginShape();

    float noiseVal = noise((y+cylHeight/2+noiseAdd)*noiseFreq);
    for(int i = 0; i <= resolution;i++){


      float x = cos(angle * i)*radius;
      float z = sin(angle * i)*radius;

      vertex(x * noiseVal,y,z * noiseVal);
    }
    endShape();
  }
  myArcBall.end();
}

void keyPressed(){
  if(key == 's'){
    beginRecord(pdf);

    float angle = TWO_PI/printResolution;
    float yAdd = (cylHeight/printResolution) * 20;

    for(float y = -cylHeight/2; y <= cylHeight/2;y +=yAdd ){
      pushMatrix();
      translate(width/2,height/2);
      float noiseVal = noise((y+cylHeight/2+noiseAdd)*noiseFreq);
      beginShape();
      for(int i = 0; i <= printResolution;i++){

        float x = cos(angle * i)*radius;
        float z = sin(angle * i)*radius;


        if(i % 20 == 0){
          // senkrechter Vector zu x,z
          float perpX = -z;
          float perpY = x;
          float perpLength = dist(0,0,perpX,perpY);
          perpX /= perpLength;
          perpY /= perpLength;
          vertex(x * noiseVal - perpX,z * noiseVal-perpY);
          vertex(x * noiseVal * 0.75 - perpX,z * noiseVal * 0.75-perpY);
          vertex(x * noiseVal * 0.75 + perpX,z * noiseVal * 0.75+perpY);
          vertex(x * noiseVal + perpX,z * noiseVal + perpY);
        }
        else{
          vertex(x * noiseVal,z * noiseVal);
        }
      }
      endShape();
      beginShape();
      for(int i = 0; i <= printResolution;i++){
        float x = cos(angle * i)*radius * 0.5;
        float z = sin(angle * i)*radius * 0.5;
        vertex(x * noiseVal,z * noiseVal);
      }
      endShape();
      popMatrix();
      pdf.nextPage();
    }

yAdd = (cylHeight/printResolution) ;
    pushMatrix();
    translate(width/2,height/2);
    beginShape();
    for(float y = -cylHeight/2; y <= cylHeight/2;y +=yAdd ){
      float noiseVal = noise((y+cylHeight/2+noiseAdd)*noiseFreq);
      float x = radius * noiseVal;
      vertex(x,y);
    }
    int counter = 0;
    for(float y = cylHeight/2; y >= -cylHeight/2;y -=yAdd ){
      
      float noiseVal = noise((y+cylHeight/2+noiseAdd)*noiseFreq);
      float x = radius * noiseVal * 0.5;
      if(counter % 20 == 0){
        vertex(x,y + 1);
        vertex(radius * noiseVal * 0.75,y + 1);
        vertex(radius * noiseVal * 0.75,y - 1);
        vertex(x,y - 1);
      }else{
        vertex(x,y);
      }
      counter++;
    }
    endShape(CLOSE);
    popMatrix();
    endRecord();
  }
}

[bearbeiten] Day 11 04.06.2008

Exporting objects in slices to cut out using a laser cutter

import processing.pdf.*;

import processing.opengl.*;

import controlP5.*;

import org.texone.geometry.test.*;
import org.texone.geometry.formular.*;
import org.texone.geometry.*;
import org.texone.geometry.bool.*;
import org.texone.geometry.primitive.*;
import org.texone.geometry.formular.calculation.*;

ArcBall myArcBall;
Box box;

ControlP5 controlP5;
ControlWindow controlWindow;

int sliderY = 40;



float mmToPixels = 595.0 / 210.0;

int mmToPixels(float theMillimeters){
  return int(theMillimeters * mmToPixels);
}

/**
 * simplifies adding sliders
 **/
void addSlider(String parameter, float start, float end, float init){
  Controller mySlider = controlP5.addSlider(parameter,start,end,init,10,sliderY,100,10);
  mySlider.setWindow(controlWindow);

  sliderY += 30;
}

float radius = 100;
float cylHeight = 200;
int resolution = 20;
int printResolution = 200;
float noiseFreq = 0.1;
float noiseAdd = 0;

void setup(){
  size(mmToPixels(210),mmToPixels(297),OPENGL);

  /* initialize control */
  controlP5 = new ControlP5(this);
  controlP5.hide();
  controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200);

  /* add sliders */
  addSlider("radius",50,200,radius);
  addSlider("cylHeight",0,500,cylHeight);
  addSlider("resolution",0,100,resolution);
  addSlider("printResolution",0,1000,printResolution);
  addSlider("noiseFreq",0.01,0.2,noiseFreq);
  addSlider("noiseAdd",0,100,noiseAdd);

  myArcBall = new ArcBall(this);
  box = new Box(100,100,100);
  noFill();
}

void draw(){
  background(200);
  myArcBall.begin();

  float angle = TWO_PI/resolution;
  float yAdd = cylHeight/resolution;

  for(float y = -cylHeight/2; y <= cylHeight/2;y +=yAdd ){
    beginShape();

    float noiseVal = noise((y+cylHeight/2+noiseAdd)*noiseFreq);
    for(int i = 0; i <= resolution;i++){


      float x = cos(angle * i)*radius;
      float z = sin(angle * i)*radius;

      vertex(x * noiseVal,y,z * noiseVal);
    }
    endShape();
  }
  myArcBall.end();
}

void keyPressed(){
  if(key == 's'){
    Exporter exporter = new Exporter("test.pdf");
    
    float angle = TWO_PI/printResolution;
    float yAdd = (cylHeight/printResolution) * 10;

    for(float y = -cylHeight/2; y <= cylHeight/2;y +=yAdd ){
      Contour ring = new Contour();
      float noiseVal = noise((y+cylHeight/2+noiseAdd)*noiseFreq);
      Path outerRing = new Path();
      for(int i = 0; i <= printResolution;i++){

        float x = cos(angle * i)*radius;
        float z = sin(angle * i)*radius;


        if(i % 20 == 0){
          // senkrechter Vector zu x,z
          float perpX = -z;
          float perpY = x;
          float perpLength = dist(0,0,perpX,perpY);
          perpX /= perpLength;
          perpY /= perpLength;
          outerRing.addVertex(x * noiseVal - perpX,z * noiseVal-perpY);
          outerRing.addVertex(x * noiseVal * 0.75 - perpX,z * noiseVal * 0.75-perpY);
          outerRing.addVertex(x * noiseVal * 0.75 + perpX,z * noiseVal * 0.75+perpY);
          outerRing.addVertex(x * noiseVal + perpX,z * noiseVal + perpY);
        }
        else{
          outerRing.addVertex(x * noiseVal,z * noiseVal);
        }
      }
      ring.addPath(outerRing);
      Path innerRing = new Path();
      for(int i = 0; i <= printResolution;i++){
        float x = cos(angle * i)*radius * 0.5;
        float z = sin(angle * i)*radius * 0.5;
        innerRing.addVertex(x * noiseVal,z * noiseVal);
      }
      ring.addPath(innerRing);
      exporter.addContour(ring);
    }

    yAdd = (cylHeight/printResolution) ;
   
   Contour vertical = new Contour();
   Path verticalPath = new Path();
    for(float y = -cylHeight/2; y <= cylHeight/2;y +=yAdd ){
      float noiseVal = noise((y+cylHeight/2+noiseAdd)*noiseFreq);
      float x = radius * noiseVal;
      verticalPath.addVertex(x,y);
    }
    int counter = 0;
    for(float y = cylHeight/2; y >= -cylHeight/2;y -=yAdd ){

      float noiseVal = noise((y+cylHeight/2+noiseAdd)*noiseFreq);
      float x = radius * noiseVal * 0.5;
      if(counter % 20 == 0){
        verticalPath.addVertex(x,y + 1);
        verticalPath.addVertex(radius * noiseVal * 0.75,y + 1);
        verticalPath.addVertex(radius * noiseVal * 0.75,y - 1);
        verticalPath.addVertex(x,y - 1);
      }
      else{
        verticalPath.addVertex(x,y);
      }
      counter++;
    }
    vertical.addPath(verticalPath);
    
    exporter.addContour(vertical);
    exporter.export();
    
  }
}

Code for exporting Contour Tab

class Vertex{
  float x,y;

  Vertex(float _x, float _y){
    x = _x;
    y = _y;
  }

  void draw(){
    vertex(x,y);
  }
}

class Path{
  ArrayList vertices = new ArrayList(); 

  void addVertex(Vertex _vertex){
    vertices.add(_vertex);
  }

  void addVertex(float _x, float _y){
    vertices.add(new Vertex(_x,_y));
  }

  void draw(){
    beginShape();
    for(int i = 0; i < vertices.size();i++){
      Vertex vertex = (Vertex)vertices.get(i);
      vertex.draw();
    }
    endShape();
  }
}

class Contour{
  ArrayList paths = new ArrayList();

  float width = 0;
  float height = 0;

  float minX = Float.MAX_VALUE;
  float minY = Float.MAX_VALUE;
  float maxX = Float.MIN_VALUE;
  float maxY = Float.MIN_VALUE;

  void addPath(Path _path){
    paths.add(_path);

    for(int i = 0; i < _path.vertices.size();i++){
      Vertex vertex = (Vertex)_path.vertices.get(i);
      minX = min(minX,vertex.x);
      minY = min(minY,vertex.y);
      maxX = max(maxX,vertex.x);
      maxY = max(maxY,vertex.y);
    }

    width = maxX - minX;
    height = maxY - minY;
  }

  void normalize(){
    for(int i = 0; i < paths.size();i++){
      Path path = (Path) paths.get(i);

      for(int j = 0; j < path.vertices.size();j++){
        Vertex vertex = (Vertex)path.vertices.get(j);
        vertex.x -= minX;
        vertex.y -= minY;
      }

    }

    maxX -= minX;
    maxY -= minY;
    minX = 0;
    minY = 0;
  }

  void draw(){
    for(int i = 0; i < paths.size();i++){
      Path path = (Path) paths.get(i);
      path.draw();
    }
  }
}

class Exporter{
  ArrayList contours = new ArrayList();

  PGraphicsPDF pdf;

  Exporter(String fileName){
    pdf = (PGraphicsPDF)createGraphics(width, height, PDF, fileName);
  }

  void addContour(Contour _contour){
    contours.add(_contour);
  }

  void export(){
    beginRecord(pdf);
    float x = 0;
    float y = 0;
    float maxHeight = 0;
    for(int i = 0; i < contours.size();i++){
      Contour contour = (Contour)contours.get(i);
      contour.normalize();
      if(x + contour.width > width){
        x = 0;
        y += maxHeight;
        maxHeight = 0;
      }
      if(y + contour.height > height){
        y = 0;
        x = 0;
        pdf.nextPage();
      }

      pushMatrix();
      translate(x,y);
      contour.draw();
      popMatrix();
      x += contour.width;
      maxHeight = max(maxHeight,contour.height);
    }
    endRecord();
  }
}
Persönliche Werkzeuge