Created
July 16, 2012 11:54
-
-
Save paranoiq/3122289 to your computer and use it in GitHub Desktop.
Blikátko
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> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<title>Blikátko simulátor</title> | |
</head> | |
<body> | |
<style> | |
html, body { margin: 0; padding: 0; } | |
</style> | |
<canvas id='canvas' width=1600 height=794></canvas> | |
<script> | |
var cavas = document.getElementById('canvas'); | |
var c = canvas.getContext('2d'); | |
var timer = 0 | |
var r = 128; | |
var g = 128; | |
var b = 128; | |
var left = 0; | |
function init() { | |
timer = Math.round(Math.random() * 256); | |
r = Math.round(Math.random() * 256); | |
g = Math.round(Math.random() * 256); | |
b = Math.round(Math.random() * 256); | |
update(); | |
} | |
function update() { | |
timer--; | |
if (timer < 1) { | |
init(); | |
return; | |
} | |
var x = 12; | |
r = r + Math.round(Math.random() * x - x/2); | |
g = g + Math.round(Math.random() * x - x/2); | |
b = b + Math.round(Math.random() * x - x/2); | |
if (r < 0) r = 192; | |
if (g < 0) g = 192; | |
if (b < 0) b = 192; | |
if (r > 255) r = 64; | |
if (g > 255) g = 64; | |
if (b > 255) b = 64; | |
//* barva | |
c.fillStyle = 'rgb(' + r + ', ' + g + ', ' + b + ')'; | |
c.fillRect(0, 128, 1600, 794); | |
//*/ | |
//* graf | |
left++; | |
if (left > 1580) { | |
c.fillStyle = '#FFF'; | |
c.fillRect(0, 0, 1600, 128); | |
left = 0; | |
} | |
c.fillStyle = '#F00'; | |
c.fillRect(left, r/2, 1, 1); | |
c.fillStyle = '#0C0'; | |
c.fillRect(left, g/2, 1, 1); | |
c.fillStyle = '#00F'; | |
c.fillRect(left, b/2, 1, 1); | |
//*/ | |
setTimeout(update, 20); | |
} | |
init(); | |
</script> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment