Exponential sine wave
A Flash Developer Resource Site

1. ## Exponential sine wave

Hello!

With this code I can draw a simple sine wave on the stage:

Code:
```var frequency:Number = 5;
var axisY:Number = stage.stageHeight*.5;
var amplitudeMultiplier:Number = 32;

graphics.lineStyle(2);
graphics.moveTo(0, axisY);

for (var i:uint = 0; i <= stage.stageWidth; i++) {
var amplitude:Number = Math.sin(frequency * Math.PI*2 * i/stage.stageWidth);
graphics.lineTo(i, axisY - amplitude*amplitudeMultiplier);
}```
But... I want to draw a exponential sine wave, like this:

I think the Math.exp()-function can be useful. Please, help!

2. some dude made this one.

3. ## You mean this kind?

You mean this kind?
Add this code at the end.
I hope this works like you think.
Code:
`frequency=frequency+frequency/1000;`

4. There are two approaches you can take. Either adjust the frequency directly in the loop or take into account the i:
This one basically adjusts the frequency based upon the x position.
Code:
```for (var i:uint = 0; i <= stage.stageWidth; i++) {
var amplitude:Number = Math.sin((frequency+i/10) * Math.PI*2 * i/stage.stageWidth);
graphics.lineTo(i, axisY - amplitude*amplitudeMultiplier);
}```
This basically keeps increasing the frequency based upon the number of loops run.
Code:
```for (var i:uint = 0; i <= stage.stageWidth; i++) {
var amplitude:Number = Math.sin(frequency * Math.PI*2 * i/stage.stageWidth);
frequency+=frequency/100;
graphics.lineTo(i, axisY - amplitude*amplitudeMultiplier);
}```
Either one will work but the one based upon x position would probably be simpler in some ways.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap