Cosinus

Do you have something to share with us? A tip for newbies, perhaps? Post it here.
Post Reply
peter
Active Member
Posts: 123
Joined: Mon Oct 22, 2007 2:31 pm

Cosinus

Post by peter »

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:
Invaders, Breakout, whatever.
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
Ball = LoadImage("Ball.bmp")

'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
Last edited by peter on Wed Aug 27, 2008 7:48 pm, edited 1 time in total.
Koodiapina
Forum Veteran
Posts: 2396
Joined: Tue Aug 28, 2007 4:20 pm

Re: Cosinus

Post by Koodiapina »

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.
peter
Active Member
Posts: 123
Joined: Mon Oct 22, 2007 2:31 pm

Re: Cosinus

Post by peter »

Hi Grandi,

With your circle are the functions a little bit
adulterates.
A ball is better as Sprite.
Koodiapina
Forum Veteran
Posts: 2396
Joined: Tue Aug 28, 2007 4:20 pm

Re: Cosinus

Post by Koodiapina »

peter wrote:A ball is better as Sprite.
I bet, but you should share the image, that we could test the code with it :P
peter
Active Member
Posts: 123
Joined: Mon Oct 22, 2007 2:31 pm

Re: Cosinus

Post by peter »

Post Reply