class Graph implements Drawable { int width = 250; int height = 100; int posX, posY, start, end; String title; float value; PFont font; Drawable[] hedges; boolean isOutput = false; Graph(int x, int y, String t, int s, int e) { posX = x; posY = y; title = t; start = s; end = e; value = 0.0; hedges = new Drawable[0]; font = loadFont("BitstreamVeraSans-Roman-10.vlw"); } void draw() { pushMatrix(); translate(posX, posY); fill(0); noStroke(); textFont(font); textMode(SCREEN); text(title + ": " + value, posX, posY-2); if (!isOutput) fill(200, 200); if (isOutput) fill(143, 165, 211, 200); stroke(0); rect(0, 0, width, height); for(int i = 0; i < hedges.length; i++) { hedges[i].draw(); } noFill(); stroke(255, 0, 0); beginShape(); vertex(map(constrain(value, start, end), start, end, 0, width), height); vertex(map(constrain(value, start, end), start, end, 0, width), 0); endShape(); noStroke(); popMatrix(); } void setValue(float val) { value = val; } void addHedge(int a, int b, int c, int d) { hedges = (Drawable[]) append(hedges, new Hedge(a, b, c, d)); } class Hedge implements Drawable { int a, b, c, d; Hedge(int a, int b, int c, int d) { this.a = a; this.b = b; this.c = c; this.d = d; } void draw() { stroke(0, 0, 200); noFill(); beginShape(); vertex(map(constrain(a, start, end), start, end, 0, width), height); vertex(map(constrain(b, start, end), start, end, 0, width), 0); vertex(map(constrain(c, start, end), start, end, 0, width), 0); vertex(map(constrain(d, start, end), start, end, 0, width), height); endShape(); noStroke(); } } }