interface & application programming
initital tries
I was not able to get the hello.echo board to properly communicate with processing. It was communicating to the serial port (as proven by Arduino.app). Yet, I do know how to use processing...
web app
Here is an example of processing.js which runs a simple flocking algorithm.
/**
flockingWithConnex_1.pde
| Henry G. Skupniewicz
(|| henryskup.com
||)
|
*/
int winWidth = 500;
int winHeight = 500;
int sight = int(.08 * winWidth);
int personalSpace = sight;
int incSize = int(.005 * winWidth);
// n = double the sudo-max circle packing in area... v.unscientific.
int n = int(2*((winWidth*winHeight)*.9069)/(PI*sq(sight*.5)));
int boidSize = 0;
float connexThickness = .1;
int margin = 10;
Flock F = new Flock();
void setup() {
size(winWidth, winHeight);
background(255);
stroke(0,0,0,255);
fill(0);
smooth();
F.makeFlock(n);
}
void draw(){
fill(255,100);
noStroke();
rect(0,0,winWidth,winHeight);
fill(0,0,0,100);
F.updateFlock(10);
int xPos = null;
int yPos = null;
updatePersonalSpace(mouseX, mouseY);
}
void passCursorPosition(int x, int y){
updatePersonalSpace(x, y);
}
void updatePersonalSpace(int x, int y) {
PVector center = new PVector((winWidth/2), (winHeight/2),0);
PVector cursorLoc = new PVector(x, y,0);
float maxDist = center.mag();
float cursorDist = center.dist(cursorLoc);
float newPersonalSpace = map(cursorDist,0,maxDist,sight,0);
personalSpace = int(newPersonalSpace);
}
class Flock {
Boid[] Boids = new Boid[n];
Boid[] makeFlock(int n) {
for (int i=0;i=(winWidth - margin)){
dX = random(-incSize, 0);
} else {
dX = random(-incSize, incSize);
}
if (loc.y<=margin) {
dY = random(0, incSize);
} else if (this.loc.y>=(winWidth - margin)){
dY = random(-incSize, 0);
} else {
dY = random(-incSize, incSize);
}
PVector dV = new PVector(dX, dY,0);
dV.add(connex);
this.loc.add(dV);
}
PVector makeConnections(Boid[] Boids){
PVector connex = new PVector(0,0,0);
for (Boid B : Boids){
float dist = this.loc.dist(B.getLoc());
if ((dist <= float(sight))&&(B!=this)) {
strokeWeight(connexThickness);
line(this.loc.x, this.loc.y, B.loc.x, B.loc.y);
PVector vec = new PVector((B.loc.x-this.loc.x),(B.loc.y-this.loc.y),0);
if (dist > personalSpace){
connex.add(vec);
} else {
connex.sub(vec);
}
} else {continue;}
}
connex.normalize();
return connex;
}
ArrayList findNearBoids() {
ArrayList nearBoids = new ArrayList();
return nearBoids;
}
PVector getLoc(){
return this.loc;
}
}