Skip to content

Instantly share code, notes, and snippets.

@tagr
Created January 23, 2015 04:17
Show Gist options
  • Save tagr/7ed4a04162d685fe4191 to your computer and use it in GitHub Desktop.
Save tagr/7ed4a04162d685fe4191 to your computer and use it in GitHub Desktop.
HTML5 Canvas Sine Plotting
canvas(id='c',width='800',height='600')
$(function() {
var canvas = $('canvas')[0],
context = canvas.getContext('2d'),
_points = 6400,
_r = 0,
_g = 0,
_b = 255,
_a = 1,
plot = function(p) {
_g = Math.floor(Math.random()*255);
_b = Math.floor(Math.random()*128+127);
context.fillStyle = 'rgba('+_r+','+_g+','+_b+','+_a+')';
context.fillRect(p/4,64/Math.sin(p)-64,2,2);
}
setInterval(function(){
var originalValue = _points;
while(_points--) plot(_points);
_points = originalValue;
},60)
});
body {
background: #000;
}
canvas {
border: 1px solid rgba(64,4,255,0.3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment