//3d cam adapted from Ariel Malka | http:www.chronotext.org float fovy, aspect, Znear, Zfar; float elevation, azimuth, twist, distance; //init color modification vars float globr1, globr2, globg1, globg2, globb1, globb2; float incr, incg, incb, overr, overg, overb; int colcount, rmod, gmod, bmod; //set fade rate float fad = 40; // brick+girder particulars Pixel[] myPixels; float bricksize, brickdepth, brickspc, spacersize, barwidth, inch, xloc, yloc; int countx, county, tot, count; // set up traffic variables Peep[] myPeeps; int bodies, setspeed, high, standpos; BFont meta; //interface array int[] button = { 0,0,0,0,0,0,0,0,0,0,0,0 }; void setup() { noStroke(); size(600, 400); //grid+measurement setup countx = 8; county = 8; tot = countx*county; bricksize = 10; brickdepth = 2; brickspc = .33; spacersize = bricksize*brickspc; barwidth = countx*bricksize+((countx+1)*spacersize); inch = bricksize/12; colcount = tot-1; //traffic setup standpos = tot-1; bodies = 3; setspeed = 12; //3D setup xloc = 25; yloc = -55; distance = 350.0; elevation = 0.0; azimuth = 0.0; twist = 0.0; fovy = 30.0; aspect = (float)width / (float)height; Znear = 1.0; // ? Zfar = 1000.0; // ? meta = loadFont("Meta.vlw.gz"); textFont(meta, 17); myPixels = new Pixel[tot]; myPeeps = new Peep[bodies]; setGlob(); setMod(); sphereDetail(16); for (int i=0; i < tot; i++){ myPixels[i] = new Pixel(); myPixels[i].rtarg = globr1 + (incr*rmod*i) + 2; myPixels[i].gtarg = globg1 + (incg*gmod*i) + 2; myPixels[i].btarg = globb1 + (incb*bmod*i) + 2; } for (int i=0; i < bodies; i++){ myPeeps[i] = new Peep(); myPeeps[i].speed = int(random(5)+setspeed); myPeeps[i].peephigh = int(random(12)+48); if(random(100)>50){ myPeeps[i].pos = int(random(countx)); myPeeps[i].up = 1; }else{ myPeeps[i].pos = int(random(countx)+(tot-countx));; myPeeps[i].up = -1; } } } void loop() { background(64); // advance bodies for (int i=0; i= (tot-1)){ fad = random (40); colcount = 0; setGlob(); setMod(); } } } } class Peep { int up; int speed; int dir = 1; int pos; int pincr = 0; int dirmod = 1; int peephigh; void run() { pincr++; if (pincr==speed){ if (random(100) >= 90){ if (random(100) >= 50){ dirmod = 1; }else{ dirmod = -1; } dir = 1*dirmod; }else{ dir = countx*up; } pos += dir; pincr = 0; if (pos < -countx*2){ pos = int(random(countx)); speed = int(random(5)+setspeed); peephigh = int(random(12)+48); up = 1; } if (pos > tot+(countx*2)){ pos = int(random(countx)+(tot-countx)); speed = int(random(5)+setspeed); peephigh = int(random(12)+48); up = -1; } } } } void setGlob() { //reset global gradation values globr1 = random (255); globg1 = random (255); globb1 = random (255); globr2 = random (255); globg2 = random (255); globb2 = random (255); incr = abs((globr1-globr2)/tot); incg = abs((globg1-globg2)/tot); incb = abs((globb1-globb2)/tot); overr = random(128)+128; overg = random(128)+128; overb = random(128)+128; } void setMod() { if (globr2 >= globr1){ rmod = 1; }else{ rmod = -1; } if (globg2 >= globg1){ gmod = 1; }else{ gmod = -1; } if (globb2 >= globb1){ bmod = 1; }else{ bmod = -1; } } void loadInterface() { int y = 20; int l = 12; fill(200); text("MOVE", 23, 30); drawNav(35, 40, 35, 50, 45, 50, 40, 40, 10, 10, 0); if (button[0] == 1){ yloc-=5; button[0] = 0; } drawNav(35, 70, 35,70, 45,70, 40,80, 10, 10, 1); if (button[1] == 1){ yloc+=5; button[1] = 0; } drawNav(50, 55, 50,55, 50,65, 60,60, 10, 10, 2); if (button[2] == 1){ xloc+=5; button[2] = 0; } drawNav(20, 55, 30,55, 30,65, 20,60, 10, 10, 3); if (button[3] == 1){ xloc-=5; button[3] = 0; } fill(200); text("ROTATE", y, 110); drawNav(35, 120, 35,130, 45,130, 40,120, 10, 10, 4); if (button[4] == 1){ elevation -= 1; button[4] = 0; } drawNav(35, 150, 35,150, 45,150, 40,160, 10, 10, 5); if (button[5] == 1){ elevation += 1; button[5] = 0; } drawNav(50, 135, 50,135, 50,145, 60,140, 10, 10, 6); if (button[6] == 1){ azimuth -= 1; button[6] = 0; } drawNav(20, 135, 30,135, 30,145, 20,140, 10, 10, 7); if (button[7] == 1){ azimuth += 2; button[7] = 0; } fill(200); text("ZOOM", 23, 190); drawTextnav (23,200, 12,12,8,"-"); if (button[8] == 1){ distance += 5; button[8] = 0; } drawTextnav (43,200, 12,12,9,"+"); if (button[9] == 1){ distance -= 5; button[9] = 0; } fill(200); text("TRAFFIC SPEED: "+(20-setspeed), 23, 250); drawTextnav (23,260, 12,12,10,"<<"); if (button[10] == 1){ if (setspeed < 20){ setspeed += 1; } button[10] = 0; } drawTextnav (43,260, 12,12,11,">>"); if (button[11] == 1){ if (setspeed > 2){ setspeed -= 1; } button[11] = 0; } fill(200); text("use directional keys", 23, 350); text("to move grey block", 23, 365); } void drawNav(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int wide, int hi, int id) { float mx = mouseX; float my = mouseY; if(mx>x1 && mxy1 && myx1 && mxy1 && my0){ standpos -= 1; } } if(key==UP){ if (standpos>=countx){ standpos -= countx; } } if(key==DOWN){ if (standpos < tot-countx){ standpos += countx; } } }