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.

Lesson 3.1 – Multiple Reactor Points

Multiple Reactor Points

ArrayList<PVector> reactorList = new ArrayList<PVector>();
int maxPointCount = 20;
int gridWidth = 30;
int gridHeight = 30;
float shapeWidth = 19;
float shapeHeight = 19;
float reactorScaler = .008;

void setup() {
size(500,500);
smooth();
}

void draw() {
background(255);
PVector temp = new PVector(mouseX,mouseY);
reactorList.add(temp);
if (reactorList.size() >= maxPointCount) {
reactorList.remove(0);
}

drawGeometry();
}

void drawGeometry() {

// unconment to see the trail of reactors created by mouse movement

//stroke(255,0,0);
// for(int i = 0; i <reactorList.size()-1; i++) {
//  line(reactorList.get(i).x,reactorList.get(i).y, reactorList.get(i+1).x, reactorList.get(i+1).y);
// }

stroke(0);
noFill();
for(int i = 0; i<gridWidth; i++ ) {
for(int j = 0; j<gridHeight; j++ ) {
PVector myPos = new PVector(i*shapeWidth, j*shapeHeight);
PVector cpt = closestPoint(myPos);
float reactorDistance = dist(cpt.x, cpt.y, myPos.x, myPos.y);
float scaler = reactorDistance*reactorScaler;
ellipse(myPos.x, myPos.y, shapeWidth*scaler, shapeHeight*scaler);
};
};

}

PVector closestPoint(PVector location) {
PVector tempPoint = reactorList.get(0);
float bestDistance = dist(tempPoint.x,tempPoint.y,location.x,location.y);
for (int i = 0; i < reactorList.size(); i++) {
float tempDistance = dist(reactorList.get(i).x,reactorList.get(i).y,location.x,location.y);
if (tempDistance<bestDistance) {
bestDistance = tempDistance;
tempPoint = reactorList.get(i).get();
}
}
return tempPoint;
}


Exercise: Create a new examples using this principle by modifying the code with different geometric forms. Try rotation, colour change or deformations, or combining it with elements from previous exercises