Skip to content

Commit

Permalink
Merge pull request #5 from brainmachine/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
timrolls authored Sep 8, 2017
2 parents 9d8c2a5 + e49ff91 commit a7dcef3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
32 changes: 21 additions & 11 deletions LightWork_Scraper/LightWork_Scraper.pde
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,45 @@ int pos;
float margin =50;

void setup() {
size(800, 800, JAVA2D); //wtf
size(640, 480, JAVA2D); //wtf
background(0);

//initialize scraper
scrape = new Scraper("mapper-lightwork-filtered-negative.svg");
scrape = new Scraper("layout.svg");
scrape.init();
scrape.normCoords();

opc = new OPC(this, "fade1.local", 7890);
scrape.update();
opc.showLocations(false);

//display array of points from SVG
//println(scrape.getArray());
}

void draw() {
background(0);

rect(0,0,50,50);
//scrape.update();
scrape.display();
// Test animation
//noFill();
//strokeWeight(25);
//for (int i = 0; i < 100; i+=10) {
// stroke(255-i*2.5*sin(frameCount*0.7), i*2.5*sin(frameCount*0.5), 255*sin(frameCount*0.2));
// ellipse(width/2, height/2, i*100*sin(frameCount*0.02), i*100*sin(frameCount*0.02));
//}
// End test animation


//rect(0,0,50,50); //test margin bounds
scrape.display();

//simple chase animation
noStroke();
fill(0,0,255);
if(pos<=width)pos+=5;
fill(255*sin(frameCount*0.1), 255*sin(frameCount*0.3), 255*cos(frameCount*0.6));
if (pos<=width)pos+=5;
else pos=0;
rect(pos,0,100,height);

rect(pos, 0, 100, height);
ellipse(mouseX, mouseY, 30, 30);


}
42 changes: 30 additions & 12 deletions LightWork_Scraper/Scraper.pde
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ public class Scraper {
// Now we can actually get the vertices from each child
for (int j = 0; j < total; j++) { //using 1 to fix duplicate first point issue temporarily
PVector v = child.getVertex(j);
if(v.x>=0 && v.y>=0){

v.set (v.x, v.y);
loc.add(v);
//print(v);
}
}
}
}
Expand All @@ -35,13 +34,18 @@ public class Scraper {
void normCoords()
{
float[] norm = new float[4];
norm = getMinMaxCoords();
norm = getMinMaxCoords(loc);

int index=0;

//println(loc);

for (PVector temp : loc) {
temp.set (map(temp.x, norm[0], norm[2], 0, 1), map(temp.y, norm[1], norm[3], 0, 1));
loc.set(index, temp);
if (temp.x>0 && temp.y>0) {
temp.set (map(temp.x, norm[0], norm[2], 0.001, 1), map(temp.y, norm[1], norm[3], 0.001, 1));
loc.set(index, temp);

}
index++;
}
}
Expand All @@ -55,33 +59,47 @@ public class Scraper {

//draw based on coords in arraylist. enhanced arraylist loop
for (PVector temp : loc) {
ellipse(map(temp.x, 0, 1, margin, width-margin), map(temp.y, 0, 1, margin, height-margin), 10, 10);
if (!(temp.x == 0.0) && !(temp.y == 0.0)) {
ellipse(map(temp.x, 0, 1, margin, width-margin), map(temp.y, 0, 1, margin, height-margin), 10, 10);
}
}

}

//set led coords in opc client
void update() {
void update() { //<>//
int index =0;
for (PVector temp : loc) {
opc.led(index, (int)map(temp.x, 0, 1, margin, width-margin), (int)map(temp.y, 0, 1, margin, height-margin));
index++;
}

println(loc.size());
}

ArrayList getArray() {
return loc;
}

//deterimines bounding box of points in SVG for normalizing
float[] getMinMaxCoords() {
float xArr[] = new float[loc.size()];
float yArr[] = new float[loc.size()];
float[] getMinMaxCoords(ArrayList<PVector> points) {
ArrayList<PVector> pointsCopy = new ArrayList<PVector>(points);

for (int i=pointsCopy.size()-1; i>=0; i--) {
PVector temp = pointsCopy.get(i);
if (temp.x==0 && temp.y==0) {
pointsCopy.remove(i);
}
}

float xArr[] = new float[pointsCopy.size()];
float yArr[] = new float[pointsCopy.size()];

int index =0;
for (PVector temp : loc) {
for (PVector temp : pointsCopy) {

xArr[index] = temp.x;
yArr[index] = temp.y;

index++;
}

Expand Down
3 changes: 3 additions & 0 deletions LightWork_Scraper/data/lightwork_map_complete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a7dcef3

Please sign in to comment.