/* data visualization for sesnon
by nick lally and nik hanselmann
*/
PImage bufSlice;
PGraphics buf;
CameraPosition campos;
int camCount;
String[] temp_array;
float[] lpst = new float [4];
float[] lpst_tween = new float[4];
int counter;
int screencount;
int numFloaters = 10; //number of lines
Floaters[] floaters = new Floaters[numFloaters]; //create array for lines
//Noise noises;
//float cur_ms;
float nex_ms;
squiggle[] s = new squiggle[10];
void setup() {
size(1024, 768, P3D);
colorMode(HSB);
fill(100);
campos = new CameraPosition();
buf = createGraphics(2000, 2000, P3D);
buf.beginDraw();
//buf.smooth();
buf.background(255);
buf.endDraw();
//initialize starting points of lines
for (int i = 0; i < numFloaters; i++) {
floaters[i] = new Floaters(100 + i*150, 10, random(10));
}
for(int i = 0; i < s.length; i++){
s[i] = new squiggle();
}
fill(0,20);
stroke(255,70);
counter = 100;
getData();
//cur_ms = millis();
nex_ms = millis();
}
void draw() {
if(millis() >= nex_ms && screencount <= 60){
buf.save("screenshot" + screencount + ".tiff");
screencount++;
nex_ms = millis() + 60000;
}
translate(width/2,height/2);
for(int i = 0; i < s.length; i++){
}
counter--;
if(counter <= 0){
counter = 100;
getData();
}
//println (counter);
for (int i = 0; i < numFloaters; i++) {
buf.beginDraw();
floaters[i].move();
pushMatrix();
translate(buf.width/2, buf.height/2);
s[i].draw();
popMatrix();
buf.endDraw();
}
campos.move(floaters[int(camCount/100)].x-width/2, floaters[int(camCount/100)].y-500);
//println(floaters[int(camCount/1000)].y);
if (camCount >= (numFloaters-1) * 100) {
camCount = 0;
}
camCount ++;
}
class Floaters {
float x, y; //position
float prevX, prevY; //previous position
int count = 0;
float radius;
//Noise noises;
int direction;
//contructor
Floaters(float xpos, float ypos, float r) {
x = xpos;
y = ypos;
prevX = x-1;
prevY = y-1;
radius = r;
//noises = new Noise();
direction = 1;
}
//move method
void move() {
count++;
prevX = x;
prevY = y;
radius += random(.02);
/*if (count > 150){
x = x + sin(radius);
y = y + -cos(radius)+.1;
} else {
x = x + sin(radius);
y = y + cos(radius)+.1;
}
if (count > 300) {
count = 0;
} */
x = x + (direction * sin(radius));
y = y + cos(radius)+.1;
if ((x < 10) || (y < 10) || (x > buf.width-10) || (y > buf.height-10)){
x = buf.width/2;
y = buf.height/2;
}
color cp;
float b;
//test next pixel
/*if (int(prevX) != int(x) && int(prevY) != int(y)){
cp = buf.get(int(x),int(y));
b = brightness(cp);
if (b < 240){
direction = direction * -1;
//println("change");
}
//println(direction);
}*/
//call Noise class
//noises.move(x,y);
stroke(100);
buf.point(x, y);
}
}
class Noise {
float x, y; //position
float prevX, prevY; //previous position
int count = 0;
float radius;
void move(float xpos, float ypos) {
x = xpos;
y = ypos;
//draw tail
stroke(random(220,240));
buf.point(x + random(1,4), y + random(1,4));
stroke(random(220,240));
buf.point(x + random(1,4), y + random(1,4));
stroke(random(220,240));
buf.point(x - random(1,4), y - random(1,4));
stroke(random(220,240));
buf.point(x - random(1,4), y - random(1,4));
color cp;
float b;
cp = buf.get(int(x+1),int(y));
b = brightness(cp);
if (b != 0){
stroke(200);
buf.point(x+1,y);
}
cp = buf.get(int(x-1),int(y));
b = brightness(cp);
if (b != 0){
stroke(200);
buf.point(x-1,y);
buf.point(x + random(4), y+ random(4));
}
}
}
class CameraPosition {
float x, y; //position
float currentX = 0;
float currentY = 0;
float easing;
void move(float destX, float destY) {
x = destX;
y = destY;
easing = .2;
currentX += (y - currentX) * easing;
currentY += (x - currentY) * easing;
background(255);
image(getBufSlice(currentX, currentY), -width/2, -height/2); // plot current position
}
}
PImage getBufSlice(float currentX, float currentY) {
int x = int(currentX);
int y = int(currentY);
return buf.get(x, y, width, height);
}
class squiggle{
float rad;
float x,y;
float rand_turn;
boolean turn = false;
float speed;
//float width;
squiggle(){
x = buf.width/2;
y = buf.height/2;
rad = random(0,2*PI);
//speed = lpst[3];//random(.02, lpst[3]);
//lpst_tween[0] = lpst[0];
//lpst_tween[0] = lpst
}
void draw(){
if(lpst_tween[3] < lpst[3]){
lpst_tween[3] +=.1;
}
if(lpst_tween[3] > lpst[3]){
lpst_tween[3] -=.1;
}
if(lpst_tween[1] > lpst[1]){
lpst_tween[1] -= 1;
}
if(lpst_tween[1] < lpst[1]){
lpst_tween[1] += 1;
}
speed = 5;
//buf.popMatrix();
buf.fill(100,255-map(lpst_tween[0], 0,400,0,255));
//println(255 - map(lpst_tween[0],0,420,0,255));
buf.line(x,y,cos(rad) * (lpst_tween[1]/7) + x, sin(rad) * (lpst_tween[1]/7) + y);
//strokeWeight(lpst[0]/50);
//buf.stroke(lpst_tween[0], lpst_tween[0]);
buf.stroke(sin(rad) * 255,255-map(lpst_tween[0], 0,400,40,255));
//println(lpst_tween[0]);
//stroke(map(lpst[0],0,420,0,255),map(lpst[0],0,420,0,255));
buf.ellipse(x,y,(-lpst_tween[3]),(-lpst_tween[3]));
//println(lpst_tween[3]);
//buf.pushMatrix();
if(lpst_tween[0] < lpst[0]){
lpst_tween[0]+=.3;
}
if(lpst_tween[0] > lpst[0]){
lpst_tween[0]-=.3;
}
x = cos(rad) * speed + x;
y = sin(rad) * speed + y;
if(sqrt(sq(x - (buf.width/2)) + sq(y - (buf.height/2))) < 850){
rad += random(-.25,.25);
turn = false;
}
else {
if(turn == false){
rand_turn = random(.1,.3);
turn = true;
}
rad += rand_turn;
}
}
}
void getData(){
String query = "http://transmogrify.me/loungeout.php";
println(query);
String[] results = loadStrings(query);
for(int i = 0; i < results.length; i++){
temp_array = split(results[i],',');
}
//for ( int i=0; i< temp_array.length -1; i++){
println(temp_array);
lpst[0] = float(temp_array[1]);
lpst[1] = float(temp_array[2]);
lpst[2] = float(temp_array[4]);
lpst[3] = float(temp_array[3]);
//println( q + ", " + w + ", " + e + ", " + r);
//}
//}
}
void keyPressed(){
if(key == 'q'){
buf.save("screenshot" + screencount + ".tiff");
screencount++;
}
if(key == 'c'){
buf.background(255);
}
}