Learning canvas. Just plotting points :)
Created
January 23, 2015 04:17
-
-
Save tagr/7ed4a04162d685fe4191 to your computer and use it in GitHub Desktop.
HTML5 Canvas Sine Plotting
This file contains 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
canvas(id='c',width='800',height='600') |
This file contains 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() { | |
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) | |
}); |
This file contains 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
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