[Gambas-user] using Sin() to produce a specific range of values

Kevin Fishburne kevinfishburne at ...1887...
Sun Jul 10 08:33:27 CEST 2011


On 07/10/2011 02:02 AM, Ian Haywood wrote:
> On Sun, Jul 10, 2011 at 3:37 PM, Kevin Fishburne
> <kevinfishburne at ...1887...>  wrote:
>> I need to use the Sin() function to calculate an output range from an
>> input range. The advantage of Sin() is that it's not linear; it makes a
>> nice smooth curve of values sort of like a sound wave in an audio editor.
> this example project does this using 50 numbers, you can adjust the stepping
> in the FOR loop to change the number of numbers produced.

Hi Ian. The code attached is:

Public Sub Main()
     Dim i As Float

     For i = 0.0 To 1.0 Step 0.02
       Print CInt(255 * Sin(Pi(i)))
     Next
End

It's output values when run are:

0
16
31
47
63
78
93
108
122
136
149
162
174
185
196
206
215
223
230
237
242
246
250
252
254
255
254
252
250
246
242
237
230
223
215
206
196
185
174
162
149
136
122
108
93
78
63
47
31
16

That worked extremely well, thank you so much. The Pi part is 
interesting. I thought I had it working, as it worked very similarly to 
your code, but I didn't use Pi. I was using something like Rad(degrees), 
cycling from 0 to 360 instead.

Something I just corrected was that I needed those values inversed. It 
should have started at 255, went to zero in the middle, then back to 
255. I figured it out, so I guess I'm not a completely jackass. :) 
Thanks so much!

Also, to the mailing list in general, please let me know if it's okay if 
every now and then if I post a link to what I've done so far with 
GAMBAS. Part of me thinks it's okay because we should all be proud of 
what we've programmed with it, but I don't want to offend the list. Any 
input on that is appreciated. Sometimes when someone helps me (a lot 
around here!) I want to show them the immediate results of the fix, but 
I'm a bit reserved as I don't want to pollute an already busy list. 
Maybe there should be a new gb mailing list just for accomplishments?

-- 
Kevin Fishburne
Eight Virtues
www:http://sales.eightvirtues.com
e-mail:sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list