Mathematics, Waves, Sin, Cos, Angles and HTML5

0 favourites
From the Asset Store
Waves SFX Sea & Ocean contains 170 seamless loops.
  • I did a vey easy approach the other day

    :)

    web example

    capx

    Manipulate magnitude from sine when needed ;)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Not sure what you mean with that. The code already does that, no? The slider is not a necessity.

    Ok, I've worked out a better explanation for this:

    Well, I mean that if we have two formulas to pick up the value of Amplitude and Period, let's say the ones I'm trying to implement:

    Amplitude: 4 * cos^2(Pi*X/Period)

    Period: Omega * Distance1 / 2 * Factor

    Omega and Factor are given by two sliders.

    They result in two real values, if they are introduced as variables in Draw Line:

    Having a sinus in the Y term, we can find ourselves with a wave that doesn't depicts the numbers from our mathematical formulae.

    That's the issue. I Hope this has been clearer. Tell me what do you think.

  • Period: Distance1 is a constant I suppose? Period should calculate just fine imo.

    Amplitude: What is x? also note that construct uses degrees instead of radian, so you probably want to use 180 instead of p. Also you need to place the ^2 after the brackets. Also you need to calculate the period before amplitude in the event sheet (just put the period calculation above the amplitude calculation), so that you use the current period for your calculation.

    To make the drawing formula more clear (I suppose distance1 is the width of your graph):

    for 1 to distance1: canvas line to: x = loopindex+startx; y = sin(loopindex*360/period)*amplitude+starty

    period then would be the amount of pixels it takes to run through a full circle.

  • Hi mindfaQ,

    I've prepared this clear version of the test. Below the waves box you will see a black box, which is aimed to represent a pattern of vertical lines with different color values, from white to black, depending on the point of the wave represented alog the x axis: maximum point white, minimum point black.

    The x represents in the formula the whole lenght of the box, although I suspect it's aimed to be used only to show a point. If so, I fear all this effort could be in the wrong direction.

    By now, the version of the proyect is here:

    Test.capx

    What do you think?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)