/ Published in: Processing
the Amazing Blinkenlights (w/o images... or documentation for that part)
Expand |
Embed | Plain Text
import processing.opengl.*; import javax.media.opengl.*; // import libraries import hypermedia.net.*; UDP udp; // define the UDP object PImage bg, bgRed, sl, light, trig, e404, e500; float radius, top_env, left_env,a; String timeStr; int totalUsers, activeUsers; PFont led; boolean b0rken = false; PGraphicsOpenGL pgl; GL gl; float noiseScale=0.02; Dot[] dots; void setup() { size(screen.width, screen.height, OPENGL); background(0); smooth(); noStroke(); noCursor(); bg = loadImage("worldmap.green.png"); bgRed = loadImage("world-map-square-projection-red.png"); sl = loadImage("scanlines.png"); light = loadImage("dot.green.png"); trig = loadImage("trig.png"); e404 = loadImage("404.png"); e500 = loadImage("500.png"); led = loadFont("DS55.vlw"); totalUsers = 1200; activeUsers = 1200; top_env = (screen.width/2 - bg.width/2); left_env = (screen.height/2 - bg.height/2); dots = new Dot[0]; udp = new UDP( this, 1984 ); udp.listen( true ); // udp.log( true ); radius = ( 1024 / TWO_PI ); } void draw(){ background(0); pgl = (PGraphicsOpenGL) g; gl = pgl.gl; if(b0rken){ image(bgRed, top_env, left_env); textAlign(CENTER); textFont(led, 50); text(b0rkenMsg, 512+top_env, 334+left_env); fill(#FF0000); } else { noTint(); image(bg, top_env, left_env); setTotalUsers(); setActiveUsers(); setTime(); } pgl.beginGL(); for(int i=0; i<height; i+=2) { gl.glColor4f( 0, 0, 0, random(.1, .3)); gl.glRectf(0, i, width, i+1); } for(int i=0; i<width; i+=5) { gl.glColor4f( 0, 0, 0, random(0, .1)); gl.glRectf(i, 0,i+1, height); } // This fixes the overlap issue gl.glDisable(GL.GL_DEPTH_TEST); // Turn on the blend mode gl.glEnable(GL.GL_BLEND); // Define the blend mode gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_DST_ALPHA); if(!b0rken){ for(int i=0; i<dots.length; i++) { if(dots[i] instanceof Dot){ dots[i].update(); dots[i].draw(); if(dots[i].a < 0) dots = removeDot(i, dots); } } for(int i=0; i<lines.length; i++) { lines[i].update(); lines[i].draw(); if(lines[i].a < 0) lines = removeLine(i, lines); } } } pgl.endGL(); } //data = contract(data, data.length-1); // print the result println("recived: " + message + " from IP: " + ip + " on Port: " + port); handle(message); } dots = (Dot[])expand(dots, dots.length+1); dots[dots.length-1] = new Dot(x, y, 255, type, rate, msg, col); } void addLine(float x, float y, float xx, float yy, float rate){ } float x = -100; float xx = -100; float y = -100; float yy = -100; if( s.indexOf(":") > -1 && !b0rken ){ if( s.indexOf(",") > -1 ){ y = latToY( float(coordinates[0]) ); x = longToX( float(coordinates[1]) ); if(coordinates.length > 3) msg = coordinates[2]; if(action.length > 3){ yy = latToY( float(coordinates2[0]) ); xx = longToX( float(coordinates2[1]) ); if(coordinates2.length > 2) msg2 = coordinates2[2]; } } if( action[0].indexOf("request") > -1){ color col; float r, r_time; if( action.length == 3){ r_time = float(action[2]); r_time = constrain(r_time, 1.0, 16.0); r = ( r_time-1.0 ) / float(15); r_time = r_time/30; col = color(r*255, 255-(r*255), 0); } else { col = color(0,255,0); r_time = 10; } addDot(x, y, light, r_time, msg, col); } if( action[0].indexOf("500") > -1){ addDot(x, y, e500, 0.1, msg, #FF0000); } if( action[0].indexOf("404") > -1){ addDot(x, y, e404, 0.1, "error", #FFFF00); } if( action[0].indexOf("logged") > -1){ activeUsers = int(action[1]); } if( action[0].indexOf("registered") > -1){ totalUsers = int(action[1]); } if( action[0].indexOf("build_failure") > -1){ b0rken = true; b0rkenMsg = action[1]; } if( action[0].indexOf("trig") > -1){ addDot(x, y, trig, 0.1, msg, #0000FF); addDot(xx, yy, trig, 0.1, msg2, #0000FF); addLine(x, y, xx, yy, 0.1); } } else { if( s.indexOf("login") > -1){ activeUsers++; } if( s.indexOf("logout") > -1){ activeUsers--; } if( s.indexOf("signup") > -1){ totalUsers++; } if( s.indexOf("build_success") > -1){ b0rken = false; } } } float longToX(float longitudeDegrees){ float longitude = radians(longitudeDegrees); return ( (radius * longitude) + 461 + top_env )*2; } float latToY(float latitudeDegrees){ float latitude = radians(latitudeDegrees); float y = radius/2.0 * log( (1.0 + sin(latitude)) / (1.0 - sin(latitude)) ); return ((y * -1.0) + 450 + left_env)*2; } void mousePressed(){ addDot(float(mouseX-20)*2, float(mouseY-20)*2, light, 10, mouseX + "," + mouseY, #00FF00); } float x, y, xx, yy, a, rate; x = ix; y = iy; xx = ixx; yy = iyy; a = ia; rate = irate; } void update(){ if(a > 0) a = a - rate; } void draw(){ float diff; if(a > 0){ stroke(#0046FF, a); noFill(); diff = (x - xx)*2; if(diff < 0) diff = diff * -1; curve(x+diff, y+diff, x+20, y+20, xx+20, yy+20, xx+diff, yy+diff); } } } class Dot{ float x, y, a, rate; PImage type = light; String msg; color col; x = ix; y = iy; a = ia; type = itype; rate = irate; msg = imsg; col = icol; } void update() { if(a > 0) a = a - rate; } void draw() { if(a > 0){ tint(255, a); fill(col, a); textFont(led, 24); text(msg, x+40, y+20); image(type, x, y, 80, 80); } } } void setActiveUsers(){ fill(#73FF02); textFont(led, 59); textAlign(LEFT); text(activeUsers, 5+top_env, 55+left_env); } void setTotalUsers(){ fill(#73FF02); textFont(led, 59); textAlign(RIGHT); text(totalUsers, 1019+top_env, 55+left_env); } void setTime(){ fill(#73FF02); textFont(led, 59); textAlign(LEFT); if(h.length() < 2) h = "0" + h; if(m.length() < 2) m = "0" + m; text(h + ":" + m, 5+top_env, 645+left_env); } Dot[] removeDot(int _i, Dot[] _a){ Dot[] b = new Dot[_a.length-1]; arraycopy(_a, 0, b, 0, _i); arraycopy(_a, _i+1, b, _i, b.length-_i); return b; } arraycopy(_a, 0, b, 0, _i); arraycopy(_a, _i+1, b, _i, b.length-_i); return b; }
You need to login to post a comment.
