Skip to content

Instantly share code, notes, and snippets.

@martian17
Created February 1, 2023 06:24
Show Gist options
  • Save martian17/23853572d3cfd736abdae7efc02a4283 to your computer and use it in GitHub Desktop.
Save martian17/23853572d3cfd736abdae7efc02a4283 to your computer and use it in GitHub Desktop.
territorial.io tool
let canvas = document.querySelector("canvas");
let ctx = canvas.getContext("2d");
let display = document.createElement("canvas");
document.body.appendChild(display);
display.style.zIndex = "1000";
display.style.position = "absolute";
display.style.bottom = "0px";
display.style.right = "0px";
display.style.pointerEvents = "none";
display.width = canvas.width/4;
display.height = canvas.height/4;
let dctx = display.getContext("2d");
let kkk = true;
let multiplier = 1;
while(kkk){
display.width = canvas.width/multiplier;
display.height = canvas.height/multiplier;
let dd = dctx.getImageData(0,0,display.width,display.height);
let ddata = dd.data;
let imgdata = ctx.getImageData(0,0,canvas.width,canvas.height);
let data = imgdata.data;
for(let y = 0; y < dd.height; y++){
for(let x = 0; x < dd.width; x++){
let y2 = y*multiplier;
let x2 = x*multiplier;
if(y2 >= imgdata.height)y2 = imgdata.height-1;
if(x2 >= imgdata.width)x2 = imgdata.width-1;
let idx = (y*dd.width+x)*4;
let idx2 = (y2*imgdata.width+x2)*4;
if(data[idx2+1] > 80){
ddata[idx+0] = 0;
ddata[idx+1] = 255;
ddata[idx+2] = 0;
ddata[idx+3] = 255;
}else{
ddata[idx+0] = data[idx2+0];
ddata[idx+1] = data[idx2+1];
ddata[idx+2] = data[idx2+2];
ddata[idx+3] = data[idx2+3];
}
}
}
dctx.putImageData(dd,0,0);
await new Promise(res=>setTimeout(res,100));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment