Created
February 2, 2013 03:49
-
-
Save vonWolfehaus/4696043 to your computer and use it in GitHub Desktop.
Create a sine-based "hill" with configurable parameters.
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
var ctx = canvas.getContext('2d'); | |
var iterations = 15, | |
moveX = 10, | |
amp = 80, | |
startX = 200, startY = 200, | |
i, rad, ny; | |
ctx.beginPath(); | |
ctx.moveTo(startX, startY); | |
for (i = 1; i <= iterations; i++) { | |
rad = Math.PI/iterations * i; | |
ny = Math.sin(rad) * -amp; | |
ctx.lineTo(startX + moveX*i, startY + ny); | |
} | |
ctx.stroke(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment