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.

Processing 2.x Basics

9. January 2014

http://processing.org Examples for Building Geometries: (Download unlekker and toxiclibs libraries for processing) Manipulating Grids and Patterns: (Source http://www.generative-gestaltung.de/P_2_1_2_01) import processing.pdf.*; import java.util.Calendar; boolean savePDF = false; float tileCount = 20; color circleColor = color(0); int circleAlpha = 180; int actRandomSeed = 0; void setup(){ size(600, 600); } void draw() { if (savePDF) beginRecord(PDF, timestamp()+".pdf"); translate(width/tileCount/2, height/tileCount/2); background(255); smooth(); noFill(); randomSeed(actRandomSeed); stroke(circleColor, circleAlpha); strokeWeight(mouseY/60); for (int gridY=0; gridY<tileCount; gridY++) { for (int gridX=0; gridX<tileCount; gridX++) { float posX = width/tileCount * gridX; float posY = height/tileCount * gridY; float shiftX = random(-mouseX, mouseX)/20; float shiftY = random(-mouseX, mouseX)/20; ellipse(posX+shiftX, posY+shiftY, mouseY/15, mouseY/15); } } if (savePDF) { savePDF = false; endRecord(); } } void mousePressed() { actRandomSeed = (int) random(100000); } void keyReleased(){ if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png"); if (key == 'p' || key == 'P') savePDF = true; } // timestamp String timestamp() { Calendar now = Calendar.getInstance(); return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now); } Exporting Lines via dxf: Screen Shot 2014-01-14 at 12.06.53 //'Collaborative Fabrication' Workshop – Formation Principles 2014 //Clemens Winkler //3d form from time capture //import peasycam and dxf export libraries import peasy.*; import processing.dxf.*; //set variables boolean isRecording = false; int recordFrame = 0; int MAX_FRAMES = 8; float xoff = 0.0; //initialize peasycam PeasyCam cam; void setup(){ size(800, 600, P3D); smooth(); frameRate(10); //peasycam instance cam = new PeasyCam(this, 200); } void draw(){ background(0, 15, 40); lights(); stroke(255, 100); strokeWeight(0.5); if(isRecording){ //start file on first frame of recording if(recordFrame == 0) beginRaw(DXF, "timeCapture.dxf"); //increment recording frame count recordFrame++; } //draw objects //make it move each frame based on recordFrame variable for (int i=0; i<20; i++){ //randomize objects xoff = xoff + .005; float n = noise(xoff) * height; float x = random(xoff*.1) * width/2; float y = random(xoff*.1) * height/4; float z = noise(xoff) * recordFrame * 500; float zz = recordFrame * 1.5 + 50; //create the objects pushMatrix(); translate(0, 0, zz); //rotateX radians(30); rotateY(radians(10)); line(0, n, z-25, x, y, z); line(x, y, z, 600, n+10, z + 25); popMatrix(); } //stop recording & reset clock //if recording and max frame count is reached if(isRecording && recordFrame == MAX_FRAMES){ isRecording = false; recordFrame = 0; //close the file endRaw(); } } //functionality for keyPressed void keyPressed(){ if(key == 'r'){ recordFrame = 0; isRecording = true; } } //////// Loft the different curves for 3D printable Geometries in Rhino   Swarm Behaviour and Cellular Automata: Screen Shot 2014-01-14 at 12.23.51 /* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/93017*@* */ /* !do not delete the line above, required for linking your tweak if you upload again */ ArrayList<MovingNode> nodes; float maxDistance = 65; float dx = 30; float dy = 30; float maxNeighbors = 10; Boolean drawMode = true; void setup() { size(800,600); background(220); nodes = new ArrayList<MovingNode>(); } void draw() { //println(nodes.size()); background(220); if(drawMode) { if(mousePressed){ addNewNode(mouseX,mouseY,random(-dx,dx),random(-dx,dx)); } } else { addNewNode(random(width),random(height),0,0); } for(int i=0; i<nodes.size(); i++) { MovingNode currentNode = nodes.get(i); currentNode.setNumNeighbors( countNumNeighbors(currentNode,maxDistance) ); } for(int i=0; i<nodes.size(); i++) { MovingNode currentNode = nodes.get(i); if(currentNode.x > width || currentNode.x < 0 || currentNode.y > height || currentNode.y < 0) { nodes.remove(currentNode); } } for(int i = 0; i < nodes.size(); i++){ MovingNode currentNode = nodes.get(i); for(int j=0; j<currentNode.neighbors.size(); j++) { MovingNode neighborNode = currentNode.neighbors.get(j); float lineColor = currentNode.calculateLineColor(neighborNode,maxDistance); stroke(lineColor, lineColor, lineColor); line(currentNode.x,currentNode.y,neighborNode.x,neighborNode.y); } currentNode.display(); } } void addNewNode(float xPos, float yPos, float dx, float dy) { //println("add new node"); //generates a random location within a 50x50px box around the mouse //float xPos = mouseX + random(-50,50); //float yPos = mouseY + random(-50,50); //adds a node at this location MovingNode node = new MovingNode(xPos+dx,yPos+dy); node.setNumNeighbors( countNumNeighbors(node,maxDistance) ); //println("newly added node has " + node.numNeighbors + " neighbors"); //println("and neighbors.size() = " + node.neighbors.size()); if(node.numNeighbors < maxNeighbors){ nodes.add(node); /*for(int i=0; i<nodes.size(); i++) { MovingNode currentNode = nodes.get(i); currentNode.setNumNeighbors( countNumNeighbors(currentNode,maxDistance) ); }*/ } } int countNumNeighbors(MovingNode nodeA, float maxNeighborDistance) { int numNeighbors = 0; nodeA.clearNeighbors(); for(int i = 0; i < nodes.size(); i++) { MovingNode nodeB = nodes.get(i); float distance = sqrt((nodeA.x-nodeB.x)*(nodeA.x-nodeB.x) + (nodeA.y-nodeB.y)*(nodeA.y-nodeB.y)); if(distance < maxNeighborDistance) { numNeighbors++; nodeA.addNeighbor(nodeB); } } return numNeighbors; } void keyPressed() { drawMode = !drawMode; nodes = new ArrayList<MovingNode>(); } class MovingNode { float x; float y; int numNeighbors; ArrayList<MovingNode> neighbors; float lineColor; float nodeWidth = 3; float nodeHeight = 3; float fillColor = 50; float lineColorRange = 180; float xVel=0; float yVel=0; float xAccel=0; float yAccel=0; float accelValue = 0.5; MovingNode(float xPos, float yPos) { x = xPos; y = yPos; numNeighbors = 0; neighbors = new ArrayList<MovingNode>(); } void display() { move(); noStroke(); fill(fillColor); ellipse(x,y,nodeWidth,nodeHeight); } void move() { xAccel = random(-accelValue,accelValue); yAccel = random(-accelValue,accelValue); xVel += xAccel; yVel += yAccel; x += xVel; y += yVel; } void addNeighbor(MovingNode node) { neighbors.add(node); } void setNumNeighbors(int num) { numNeighbors = num; } void clearNeighbors() { neighbors = new ArrayList<MovingNode>(); } float calculateLineColor(MovingNode neighborNode, float maxDistance) { float distance = sqrt((x-neighborNode.x)*(x-neighborNode.x) + (y-neighborNode.y)*(y-neighborNode.y)); lineColor = (distance/maxDistance)*lineColorRange; return lineColor; } } class Node { float x; float y; int numNeighbors; ArrayList<Node> neighbors; float lineColor; float nodeWidth = 3; float nodeHeight = 3; float fillColor = 50; float lineColorRange = 160; Node(float xPos, float yPos) { x = xPos; y = yPos; numNeighbors = 0; neighbors = new ArrayList<Node>(); } void display() { noStroke(); fill(fillColor); ellipse(x,y,nodeWidth,nodeHeight); } void addNeighbor(Node node) { neighbors.add(node); } void setNumNeighbors(int num) { numNeighbors = num; } void clearNeighbors() { neighbors = new ArrayList<Node>(); } float calculateLineColor(Node neighborNode, float maxDistance) { float distance = sqrt((x-neighborNode.x)*(x-neighborNode.x) + (y-neighborNode.y)*(y-neighborNode.y)); lineColor = (distance/maxDistance)*lineColorRange; return lineColor; } }