Mathematics, Waves, Sin, Cos, Angles and HTML5

Get help using Construct 2

Post » Sun Nov 10, 2013 11:08 pm

Thank you @mindfaQ
That is exactly what I was talking about.

@Heptagono
mindfaQ's example might need some explanation for your understanding. 'Amplitude' is Y and 'Period' (or Frequency) is what you called 'distance pp' in your graphic.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Sun Nov 10, 2013 11:15 pm

Wonderful solution!

Now I can see that the appoach that I was using was not the best way to pick up a proper result. I'm goint to test It and tell you how it has been.

Thanks and cheers!
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Sun Nov 10, 2013 11:29 pm

I probably use too many points with rising new_period. I think canvas.width*newperiod/4 or even /8 will be enough and stay fast enough if the new_period number gets large. Also what I called period in my example is the frequency instead of period in (sinwaves/360 pixel) as unit.

and instead of adding sin to y, substract it, as it should point upwards when sin is 1, not downwardsmindfaQ2013-11-10 23:38:13
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Thu Nov 21, 2013 9:08 pm

mindfaQ, there is something that I want to ask you.

Can I use an Amplitude and a Period value to draw a wave with the code you have showed me?

B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Thu Nov 21, 2013 9:13 pm

Not sure what you mean with that. The code already does that, no? The slider is not a necessity.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Thu Nov 21, 2013 10:31 pm

I did a vey easy approach the other day

[QUOTE=lennaert] :)

web example


capx


Manipulate magnitude from sine when needed ;)[/QUOTE]
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Sat Nov 23, 2013 10:23 pm

[QUOTE=mindfaQ] Not sure what you mean with that. The code already does that, no? The slider is not a necessity.[/QUOTE]

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.
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Sun Nov 24, 2013 2:30 am

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.

mindfaQ2013-11-24 02:31:07
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Mon Nov 25, 2013 5:31 pm

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?
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Previous

Return to How do I....?

Who is online

Users browsing this forum: ametueraspirant, mickclarke and 30 guests