math - sine wave drawing using JavaScript -


I am working on creating a simple ice simulation, but I have been very unsuccessful on mathematics. Basically, when a snowflake is started, this position is set somewhere on the STVG canvas. Then from there, it falls straight down, it should be a simulation of a sine wave (x coordinate should grow like a sine wave)

I have not triggered from last year, so I'm a little confused . Math.sin () takes radians, which I believe, then multiply by 180, then divide Pi to convert from degree?

Let's say X Snow is the current X position, and the width is the width of the canvas.

  x + = (sin ((x / width) * (180 / Math.PI))) * width)   

this works , But it's everywhere. I am doing what I am doing, it is a vague idea, but I can not seem to push mathematics into the code from my mind.

What am I doing wrong?

should be:

  x + = A * Math. Sin (F * (y / height) * 2 * Math.PI);   

Where A is the dimension, that is how many pixels you want that you move the layer left and right (note that the total change will be 2 * A). F is the frequency, or how often you want to move the layer left and right (I want it to be set between randomly between 2 and 10 for every layer).

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -