Skip to content

Instantly share code, notes, and snippets.

@volkanozcan
Created August 10, 2015 20:54
Show Gist options
  • Save volkanozcan/40db6a7a276a30ce9cb4 to your computer and use it in GitHub Desktop.
Save volkanozcan/40db6a7a276a30ce9cb4 to your computer and use it in GitHub Desktop.
Color Embraced
<canvas id="canv" width="32" height="32">
var c = document.getElementById('canv');
var $ = c.getContext('2d');
var col = function(x, y, r, g, b) {
$.fillStyle = "rgb(" + r + "," + g + "," + b + ")";
$.fillRect(x, y, 1,1);
}
var R = function(x, y, t) {
return( Math.floor(192 + 64*Math.cos( (x*x-y*y)/300 + t )) );
}
var G = function(x, y, t) {
return( Math.floor(192 + 64*Math.sin( (x*x*Math.cos(t/4)+y*y*Math.sin(t/3))/300 ) ) );
}
var B = function(x, y, t) {
return( Math.floor(192 + 64*Math.sin( 5*Math.sin(t/9) + ((x-100)*(x-100)+(y-100)*(y-100))/1100) ));
}
var t = 0;
var run = function() {
for(x=0;x<=35;x++) {
for(y=0;y<=35;y++) {
col(x, y, R(x,y,t), G(x,y,t), B(x,y,t));
}
}
t = t + 0.10;
window.requestAnimationFrame(run);
}
run();
body {
width: 100%;
margin: 0;
overflow: hidden;
}
canvas {
width: 100%;
height: 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment