xxxxxxxxxx
var o = {};
const scl = {
x : 1/50,
y : -1/50
};
const grid = {
x : 10,
y : 10
}
const pixelmax = 100;
const poly = [1,-1,1,0,0,1];
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
o.x = windowWidth/2;
o.y = windowHeight/2;
rectMode(CORNERS);
}
function draw() {
for (var cx = 0; x < windowHeight; x++) {
for (var cy = 0; y < windowHeight; y++) {
var z = cmake( (x-o.x)*scl.x, (y-o.y)*scl.y);
var p = polyeval(z, poly);
colorcell(cx, cy, pixelmap(p));
}
}
}
function polyeval(x, poly) { //evaluate coefs[i]*X^i at x
t = 1;
z = 0;
for (var coef of poly) {
z += t*coef;
t *= x;
}
return z;
}
function cmult(a,b) { //complex multiplication
return cmake(a.r+b.r-b.i*b.i, a.r*b.i + a.i*b.r);
}
function cmake(r,i) {
return {r: r, i: i};
}
function gridfloor(cx,cy) {
return Math.floor((x-o.x)/grid.x), Math.floor((y-o.y)/grid.y);
}
function colorcell(cx, cy, color) {
push();
fill(color);
rect(cx*grid.x, cy*grid, (cx+1)*grid.x, (cy+1)*grid.y);
pop();
}
function pixelmap(p) {
p = abs(p)
if (p>=pixelmax) return 255;
else return (p/pixelmax*256);
}