Mathematics, Waves, Sin, Cos, Angles and HTML5

Get help using Construct 2

Post » Sun Nov 10, 2013 5:02 pm

Hi Everybody,

I ask for the communty help, especially to those stronger in mathematics to solve a problem:

I've making tests in a program that should be able to represent in real time a sinus wave depending on a slider value. The idea is to have something similar to a Osciloscope made with a canvas plugin.

https://dl.dropboxusercontent.com/u/87172782/test.JPG

So that I try to do so and, as you can see in the example, I'm just near to pick up a solution, but not completely. The line represented in the canvas is not responding to the changes made on the slider. It only takes the initial values of X and Y.

The aim would be to make possible to represent a y=cos(x) for example, where X is given by the slider.

Here you would find an image and a example.

https://dl.dropboxusercontent.com/u/87172782/test.capx

Any idea or comment? Is my approach to the solution a good one? Perhaps it is not possible to be done with a canvas plugin?Heptagono2013-11-10 21:59:46
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Sun Nov 10, 2013 5:31 pm

If you try to do something similar to this, it is totally possible and relatively easy as well. The link leads to an app I once made with CC, but the graphic representation was done with the canvas plugin, and nothing else was used than "line to". Both is also available in C2 using ROJOhound's Canvas plugin for C2.
The basic approach of drawing a waveform (be it a sinus or anything else) is to split it into segments, tiny parts of the complete wave. Those segments represent the resolution, the wave is drawn at.
If you are not afraid of installing CC, I could give you the source the the link above. But maybe somebody else already working on a demo for C2
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Sun Nov 10, 2013 5:33 pm

You are setting Y to a constant: 4*cos(3.141516)^2
It needs to be a function of X, something like: 4*cos(X * _yourfrequencyvalue_)^2
ImageImageImage
B
71
S
22
G
240
Posts: 3,732
Reputation: 133,990

Post » Sun Nov 10, 2013 6:45 pm

wouldn't using the curve feature in the canvas plugin be easier?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Nov 10, 2013 6:47 pm

I haven't loaded your example but if blackhornet copied from your event:??Doesn't Construct 2 use degree instead of radian in sin()???Also better use pi instead of 3.141516
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 » Sun Nov 10, 2013 9:43 pm

Wow! That too much of course. But this is the kind of control of the waves that I seek in my app.

What I do is
            Every tick

                  -----> Loop For 1 to BoxBound : Drawing the points.

The problem is this only represents the first values, no changes.

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

Post » Sun Nov 10, 2013 9:44 pm

Y is a constant in the example.

Oh, I'm going to change this inmediately
Heptagono2013-11-10 21:45:02
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Sun Nov 10, 2013 9:45 pm

[QUOTE=LittleStain] wouldn't using the curve feature in the canvas plugin be easier?[/QUOTE]

I have never used it before, I'll check it out
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Sun Nov 10, 2013 10:01 pm

Here you can find the project in it's last state:

https://dl.dropboxusercontent.com/u/87172782/test.capx ][/URL]

As you can see, the problem is that it seems no way to represent the changes in real time
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Sun Nov 10, 2013 10:59 pm

easy with the canvas plugin:


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

Next

Return to How do I....?

Who is online

Users browsing this forum: adventurist, Blendi1223, PROxMTswatTR, ST314, Yahoo [Bot] and 19 guests