Wave lines

W

Wild_West

Guest
Is there any way to make a "wiggle" pattern using draw_line so it looks like a wave frequency?
 

NightFrost

Member
No, if you want to draw curves you have to construct them out of multiple line sections. A sine wave would be pretty simple, but something like bezier curves would need more math.
 
W

Wild_West

Guest
No, if you want to draw curves you have to construct them out of multiple line sections. A sine wave would be pretty simple, but something like bezier curves would need more math.
Okay, I'll look into it, thanks.
 

Yal

🐧 *penguin noises*
GMC Elder
In case you're wondering, the general equation of a point on a wave is

y = amplitude*sin(W*time + K*x)

where W is the wave frequency (the speed the wave undulates with) and K is the speed the wave itself is moving (and x is the coordinate along the direction the wave is moving in). Basically try out some different values and see whether it's working / looking well or not, but if you use that formula to compute the coordinates it will look like a wave.
 
W

Wild_West

Guest
In case you're wondering, the general equation of a point on a wave is

y = amplitude*sin(W*time + K*x)

where W is the wave frequency (the speed the wave undulates with) and K is the speed the wave itself is moving (and x is the coordinate along the direction the wave is moving in). Basically try out some different values and see whether it's working / looking well or not, but if you use that formula to compute the coordinates it will look like a wave.
I'm so rubbish at maths so that helps a lot, thanks. ^^;
 
D

Deleted member 13992

Guest
Another consideration is what is it exactly you're trying to achieve? If it's a wave for some electrical/measuring instrument, then the sine wave is fine. But if it's for a display that visualizes voice, then a sine is not the way to go, and you may want to consider animating it by hand instead.

Just my $0.02
 

sp202

Member
@muki All waves are combinations of sine waves with different amplitudes and frequencies. In fact, you can make any shape using a combination of sine waves.
 
D

Deleted member 13992

Guest
@muki All waves are combinations of sine waves with different amplitudes and frequencies. In fact, you can make any shape using a combination of sine waves.
This is true, but sometimes animating 6 frames of a wiggle can be far easier than coding an FM/AM synthesizer with wave visualization. ;)

It depends on the OP's needs of course.
 
W

Wild_West

Guest
This is true, but sometimes animating 6 frames of a wiggle can be far easier than coding an FM/AM synthesizer with wave visualization. ;)

It depends on the OP's needs of course.
Yeah I mean that's what I WAS gonna do, is try to simulate a wave that the player can manipulate for the sake of having to make both waves the same frequency, triggering a locking object to UNlock.
If you've ever seen the game Doctor who the eternity clock, they had a mini game type of locking thing just like that.
 

Yal

🐧 *penguin noises*
GMC Elder
Then the wave equation should be more or less exactly what you need... have both the target and player-affected wave have the same of everything except W, and then have input alter W. (Since that's the wave frequency it's a frequency, y'know). When the player makes the W equal to the target wave, the waves will overlap perfectly. (x and t are variables here, where x is the position on the 'screen' and t is the time, both of which would be the same for each point of both of the waves since they're drawn over the same region and time flows at the same speed for everything in your game, basically)
 

Zerb Games

Member
Not using draw_line. Anyways I would look into sine waves. Essentially the sin of an increasing number will result in a wave that ossilates between 0 and 1. Then you can manipulate that how you wish.


Some psuedo-code:
Code:
for(var i = 0; i > 360; i++)
{
draw_line(i*2,16+dsin(i)*16,i*2+2,16+dsin(inc_num+1)*16)
}

https://drive.google.com/file/d/0BxPYaBbqcCwPYlhtOXZQQjF5MkU/view?usp=sharing
Here's a little demo I made for my class. It's made entirely in GM.

I'm almost entirely self taught, so when I learned about this years ago I used Kahn Accademy https://www.khanacademy.org/math/trigonometry/trigonometry-right-triangles
 
W

Wild_West

Guest
Not using draw_line. Anyways I would look into sine waves. Essentially the sin of an increasing number will result in a wave that ossilates between 0 and 1. Then you can manipulate that how you wish.


Some psuedo-code:
Code:
for(var i = 0; i > 360; i++)
{
draw_line(i*2,16+dsin(i)*16,i*2+2,16+dsin(inc_num+1)*16)
}

https://drive.google.com/file/d/0BxPYaBbqcCwPYlhtOXZQQjF5MkU/view?usp=sharing
Here's a little demo I made for my class. It's made entirely in GM.

I'm almost entirely self taught, so when I learned about this years ago I used Kahn Accademy https://www.khanacademy.org/math/trigonometry/trigonometry-right-triangles
I actually did see those images from videos I watched looking up more about sin and cosine, but since they didn't really explain anything it doesn't really help a maths novice learn what to do to replicate it.
But I'll look into the other links you provided too.
 

Zerb Games

Member
I actually did see those images from videos I watched looking up more about sin and cosine, but since they didn't really explain anything it doesn't really help a maths novice learn what to do to replicate it.
But I'll look into the other links you provided too.
If you'd like I can try to make a tutorial. My laptop broke, so I'm not sure my current PC will be able to handle recording software.
 
W

Wild_West

Guest
If you'd like I can try to make a tutorial. My laptop broke, so I'm not sure my current PC will be able to handle recording software.
I mean I'm not gonna say no to an offer of help when I'm stuck so if you're willing to yeah I'd appreciate it ^^
 
D

dannyjenn

Guest
Brief explanation:

A sine wave is nothing more than the graph of magnitude = sin(angle). The sin() function comes from trigonometry, and it has a lot to do with a unit circle and sohcahtoa and all that, but you really don't need to know any of that in order to use it. All you need to know is, you put some value into it, and some other value comes out of it. Think of the in-value as x and the out-value as y. As it happens to work out, as you increase x then y first begins to increase, then it slows, then it begins to decrease, then it slows, then it begins to increase, and so on, in sort of a wavy pattern. So if you loop through all the xs, plotting the ys, you will get the wave pattern. Pseudocode:
Code:
for(x=0;x<10;x+=1){
    y = sin(x);
    draw_point(x,y);
}
The thing is, if you actually ran this code, you would not see the wave, because it's way too small. You need to throw in some multipliers,
Code:
for(x=0;x<10;x+=1){
    y = sin(x);
    draw_point(10*x,10*y);
}
The other problem is, since we're just plotting points, it's all disjointed. So instead of drawing points, we need to draw line segments:
Code:
old_x = 0;
old_y = 0;
for(x=0;x<10;x+=1){
    y = sin(x);
    draw_line(10*old_x,10*old_y,10*x,10*y);
    old_x = x;
    old_y = y;
}
Lastly, that might look a little jagged, so we can change increase the "sampling rate" by changing the x+=1 to x+=.1. That will make the line ten times smoother, yet will also make the loop and the drawing ten times slower. So you need to find a nice balance.
 
Last edited by a moderator:
Top