Author Topic: Gradient Bob  (Read 3621 times)

0 Members and 1 Guest are viewing this topic.

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Gradient Bob
« 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

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Gradient Bob
« Reply #1 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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Gradient Bob
« Reply #2 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
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Gradient Bob
« Reply #3 on: February 13, 2007 »
3.1415926535897932 Maybe we should have a comp to see how many decimal places we can calculate Pi to?  :cheers:
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Gradient Bob
« Reply #4 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
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Gradient Bob
« Reply #6 on: February 14, 2007 »
Let us know how you get on Hotshot :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: