I have a function that draw functions in processing.js like this:
var plot_line = function(x1, y1, x2, y2) {
line(x1+200, -y1+200, x2+200, -y2+200);
};
var plot = function (f, scale) {
scale = scale || 1;
for (var x=-200; x<200; x++) {
var y1 = f(x/scale)*scale;
var y2 = f((x+1)/scale)*scale;
plot_line(x, y1, x+1, y2);
}
};
but the function fail if I call plot(Math.tan, 20);
because the function have Asymptotes, the ouput look like this:
Is it possible to have generic draw function that will work for functions like tangens?
Here is a demo the output should look like on google (without vertial lines where there are Asymptotes)