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.

11.1 fall Leaves

5. Dezember 2011


import processing.serial.*;  // Import the Processing Serial Library for communicating with arduino
Serial myPort;               // The used Serial Port

int Window = 600;
int xVal,yVal,zVal;
float xRotate, yRotate;
void setup()
{
size(Window,Window,P3D);
background(200,190,143);
noStroke();
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
}

void draw()
{
float xValCorrected = float(xVal)/64;
float yValCorrected = float(yVal)/64;
float zValCorrected = float(zVal)/64;

println(xValCorrected +"\t"+yValCorrected +"\t"+zValCorrected);
if(zValCorrected > 0)
{
xRotate = map(xVal,-64,64,0,180);
yRotate = map(yVal,-64,64,180,360);

}else{
xRotate = map(xVal,-64,64,180,0);
yRotate = map(yVal,-64,64,180,0);

}
rotateX(radians(xRotate));
rotateY(radians(yRotate));
pushMatrix();
drawOneLeaf();
popMatrix();
//box(95);
}

void drawOneLeaf()
{
PVector pA = new PVector(-0.5,0.0);
PVector pB = new PVector(0.5,0.0);
PVector pG1 = makeControlPoint(-0.25,-0.15,0.15,-0.05,-0.15,0.0);
PVector pG2 = makeControlPoint(0.25,-0.15,0.15,-0.05,-0.15,0.0);
PVector pH1 = makeControlPoint(-0.25,-0.15,0.15,0.05,0.0,0.15);
PVector pH2 = makeControlPoint(0.25,-0.15,0.15,0.05,0.0,0.15);

float yMove = random(0,0.35);
pG2.y +=yMove;
pH2.y +=yMove;

int myRed = int(random(50,255));
int myGrn = int(random(50,255));
int myBlu = int(random(50,255));

fill(color(myRed,myGrn,myBlu,128));
float xTrans = random(-Window,Window);
float yTrans = random(-Window,Window);
float zTrans = random(-Window,Window);
translate(xTrans,yTrans,zTrans);
float scaleFactor = random(0.6,1.0);
scale(scaleFactor * Window/2);
float rotationAngle = random(0,360);
rotate(radians(rotationAngle));
beginShape();
vertex(pA.x,pA.y);
bezierVertex(pG1.x,pG1.y,pG2.x,pG2.y,pB.x,pB.y);
bezierVertex(pH2.x,pH2.y,pH1.x,pH1.y,pA.x,pA.y);
endShape();
}

PVector makeControlPoint(float x,float dxlo,float dxhi,float y, float dylo,
float dyhi){
float px = x + random(dxlo,dxhi);
float py = y + random(dylo,dyhi);
PVector t =new PVector(px,py);
return(t);
}
void serialEvent(Serial myPort) // Is called everytime there is new data to read
{
if (myPort.available() > 0)
{
String completeString = myPort.readStringUntil(10); // Read the Serial port until there is a linefeed/carriage return
if (completeString != null) // If there is valid data insode the String
{
trim(completeString); // Remove whitespace characters at the beginning and end of the string
String seperateValues[] = split(completeString, "\t"); // Split the string everytime a delimiter is received
xVal = int(seperateValues[0]);
yVal = int(seperateValues[1]);
zVal = int(seperateValues[2]);
}
}
}