Skip to content

Instantly share code, notes, and snippets.

@ahvonenj
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save ahvonenj/776e95bb5572728d6d76 to your computer and use it in GitHub Desktop.

Select an option

Save ahvonenj/776e95bb5572728d6d76 to your computer and use it in GitHub Desktop.
Vertical sine wave
// Result: http://puu.sh/j19yl/d37b20ff08.png
this.position =
{
x: self.vpc.x + Math.cos(time * 0.002) * this.helpers.sineBetween(-200, 200, time * 0.02),
y: self.vpc.y + Math.sin(time * 0.002) * this.helpers.sineBetween(200, 200, time * 0.02)
}
this.viewportsize = viewportsize;
this.vpc = { x: this.viewportsize.w / 2, y: this.viewportsize.h / 2 }; // Viewportcenter
this.helpers =
{
sineBetween: function(min, max, t)
{
var halfRange = (max - min) / 2;
return min + halfRange + Math.sin(t) * halfRange;
},
cosineBetween: function(min, max, t)
{
var halfRange = (max - min) / 2;
return min + halfRange + Math.cos(t) * halfRange;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment