Skip to content

Instantly share code, notes, and snippets.

@sergelerner
Last active August 29, 2015 14:15
Show Gist options
  • Save sergelerner/dbc1ee2d1db0a4da5f94 to your computer and use it in GitHub Desktop.
Save sergelerner/dbc1ee2d1db0a4da5f94 to your computer and use it in GitHub Desktop.
Canvas Sin Wave
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<style>
canvas {
display: block;
}
</style>
<script src="script.js"></script>
</head>
<body>
<canvas id="canvas"></canvas>
</body>
</html>
window.onload = function() {
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
width = canvas.width = window.innerWidth,
height = canvas.height = window.innerHeight;
context.translate(0, height/2);
context.scale(1, -1);
for (var angle = 0; angle < Math.PI * 2; angle += .1) {
var x = angle * 100,
y = Math.sin(angle) * 200;
context.fillRect(x, y, 5, 5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment