Created
July 1, 2015 16:47
-
-
Save mathdoodle/375ec2bb01fb4bfd41c2 to your computer and use it in GitHub Desktop.
Random Checkerboard
This file contains hidden or 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
{ | |
"uuid": "9e6e8852-6006-4122-99ba-4d0306f44abc", | |
"description": "Random Checkerboard", | |
"dependencies": { | |
"DomReady": "latest" | |
}, | |
"operatorOverloading": true | |
} |
This file contains hidden or 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> | |
<title>Vector graphics with canvas</title> | |
<style> | |
/* STYLE-MARKER */ | |
</style> | |
<!-- SCRIPTS-MARKER --> | |
</head> | |
<body> | |
<canvas id='canvas' width='900' height='700'></canvas> | |
<script> | |
// CODE-MARKER | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
DomReady.ready(load); | |
/** | |
* The handler function to be called at the end of the document loading process. | |
* @param ev The `load` event. | |
*/ | |
function load() { | |
var canvas = <HTMLCanvasElement>document.getElementById('canvas'); | |
canvas.height = 700; | |
canvas.width = 900; | |
var ctx: CanvasRenderingContext2D = canvas.getContext('2d'); | |
var size = 100; | |
for (var i=0; i<9; i++) { | |
for (var j=0; j<7; j++) { | |
var x = Math.random() * 9; | |
if (x > 2) { | |
ctx.fillStyle = 'rgb(' + 100 + ',' + 100 + ',100)'; | |
} | |
else { | |
ctx.fillStyle = 'rgb(' + 200 + ',' + 200 + ',200)'; | |
} | |
ctx.fillRect(i*size,j*size,size,size); | |
} | |
} | |
} |
This file contains hidden or 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
#doodle1 { | |
position: absolute; | |
background-color: #cccccc; | |
width: 900px; | |
height: 700px; | |
top: 150px; | |
left: 400px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment