Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<!DOCTYPE html>
<html>
<head><title>ChamberedTest</title></head>
<script type="text/javascript" src="js/chambered.js"></script>
<style type="text/css">
canvas, img {
image-rendering: optimizeSpeed;
image-rendering: -moz-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: optimize-contrast;
-ms-interpolation-mode: nearest-neighbor;
width:848px;
height:480px;
}
</style>
<body>
<canvas id="game" width="424" height="240"></canvas>
<script type="text/javascript">
var ctx;
var pixels;
var w = 212;
var h = 120;
var map = new Array(64 * 64 * 64);
var texmap = new Array(16 * 16 * 3 * 16);
function init() {
ctx = document.getElementById('game').getContext('2d');
for ( var x = 0; x < 64; x++) {
for ( var y = 0; y < 64; y++) {
for ( var z = 0; z < 64; z++) {
var i = z << 12 | y << 6 | x;
var yd = (y - 32.5) * 0.4;
var zd = (z - 32.5) * 0.4;
map[i] = (Math.random() * 16) | 0;
if (Math.random() > Math.sqrt(Math.sqrt(yd * yd + zd * zd)) - 0.8)
map[i] = 0;
}
}
}
pixels = ctx.createImageData(w, h);
for ( var i = 0; i < w * h; i++) {
pixels.data[i * 4 + 3] = 255;
}
setInterval(clock, 1000 / 100);
};
function clock() {
renderMinecraft();
ctx.putImageData(pixels, 0, 0);
};
var f = 0;
function renderMinecraft() {
var ox = 32.5 + Date.now() % 10000 / 10000 * 64;
var oy = 32.5;
var oz = 32.5;
f++;
for ( var x = 0; x < w; x++) {
var worldxd = (x - w / 2) / h;
for ( var y = 0; y < h; y++) {
var worldyd = (y - h / 2) / h;
var worldzd = 1;
var ___zd = worldzd;
var rotyd = worldyd;
var rotxd = ___zd;
var rotzd = worldxd;
var col = 0;
var br = 255;
var ddist = 0;
var closest = 32;
for ( var d = 0; d < 3; d++) {
var dimLength;
if (d == 0) dimLength = rotxd;
if (d == 1) dimLength = rotyd;
if (d == 2) dimLength = rotzd;
var ll = 1 / Math.abs(dimLength);
var xd = (rotxd) * ll;
var yd = (rotyd) * ll;
var zd = (rotzd) * ll;
var initial;
if (d == 0) initial = ox - Math.floor(ox);
if (d == 1) initial = oy - Math.floor(oy);
if (d == 2) initial = oz - Math.floor(oz);
if (dimLength > 0) initial = 1 - initial;
var dist = ll * initial;
var xp = ox + xd * initial;
var yp = oy + yd * initial;
var zp = oz + zd * initial;
if (dimLength < 0) {
if (d == 0) xp--;
if (d == 1) yp--;
if (d == 2) zp--;
}
while (dist < closest) {
var tex = map[(zp & 63) << 12 | (yp & 63) << 6 | (xp & 63)];
if (tex > 0) {
col = 255+ (255<<8) + (255<<16);
ddist = 255 - ((dist / 32 * 255) | 0);
br = 255 * (255 - ((d + 2) % 3) * 50) / 255;
closest = dist;
}
xp += xd;
yp += yd;
zp += zd;
dist += ll;
}
}
var r = ((col >> 16) & 0xff) * br * ddist / (255 * 255);
var g = ((col >> 8) & 0xff) * br * ddist / (255 * 255);
var b = ((col) & 0xff) * br * ddist / (255 * 255);
pixels.data[(x + y * w) * 4 + 0] = r;
pixels.data[(x + y * w) * 4 + 1] = g;
pixels.data[(x + y * w) * 4 + 2] = b;
}
}
}
init();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.