public class LGraph { private ParamSet p; public int xPos; public int yPos; public int w; public int h; private int spacing = 8; private float[] seq; private int xPoints; private int seqPos; private float pop; private PImage bgSaved; public LGraph(int xPos, int yPos, int w, int h) { this.xPos = xPos; this.yPos = yPos; this.w = w; this.h = h; this.p = p; xPoints = floor(w/spacing) + 1; seq = new float[xPoints]; seqPos = 0; bgSaved = null; } public void setP(ParamSet p) { this.p = p; } private void genSeq() { float r = p.rCurrent; pop = p.pInit; for(seqPos = 0; seqPos < xPoints; seqPos++) { pop = logistic(r, pop); seq[seqPos] = pop; } } public void update() { genSeq(); } public void clear() { fill(218); stroke(0); rect(xPos, yPos, w, h); seqPos = 0; pop = seq[0]; } public void saveBG(color c) { render(c); bgSaved = get(xPos, yPos, w, h); } public void render() { render(lineRed); } public void render(color c) { // Smooth and clear, baby smooth(); clear(); // Restore graphs from saved values of r, if any exist if(bgSaved != null) image(bgSaved, xPos, yPos); // Deal with positioning pushMatrix(); translate(xPos, yPos); float lastX = 0; float lastY = h; float pRng = p.pMax - p.pMin; stroke(c); for(int i = 0; i < seq.length; i++) { float x = i * spacing; float y = (h - (seq[i] - p.pMin) / pRng * (h-1)); line(lastX, lastY, x, y); lastX = x; lastY = y; } popMatrix(); } public float next() { pop = logistic(p.rCurrent, pop); seqPos++; return pop; } }