...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
float[] rawData; void setup() { size(1400, 800); rawData = randomData(128); } void draw() { float interval = map(mouseX, 0, width, 0, 1); float timeConstant = map(mouseY, 0, height, 0, 1); float[] lowPassed = lowPass(rawData, interval, timeConstant); background(0); drawLine(rawData, color(127)); drawLine(lowPassed, color(255, 255, 0)); } float[] randomData(int size) { float[] data = new float[size]; for(int i=0; i < data.length; i++) { data[i] = noise(i); } return data; } void drawLine(float[] data, color c) { noFill(); stroke(c); beginShape(); for (int i=0; i < data.length; i++) { vertex(map(i, 0, data.length, 0, width), map(data[i], 0, 1, 0, height)); } endShape(); } float[] lowPass(float[] in, float interval, float timeConstant) { float[] out = new float[in.length]; float alpha = interval / (timeConstant + interval); out[0] = in[0]; for (int i=1; i < in.length; i++) { out[i] = alpha * in[i] + (1 - alpha) * out[i-1]; } return out; } |
...