Last active
December 23, 2015 00:19
-
-
Save evitolins/6552508 to your computer and use it in GitHub Desktop.
Create random colored squares... marginally useful.
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
function getRandomInt(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
// Build Canvas | |
var canvas = document.createElement('canvas'), | |
ctx = canvas.getContext('2d'), | |
w = canvas.width, | |
h = canvas.height, | |
// Generate Random Rectangle | |
ww = getRandomInt(20, w), | |
hh = getRandomInt(20, h), | |
xx = getRandomInt(0, w/2), | |
yy = getRandomInt(0, h/2), | |
c = ["blue","yellow", "green", "orange", "purple", "red", "grey", "brown", "white"]; | |
// Render Random Content | |
ctx.rect(xx, yy, ww, hh); | |
ctx.fillStyle = c[ getRandomInt (0, c.length - 1)]; | |
ctx.fill(); | |
document.body.appendChild(canvas); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment