Skip to content

Instantly share code, notes, and snippets.

@vonWolfehaus
Created February 2, 2013 03:49
Show Gist options
  • Save vonWolfehaus/4696043 to your computer and use it in GitHub Desktop.
Save vonWolfehaus/4696043 to your computer and use it in GitHub Desktop.
Create a sine-based "hill" with configurable parameters.
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