xxxxxxxxxx
let screen, obj = [], inv = 0, lag = 3;
function invert(col){
if(!inv) return col;
let x = color(col), y = new Array(4);
for(let i=0; i<3; ++i)
y[i] = 255*(1-x._array[i]);
y[3] = 255*x._array[3];
return y;
}
function setup(){
createCanvas(400, 400);
screen = createGraphics(400, 400);
screen.Fill = screen.fill;
screen.fill = function(args){
screen.Fill(invert(args));
}
screen.Stroke = screen.stroke;
screen.stroke = function(args){
screen.Stroke(invert(args));
}
for(let i=0; i<5; ++i)
obj.push(new box(i));
}
function draw(){
obj.push(new snake_segment(
Math.floor(200+120*Math.cos(frameCount/50)+50*Math.sin(frameCount/50)),
Math.floor(200-120*Math.cos(frameCount/50)+50*Math.sin(frameCount/50)),
50*Math.sin(frameCount/50)
));
obj = obj.filter(o => o.d == 0 || o.d > frameCount-lag);
inv = 0;
screen.clear();
for(let o of obj)
if(o.z && o.z < 0) o.draw(0);
for(let o of obj)
if(!o.z || o.z >= 0) o.draw(0);
background(127.5);
tint(255, 255);
image(screen, 0, 0, 400, 400);
inv = 1;
screen.clear();
for(let o of obj)
if(o.z && o.z < 0) o.draw(lag);
for(let o of obj)
if(!o.z || o.z >= 0) o.draw(lag);
tint(255, 127.5);
if(!keyIsDown(32)) image(screen, 0, 0, 400, 400);
}