xxxxxxxxxx
35
let draw_wave = function() {
let history = [];
let width = 400;
let zero_line = 200;
let amplitude = 100;
let margins = 50;
let graph_step = 1;
let time_step = 1;
let memory = (width - 2 * margins) / graph_step;
let t = 0;
return function() {
t = (1 + 20*t) / (20 - t);
let ft = amplitude * 2*t / (1+t*t);
history.push(zero_line + ft);
if(history.length > memory) {
history.shift();
}
beginShape();
for(let x = 0; x < history.length; ++x) {
vertex(x*graph_step + margins, history[x]);
}
endShape();
}
}();
function setup() {
createCanvas(400, 400);
noFill();
}
function draw() {
background(220);
draw_wave();
}