Skip to content

Instantly share code, notes, and snippets.

@Snack-X
Last active August 29, 2015 14:04
Show Gist options
  • Save Snack-X/9aca1f31b51b7e128741 to your computer and use it in GitHub Desktop.
Save Snack-X/9aca1f31b51b7e128741 to your computer and use it in GitHub Desktop.
codegolf SE 33569 - try 1
<!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 SIZE = 1024;
var cv = document.getElementById("cv");
cv.width = SIZE;
cv.height = SIZE;
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, SIZE, SIZE);
var data = image_data.data;
var x = 0, y = 0;
for(var i = 0, len = data.length ; i < len ; ) {
data[i++] = red(x, y) & 255;
data[i++] = green(x, y) & 255;
data[i++] = blue(x, y) & 255;
data[i++] = 255;
if(++x === SIZE) {
x = 0;
y++;
}
}
ctx.putImageData(image_data, 0, 0);
function red(x, y) {
return x + y;
}
function green(x, y) {
return 256 + x - y;
}
function blue(x, y) {
return x * y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment