// visualize_Pacman (2005. 4. 25.) // by SeungJoon Choi // erucipe@hanmail.net // // http://risknfun.com/pacman/index_e.html // http://processing.org import processing.net.*; float fw, fh; int rr, gg, bb; Player[] players = null; Client client; void setup() { size(400, 400, P3D); background(0); noStroke(); fw = 38.1 * 19; fh = 38.1 * 11; rr = (int)random(255); gg = (int)random(255); bb = (int)random(255); players = new Player[3]; for(int i = 0; i < 3; i++) { players[i] = new Player(); } client = new Client(this, "http://epicure.graffity.net", 80); client.write("GET /things/projects/pacman/game050424/1113/pml.log HTTP/1.1\n"); client.write("HOST: epicure.graffity.net\n\n"); } void paint_m(String s) { noStroke(); String[] b = s.split(","); if(b.length == 4) { //fill(rr, gg, bb, 2); beginShape(TRIANGLES); fill(rr+127, 0, 0, 10); vertex(players[0].x, players[0].y); fill(0, gg+127, 0, 10); vertex(players[1].x, players[1].y); fill(0, 0, bb+127, 10); vertex(players[2].x, players[2].y); endShape(); float y = float(b[3]) / fh * width; float x = float(b[2]) / fw * height; if(int(b[1]) == 0) { fill(255, 255, 0, 24); } if(int(b[1]) == 1) { players[0].x = x; players[0].y = y; fill(255, 0, 0, 24); } if(int(b[1]) == 2) { players[1].x = x; players[1].y = y; fill(0, 255, 0, 24); } if(int(b[1]) == 3) { players[2].x = x; players[2].y = y; fill(0, 0, 255, 24); } float size = 30*random(1); ellipse(x + (1-2*random(1))*30, y + (1-2*random(1))*30, size+30*random(1), size+30*random(1)); } } void paint_g(String s) { String[] b = s.split(","); if(b.length == 3) { if(int(b[1]) == 2) { //power fill(random(255), random(255), random(255), 127); int py = int(b[2]) / 19; int px = int(b[2]) % 19; float x = px*38.1 + 38.1*0.5; float y = py*38.1 + 38.1*0.5; float radius = 100 + random(100); float x1 = y / fh * width; float y1 = x / fw * height; ellipse(x1, y1, radius, radius); float x2 = x1; float y2 = y1; for(int k = 0; k < 10; k++) { x2 += (1 - random(2))*random(200 / (k+1)); y2 += (1 - random(2))*random(200 / (k+1)); fill(random(255), random(255), random(255), 64); radius *= 0.9; ellipse(x2, y2, radius, radius); } } if(int(b[1]) == 1) { //dot //fill(255, 255, 255, 127); int py = int(b[2]) / 19; int px = int(b[2]) % 19; float x = px*38.1 + 38.1*0.5; float y = py*38.1 + 38.1*0.5; //ellipse(y / fh * width, x / fw * height, 100, 100); //curve(x1, y1, x2, y2, x3, y3, x4, y4); float y1 = y / fh * width; float x1 = x / fw * height; int n = int(3 + random(7)); for(int j = 0; j < n; j++) { strokeWeight(random(5)); stroke(random(255), 255, 255, random(64)); beginShape(LINE_STRIP); curveVertex(x1, y1); curveVertex(x1, y1); float x2 = x1; float y2 = y1; for(int k = 0; k < 10; k++) { x2 += (1 - 2*random(1))*random(k*5); y2 += (1 - 2*random(1))*random(k*5); curveVertex(x2, y2); } endShape(); } } } } String sbuff = ""; int mode = 0; void draw() { int xx = int(random(width-1)); int yy = int(random(height-1)); int pos = yy * width + xx; rr += (1-random(2))*16; gg += (1-random(2))*16; bb += (1-random(2))*16; fill(rr, rr, rr, random(16)); noStroke(); rect(xx, yy, 8 + random(24), 8 + random(24)); if (client.available() > 0) { int inByte = client.read(); if((char)inByte == 'm') { mode = 0; sbuff = ""; sbuff += (char)inByte; } if((char)inByte == 'g') { mode = 1; sbuff = ""; sbuff += (char)inByte; } if((char)inByte == '\r') { if(mode == 0) { paint_m(sbuff); } if(mode == 1) { paint_g(sbuff); } sbuff = ""; } else { sbuff += (char)inByte; } } } class Player { public Player() { x = 0; y = 0; } float x, y; }