Skip to content

Instantly share code, notes, and snippets.

@Snack-X
Created August 5, 2014 03:53
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 Snack-X/906e6d962c93293e2771 to your computer and use it in GitHub Desktop.
Save Snack-X/906e6d962c93293e2771 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>35569</title>
</head>
<body>
<canvas id="cv"></canvas>
<script src="script.js"></script>
</body>
</html>
var DIM = 1024;
var DM1 = DIM - 1;
var _sq = function(x) { return x * x; };
var _cb = function(x) { Math.abs(x * x * x); };
var _cr = function(x) { Math.pow(x, 1 / 3); };
var cv = document.getElementById("cv");
cv.width = DIM;
cv.height = DIM;
cv.style.position = "fixed";
cv.style.left = "0px";
cv.style.top = "0px";
document.body.appendChild(cv);
var ctx = cv.getContext("2d");
var image_data = ctx.getImageData(0, 0, DIM, DIM);
var data = image_data.data;
var x = 0, y = 0;
for(var i = 0, len = data.length ; i < len ; ) {
data[i++] = red(x, y) >> 2;
data[i++] = green(x, y) >> 2;
data[i++] = blue(x, y) >> 2;
data[i++] = 255;
if(++x === DIM) {
x = 0;
y++;
}
}
ctx.putImageData(image_data, 0, 0);
function red(x, y) {
return (x + y) & y;
}
function green(x, y) {
return (255 + x - y) & x;
}
function blue(x, y) {
return Math.pow(x, y) & y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment