Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: Hotshot on February 13, 2007

Title: Gradient Bob
Post by: Hotshot on February 13, 2007
Code: [Select]
' GRADIENT - FEB 08 2007
; this was from zawran on BlitzMax a
; And I have convert to freebasic with Bob and gradients =)

Const ScreenX=106
Const ScreenY=106
Const ESCAPE =1

' PLAY AROUND WITH THESE ON SIZE AND DEGREE( 0 TO 360 )
Const SIZE  =140
Const DEGREE=100

'' set screen mode
   SCREEN 18
   
   '' allocate and draw to an image buffer
   DIM image_buffer AS ANY PTR
   image_buffer = ImageCreate( 256, 256, RGBA( 64, 160, 0, 255 ) )
   
   'CIRCLE  ( 32, 32 ), 28, RGBA( 255, 0, 0, 128 ),,,,F
For X=1 To ScreenX
          For Y=1 To ScreenY
              ' Play around with X,Y by swap around for different COLORS!
          Color (X,Y)
          ' Draw the Line
        Line image_buffer,(X,Y)-(X,Y)
    Next X
Next Y
     
' bob effect !
Dim  bobx(DEGREE)
Dim  boby(DEGREE)

For i = 0 To 63
    bobx( i ) = i * SIZE Mod DEGREE
    boby( i ) = i * SIZE Mod DEGREE
Next

bobXadd = 1 ' this is the values we add To move the bobs
bobYadd = 2 ' change these For different patterns

While INKEY$ = ""   
  Cls
  For i = 0 To 63
          ' blit image buffer to screen
          PUT( 300 + Sin( bobx(i) ) * 300, 300 + Sin( boby(i) ) * 224 ), image_buffer, PSET
          'PUT( 180, 140 ), image_buffer, ALPHA        
  Next i
     
      For i = 0 To 63
          bobx(i) = bobx(i) + bobXadd Mod DEGREE
          boby(i) = boby(i) + bobYadd Mod DEGREE
      Next i
Wend

I got a problem with this and could anyone sort out for me please

cheers
Title: Re: Gradient Bob
Post by: Clyde on February 13, 2007
It's to do with your sin and cosine calculations and it working differently from Blitz ;)
In FB it deals with Radians and not degrees in the argument, which BB automatically converts for you.

Code: [Select]
PUT( 300 + Sin( bobx(i) *(PI/180) ) * 300, 300 + Sin( boby(i)*(PI/180) ) * 224 ), image_buffer, PSET

you'll need to change your *300 & 224 speeds.
Also you'll need to set up a variable for Pie;

eg:
Code: [Select]
Const PI = 3.14151693

Cheers and this helps,
Clyde.
Title: Re: Gradient Bob
Post by: Jim on February 13, 2007
Quote
Const PI = 3.14151693
That's not quite right
Const PI = 3.14159265
not that one ten-thousandth of a circle is going to make that much difference :)

Like Clyde says, Blitz uses degrees, FB uses radians.
degrees = radians * 180 / pi
radians = degrees * pi / 180

Jim
Title: Re: Gradient Bob
Post by: Shockwave on February 13, 2007
3.1415926535897932 Maybe we should have a comp to see how many decimal places we can calculate Pi to?  :cheers:
Title: Re: Gradient Bob
Post by: Jim on February 13, 2007
Or a memory competition.  I can remember it to 3.141592653589 but seem to have got stuck there even though I've tried.  I think it was written round the wall of some class I was bored in so I just sat there and memorised some digits :D

Jim
Title: Re: Gradient Bob
Post by: taj on February 14, 2007
http://3.141592653589793238462643383279502884197169399375105820974944592.com/index1.html


lalalala....
Title: Re: Gradient Bob
Post by: Clyde on February 14, 2007
Let us know how you get on Hotshot :)