Created
August 7, 2014 05:47
-
-
Save Snack-X/4b9b286e9c276b11d7dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>35569</title> | |
</head> | |
<body> | |
<canvas id="cv"></canvas> | |
<script src="script.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Math.cos(x & y) << 16; | |
} | |
function green(x, y) { | |
return red(DIM - x, DIM - y); | |
} | |
function blue(x, y) { | |
return Math.tan(x ^ y) << 8; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment