Computer Science Canada [source code] Modeling a wave |
Author: | Tony [ Mon Apr 21, 2003 11:01 pm ] | ||||
Post subject: | [source code] Modeling a wave | ||||
Inspired by my physics class and waves unit, I've came up with a short procedure for modeling waves. I will probably be making some apps using this procedure in the future.
In reality its just a cosine graph, modified to allow for accurate wave modeling. This in fact is how all graphs should be done in programming. If you're drawing dots for each X value, you'll have a lot of blank spaces unless your line is perfectly horizontal (or at 45 angle), so you have to draw a line instead. From current point to the next one. Parameters' explanations are commented inside the procedure. Here's a sample of how you call it
That will draw you a wave with 25 pixel wavelength and 20 pixel amplitude. It is in its original position (moved 0). To find frequency you need to know the time. The frequency is maxx/waveLength/time(in seconds). |
Author: | Catalyst [ Mon Apr 21, 2003 11:36 pm ] | ||
Post subject: | |||
i modded your proc a bit so its friendlier with real numbers (i dont like ints) also add a couple more params and made a little prog
|
Author: | Martin [ Tue Apr 22, 2003 8:33 pm ] |
Post subject: | |
Lookin good guys |
Author: | rizzix [ Sun May 25, 2003 7:57 pm ] |
Post subject: | |
heh, guys i've come up with an easier solution! you need to know how to use OO side of turing though... i use a simple convention (cuz i'm kinda limited by turing!!), used all caps for procedure, and all lower-case for functions take note of the equation: y = a(func(k(x - d))) + c where func = (sine, cos or tan) to set the amplitude u call wave_object->A(value) to get the amplitude u call something := wave_object->a to draw the wave u call wave_object->drawWave(border : int, colour : int) to change the scale of degree-to-pixel ratio (default is 1:1 i think) u call wave_object->SCALE(value : real) attached is the wave library file. have fun!!! o btw: dont use the Tangent Wave i haven't completed it yet! but if u insist u can (just remember it gets undefined at 90 degrees) |
Author: | rizzix [ Sun May 25, 2003 8:00 pm ] |
Post subject: | hmmm..... |
how do i know i attached the file? i'm new here! thanks.. |
Author: | Catalyst [ Sun May 25, 2003 8:06 pm ] |
Post subject: | |
u cant attach files in the source code area |
Author: | Catalyst [ Sun May 25, 2003 8:07 pm ] |
Post subject: | |
put it in submissions |
Author: | rizzix [ Sun May 25, 2003 8:09 pm ] | ||
Post subject: | |||
ok thx but this should work right?...
|
Author: | rizzix [ Sun May 25, 2003 8:14 pm ] | ||
Post subject: | |||
here's an example using it!
|
Author: | rizzix [ Sun May 25, 2003 8:17 pm ] | ||
Post subject: | |||
oh eh almost forgot!
to draw a grid |
Author: | Catalyst [ Sun May 25, 2003 10:18 pm ] |
Post subject: | |
cool |
Author: | Tony [ Sun May 25, 2003 11:16 pm ] |
Post subject: | |
looks awesome... just have attach wave parts together to make it solid |
Author: | PHP God [ Mon May 26, 2003 4:26 pm ] |
Post subject: | |
cool sine wave, how bout a sawtooth, or a square, or a sine-square. I'm into electronic music so this crap fascinates me. |
Author: | rizzix [ Mon May 26, 2003 4:53 pm ] |
Post subject: | |
oh! ok np simply subtract 1 from _d for y2 in the drawline proc ex: drawline (x + ix, round (((_a - border_width) * sind (_k * (x - _d))) + _c) + iy, x + ix, round ((_a * sind (_k * (x - _d - 1))) + _c) + iy, colr) i fixed the code above... |
Author: | rizzix [ Mon May 26, 2003 5:39 pm ] |
Post subject: | |
some additional info... The cool thing about this class is that it defines default values for everything so u can draw a wave by simply writing a few lines.. var wave : ^SineWave new wave wave -> drawWave(0, red) free wave By default: the wave is drawn at centre of screen but the default range is from -180 to 180 thus it technically begins drawing 180 pixels to the left of the middle the scale of the wave is 1:1 (degrees : pixels) setting the scale to 2 doubles the size, length etc, of the wave, yet display the correct values for a,k,d,c,lambda etc.. you can also set it to a value < 1, letting u to display a wave of a larger length. The amplitude of the wave is 10 pixels by default. So setting a to 2 results in an amplitude of 20 pixels you need to specify the thickness of the wave to be drawn, which by default fills the wave from the inside to the very edge. Setting a negative value results in the opposite. And yes the TangentWave is incomplete. Alas, i have no time, so if anyone is interested go ahead and extend the TrigWave class with a complete solution for the TangentWave. I'm currently working on a simple record-base DBMS solution for my ISP in school. Its a success, so far. I've eliminated all those gazillion bugs. It amazingly scalable and flexible. I'll post the complete system here (its not extremely huge, as i said it is quite simple), but only after the ISP. |
Author: | Tony [ Mon May 26, 2003 6:19 pm ] |
Post subject: | |
thats cool... And yeah, you should post your ISPs after you hand them in cuz some teachers think that everybody is stupid and just copies code of the net... and if its big, plz upload in file |
Author: | brazilian_princess [ Thu May 29, 2003 9:39 pm ] |
Post subject: | |
how do u run that??? *can u tell i suck at comps?* |
Author: | krishon [ Thu May 29, 2003 9:46 pm ] |
Post subject: | |
lol, funny avatar |
Author: | Homer_simpson [ Thu May 29, 2003 10:02 pm ] |
Post subject: | |
i think her avatar is really nice... |
Author: | rizzix [ Fri May 30, 2003 3:07 pm ] |
Post subject: | |
brazilian_princess wrote: how do u run that??? *can u tell i suck at comps?*
well copy all that code into a file... make sure the loop is pasted towards the end of the file the press F1 |