Skip to content

Instantly share code, notes, and snippets.

@Saren-Arterius
Created March 10, 2021 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Saren-Arterius/547481edb7a34b5ff7ad8865afa286dd to your computer and use it in GitHub Desktop.
Save Saren-Arterius/547481edb7a34b5ff7ad8865afa286dd to your computer and use it in GitHub Desktop.
let cache = {};
let fuck = (canvas) => {
let key = `${canvas.width},${canvas.height}`;
let ar = cache[key];
if (!ar) {
ar = [];
for (let i = 0; i < 1000; i++) {
let pixel = {
x: Math.round(canvas.width * Math.random()),
y: Math.round(canvas.height * Math.random()),
rgba: [Math.random() * 255, Math.random() * 255, Math.random() * 255, 255]
};
ar.push(pixel);
}
cache[key] = ar;
}
let ctx = canvas.getContext("2d");
let id = ctx.createImageData(1, 1);
for (let pixel of ar) {
let d = id.data;
for (let i = 0; i < pixel.rgba.length; i++) {
d[i] = pixel.rgba[i];
}
ctx.putImageData(id, pixel.x, pixel.y);
}
console.log(`Fucked with canvas: width=${canvas.width} height=${canvas.height}`);
};
(function(toDataURL) {
HTMLCanvasElement.prototype.toDataURL = function() {
let ctx = this.getContext("2d");
let data;
if (ctx) {
fuck(this);
data = toDataURL.apply(this, arguments);
}
let gl = this.getContext("webgl");
if (gl) {
let tmpCanvas = document.createElement('canvas');
tmpCanvas.width = this.width;
tmpCanvas.height = this.height;
tmpCanvas.getContext('2d').drawImage(this, 0, 0);
fuck(tmpCanvas);
data = toDataURL.apply(tmpCanvas, arguments);
}
console.log(data);
return data;
};
})(HTMLCanvasElement.prototype.toDataURL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment