/* * Agent Architecture Demo : To visualize the work done by intelligent agents. */ import java.util.ArrayDeque; // Globals int frame; int nowTime; DataQueue[] queues; int[] lastValues; int leastMax; boolean go = true; int size = 8; void setup() { frame = 0; size(500, 500); nowTime = (int)(width * .75); strokeCap(SQUARE); smooth(); populate(); } void keyPressed() { if (key == CODED) { if (keyCode == UP) { if (size < 64) { size*=2; populate(); } } if (keyCode == DOWN) { if (size > 2) { size/=2; populate(); } } } } void populate() { queues = new DataQueue[size]; lastValues = new int[size]; float ratio = (((float)size/64)*.5)+.25; float lWeight = (ratio*height)/size; for (int i=0; i queue = new ArrayDeque(); float yPosition; float lineWeight; DataQueue(float yPosition, float lineWeight) { this.yPosition = yPosition; this.lineWeight = lineWeight; } void display(int frame) { strokeWeight(lineWeight); // Draw a black background for this queue //stroke(0); //line(0,yPosition,nowTime-2,yPosition); int last = -1; for (int x : queue) { if (x-frame <= leastMax) stroke(STAGE3,255); else if (x-frame < nowTime) stroke(STAGE2,224); else stroke(STAGE1,160); if (last >= 0) line(last-frame+1,yPosition,x-frame-1,yPosition); last = x; } int max = getCurrentMax(frame,nowTime); noStroke(); fill(255,255,255); ellipse(max,yPosition,BULLSEYE_SIZE*2,BULLSEYE_SIZE*2); fill(0,0,0); ellipse(max,yPosition,BULLSEYE_SIZE,BULLSEYE_SIZE); } int getCurrentMax(int frame, int rightLimit) { int last = 0; for (int x : queue) { if (x-frame >= rightLimit) return last; last = x-frame; } return last; } void extend(int frame) { boolean lastWasNegative = false; for (int x : queue) { if ((x-frame)<0) { if (lastWasNegative) queue.removeFirst(); lastWasNegative = true; } else break; } if (queue.isEmpty()) queue.addLast(0); int last = queue.getLast(); while (last-frame < width) { last += random(width/5) + width/20; queue.addLast(last); } } }