Skip to content

Instantly share code, notes, and snippets.

@okaq
Created November 25, 2013 01:30
Show Gist options
  • Save okaq/7634892 to your computer and use it in GitHub Desktop.
Save okaq/7634892 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head id="zeta">
<title>okaq.com/speed</title>
<script type="text/javascript">
// ok
console.log("speed ok");
// perf
window.bigtime = window.performance.timing.responseEnd - window.performance.timing.navigationStart;
window.smalltime = window.performance.timing.responseEnd - window.performance.timing.requestStart;
console.log(window.performance);
// are we still loading?
// times in ms since epoch
// load
(function() {
// var async_load = function() {
// var pt = window.performance.timing;
// window.tots = pt.loadEventEnd - pt.navigationStart;
var async_load = function() {
g.init();
}
window.addEventListener("load", async_load, false);
})();
// game
var g = {
"init": function() {
console.log("g init...");
console.log("bigtime: " + window.bigtime);
console.log("smalltime: " + window.smalltime);
c.init();
pm.init();
}
}
// pixel manipulation
var pm = {
"init": function() {
}
}
// canvas
var c = {
"init": function() {
c.can = document.getElementById("beta");
c.con = c.can.getContext("2d");
c.clear();
c.chev()
},
"chev": function() {
for (var i = 0; i < 8; i++) {
var lm = 32 * i;
var rm = c.can.width - 2 * (32 * i);
c.con.fillStyle = d.rand();
c.con.fillRect(lm, lm, rm, rm);
}
},
"clear": function() {
var bg = d.rand();
var fg = d.rand();
c.con.fillStyle = bg;
c.con.fillRect(0,0,c.can.width,c.can.height);
c.con.fillStyle = fg;
c.con.fillRect(32,32,c.can.width-64,c.can.height-64);
},
// render - type array at x,y
"render": function() {
}
}
// design
var d = {
"rand": function() {
var a0 = 0.6 + 0.4 * Math.random();
var d0 = [d.rb(), d.rb(), d.rb(), a0];
var s0 = d0.join(",");
var s1 = "rgba(" + s0 + ")";
return s1;
},
"rb": function() {
return ((Math.random() * 255) >>> 0)
}
}
// unicode
var u = {
"rand": function(lo, hi) {
// return random unicode escape string within range
// Han characters start at '\u4e00'
var d0 = (hi - lo) >>> 0;
var d1 = ((Math.random() * d0) + lo) >>> 0;
return String.fromCharCode(d1);
}
}
</script>
</head>
<body id="alpha">
<canvas id="beta" width="512" height="512"></canvas>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment