Page 1 of 1

### Cosinus

Posted: Tue Aug 19, 2008 12:19 am
Hi there,

i was interested how fast CoolBasic these trigonometrically handled.
I would say, very good!
Maybe you may it use for movements in a game.
For example:
For the Ball as graphic, create a Ball or square with 16x16 pixel.

Here is the example:

Code: Select all

``````SCREEN 1024,768,16,1

Global Ball,i

'Main
Cosinus(120,45,8,4)
Cosinus(120,45,16,5)
Cosinus(120,12,32,6)
Cosinus(120,22,48,7)
Cosinus(120,Tan(-45),64,7)
Cosinus(120,Sqrt(8),80,8)
DrawScreen
WaitKey
End

Function Cosinus(z,wi,ho,t)
For i=0 To z
DrawImage Ball,i*8 +  0,(Cos(i*wi)+t)*ho
DrawImage Ball,i*8 + 64,(Cos(i*wi)+t)*ho
DrawImage Ball,i*8 + 128,(Cos(i*wi)+t)*ho
DrawImage Ball,i*8 + 192,(Cos(i*wi)+t)*ho
Next i
EndFunction
``````

### Re: Cosinus

Posted: Tue Aug 19, 2008 4:48 pm
Here's your example code, little modified. In this version tester don't need to have Ball.bmp ;)

Code: Select all

``````SCREEN 1024,768,16,1

Global Ball,i
Ball = MakeImage(16,16)
DrawToImage Ball
Color 255,0,0
Circle 0,0,16,16
DrawToScreen

'Main
Cosinus(120,45,8,4)
Cosinus(120,45,16,5)
Cosinus(120,12,32,6)
Cosinus(120,22,48,7)
Cosinus(120,Tan(-45),64,7)
Cosinus(120,Sqrt(8),80,8)
DrawScreen
WaitKey
End

Function Cosinus(z,wi,ho,t)
For i=0 To z
DrawImage Ball,i*8 + 0,(Cos(i*wi)+t)*ho
DrawImage Ball,i*8 + 64,(Cos(i*wi)+t)*ho
DrawImage Ball,i*8 + 128,(Cos(i*wi)+t)*ho
DrawImage Ball,i*8 + 192,(Cos(i*wi)+t)*ho
Next i
EndFunction``````
BTW; nice example, but could also include sin.

### Re: Cosinus

Posted: Tue Aug 19, 2008 6:44 pm
Hi Grandi,

With your circle are the functions a little bit