Author Topic: Deck chair and beach ball  (Read 5041 times)

0 Members and 1 Guest are viewing this topic.

gooner

  • Guest
Deck chair and beach ball
« on: July 24, 2008 »
Just a simple program to prove i'm getting the hang of rasters with a lot of help from Rain_storm and Shockie.Thanks guys
 :)
« Last Edit: September 20, 2009 by Shockwave »

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Deck chair and beach ball
« Reply #1 on: July 24, 2008 »
You're picking this stuff up really fast, it took me much longer to get a foot in the door. I like the way way the colours make a nice gradient. Just one question how did you go about drawing the beach ball I presume its just three circles but its being drawn on top of the background so how did you stop it from overlapping? Did you use sin/cos for the orange part of the ball?

Challenge Trophies Won:

gooner

  • Guest
Re: Deck chair and beach ball
« Reply #2 on: July 24, 2008 »
Cheers for that Rain
Code: [Select]
CIRCLE (xx, yy), 50, &h666666
    CIRCLE (xx,yy),50,&h000040,,,1,f
    CIRCLE (xx,yy),50,&hFF8000,,,0.5,f

This was the code i used for the beach ball,it was pure chance it didn't overlapp.Any tips on using sin/cos would be greatley received.
 :)

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Deck chair and beach ball
« Reply #3 on: July 24, 2008 »
This is strange the value of &h666666 does not occur in your exe's disassembly not even once, I found the &hFF8000 and &h40 in close proximity it seems your exe uses the value &h0F not &h666666 for the first circle. Still cant understand why there isnt any overlap though. Is there any chance I can get the full source code so I can check this out. Little tricks like this are invalueable

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Deck chair and beach ball
« Reply #4 on: July 24, 2008 »
Congrats on your progress Gooner dude. Welldone.

Cheers and all the very best,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

gooner

  • Guest
Re: Deck chair and beach ball
« Reply #5 on: July 25, 2008 »
Heres the code for you mate
Code: [Select]
' DECKCHAIRS AND BEACBALLS
'

OPTION EXPLICIT


'   SCREEN MODE 18 IS 640 * 480


    SCREEN 18,32,2,
    SCREENSET 1,0
   
    DIM SHARED AS INTEGER YRES = 480 :' DRAW HEIGHT
    DIM SHARED AS INTEGER XRES = 640 :' DRAW WIDTH
    DIM SHARED AS DOUBLE XX=0
    DIM SHARED AS DOUBLE YY=0
    DIM SHARED AS INTEGER BBX=0'MOVES CIRCLE HORIZONTALY
    DIM SHARED AS INTEGER BBY=0'MOVES CIRCLE VERTICALLY
'   SUBROUTINES;

   
    DECLARE SUB DOUBLE_BUFFER()
    DECLARE SUB PLOT_BARS()
    declare sub PLOT_CIRCLE()

'   COUPLE OF VARIABLES USED AS GENERAL COUNTING VARIABLES, THESE NEED TO BE SHARED;

    DIM SHARED AS DOUBLE ADD1,ADD2,ADD3
   
    DIM SHARED AS INTEGER SCREEN_R(YRES)
    DIM SHARED AS INTEGER SCREEN_G(YRES)
    DIM SHARED AS INTEGER SCREEN_B(YRES)
 
' MAIN LOOP; 
DO
   'MOVE BARS;
    ADD1=ADD1+.1
    ADD2=ADD2+.2
    ADD3=ADD3+.3
    PLOT_CIRCLE()
    PLOT_BARS()
    DOUBLE_BUFFER()   
   
LOOP UNTIL INKEY$<>""
END


'-------------------------------------------------------------------------------
SUB PLOT_BARS()
   
    DIM AS INTEGER y,c1,c2,c3
   
    C1=160+59*sin(add3*3.14/45)
    C2=160+59*cos(add3*3.14/90)
    C3=160+59*sin(add3*3.14/180)
   
   
    FOR Y=0 TO YRES
       
        SCREEN_R(Y)=120+(C1*SIN((Y-ADD2)*3.14/120))
        SCREEN_G(Y)=120+(C2*COS((Y+ADD2)*3.14/120))
        SCREEN_B(Y)=120+(C3*SIN((Y-ADD1)*3.14/120))
       
   

  NEXT
  END SUB

   SUB PLOT_CIRCLE()
     

END SUB

SUB DOUBLE_BUFFER()
    DIM Y AS INTEGER
   
    SCREENCOPY
    CLS
   
    FOR Y=0 TO YRES
     
        LINE(0,Y)-(XRES,Y),RGB(SCREEN_R(Y),SCREEN_G(Y),SCREEN_B(Y))
          'MOVE CIRCLE
   
   if BBX=0 then XX=XX+.006
   if XX>590 then BBX=1
   if BBX=1 then XX=XX-.008
    IF XX<36 THEN BBX=0
 
   
   if BBY=0 then YY=YY+.007
   if YY>434 then BBY=1
   if BBY=1 then YY=YY-.006
   if YY<42 then BBY=0
   

   

    CIRCLE (XX, YY), 50, &h666666
    circle (XX,yy),50,&h000040,,,1,f
    circle (XX,yy),50,&hFF8000,,,0.5,f' Draws a filled ellipse
   
 NEXT



   
    SLEEP 2
END SUB
The raster part of the code was supplied by Shockwave and modified by me to get the deckchair effect.The beachball was coded by me incorparating what i lernt when i done gooner bounce.
Quote
This is strange the value of &h666666 does not occur in your exe's disassembly not even once, I found the &hFF8000 and &h40 in close proximity it seems your exe uses the value &h0F not &h666666 for the first circle.
Sorry mate the &h666666 was something i changed after i uploaded it to tidy the code up sorry for any confusion.
cheers dude.
 :)
« Last Edit: July 25, 2008 by Gooner »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Deck chair and beach ball
« Reply #6 on: July 25, 2008 »
You're definately coming along in leaps and bounds, the colours here are very erm.. Vivid!

I know you need more help with colours so I won't bash them, it's a pleasure to see your progress, please keep the programs coming.

A few little tips that might help you;

You called the sub PLOT_CIRCLE()

That sub is correctly defined but it is actually empty!

In your source, the circle commands are actually inside the Y draw loop which fills the screen with your "deck chair" raster effect.
This means that your circles are being drawn YRES times or 480 times in this case, and as there are 3 circles in your beachball you are drawing 1,440 circles every frame!

So maybe as a coding exercise you could fix those bugs :) Shout if you need help!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Deck chair and beach ball
« Reply #7 on: July 25, 2008 »
Oh, sorry one more thing, this circle;

CIRCLE (XX, YY), 50, &h666666

Is overwritten by the next one so there's no point in having it.

Clue.. They both have a radius of 50 pixels :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Deck chair and beach ball
« Reply #8 on: July 25, 2008 »
I never knew that circle in FB is actually elipse now I understand so in this code
Code: [Select]
    circle (XX, yy), 50, &hFF8000,,,0.5,f' Draws a filled ellipse
0.5 is the value y gets scaled by for the radius and f is for fill the circle instead of drawing just the outline correct?


Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Deck chair and beach ball
« Reply #9 on: July 25, 2008 »
You are correct Rain :)
Shockwave ^ Codigos
Challenge Trophies Won:

gooner

  • Guest
Re: Deck chair and beach ball
« Reply #10 on: July 25, 2008 »
Thanks for your responce Simon Shockwave


You called the sub PLOT_CIRCLE()

That sub is correctly defined but it is actually empty!

In your source, the circle commands are actually inside the Y draw loop which fills the screen with your "deck chair" raster effect.This means that your circles are being drawn YRES times or 480 times in this case, and as there are 3 circles in your beachball you are drawing 1,440 circles every frame!
This might explain why i had to slow the movement of the beach ball  down using doubles as using whole numbers the beach ball went like f**k.I knew i had to insert a sub routine but wasn't sure  where to insert it.Any chance you could tell me where it should go cheers dude
Oh, sorry one more thing, this circle;

CIRCLE (XX, YY), 50, &h666666

Is overwritten by the next one so there's no point in having it.

Clue.. They both have a radius of 50 pixels :)
I,m glad you spotted my deliberate mistake he he.
And finally
the colours here are very erm.. Vivid!
I know you need more help with colours so I won't bash them.
I definitely need help with colours i do seem to have a liking for garish colours rather than the plain ones,it must be down to the wallpaper we used to have as kids.Thanks  for all your help quality
 :)

gooner

  • Guest
Re: Deck chair and beach ball
« Reply #11 on: July 25, 2008 »
@ Rain
I never knew that circle in FB is actually elipse now I understand so in this code
Code: [Select]
    circle (XX, yy), 50, &hFF8000,,,0.5,f' Draws a filled ellipse
0.5 is the value y gets scaled by for the radius and f is for fill the circle instead of drawing just the outline correct?
Yes mate i stumbled across this in the FB help index and thought i'd have a play with it.This has given me an idea for my next challenge.I going to look through the help index and pick something in their examples and code something around it hopefully something i haven't yet come across.Watch this space
 ;)

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Deck chair and beach ball
« Reply #12 on: July 25, 2008 »
Ok, help with subroutines.

You can define them almost anywhere in your program.
You cannot define them inside a loop (main loop, for next loop etc).
You cannot define a subroutine within another subroutine.

A subroutine MAY call another subroutine.

A program stucture may look like this;

Code: [Select]

OPEN SCREEN
DECLARE VARIABLES
DECLARE SUBROUTINE1
DECLARE SUBROUTINE2
DECLARE SUBROUTINE3

MAIN LOOP
 CODE
 CALL SUBROUTINE 2
 SOME MORE CODE
 SOME MORE CODE
 CALL SUBROUTINE 1

LOOP UNTIL KEY PRESSED
END

SUBROUTINE1
 CODE
 MORE CODE
END SUB

SUBROUTINE2
 CODE
 MORE CODE
 CALL SUBROUTINE 3
 CODE
 MORE CODE
END SUB

SUBROUTINE3
 CODE
 MORE CODE
END SUB


First of all variables are initialised, screen is open etc. You should declare the subroutines you are going to use before the main loop, the main loop is the bit of code that is repeasted each frame.

After the main loop the program is ended.
But under the END command you can see the actual subroutines.

You can call these subroutines from anywhere in your program.
As you can see, a subroutine can call another subroutine.

In order to understand this, think of this;

SUB DOUBLE_BUFFER()

as a label called "DOUBLE_BUFFER()"

and when you type "DOUBLE_BUFFER" into your main program, essentially, this happens.

The address of where you are in the program is placed on something called "THE STACK"
A stack is different to a QUEUE. Stack is "last on, first off", like taking plates off the top of a stack of plates. A queue is like pushing marbles down a hose pipe. First in first out.

Anyway, the address is placed on the stack. The program then jumps to the label "DOUBLE_BUFFER" and does whatever it finds there until it finds "END SUB", it looks at the stack, sees the address that was put onto it and jumps back to that address.

This is why you can call SUBS from other SUBS, many addresses are PUSHED onto the stack, and then POPPED off the stack as the program encounters End Subs.

So the simple answer to your question is.

You may call your subs from anywhere in your program.



I have an idea why your code ended up the way it did. (the empty sub).

The circles were put at the end of the double buffering sub because you were not seeing them.
I notice that you called PLOT_CIRCLE before you DOUBLE_BUFFERED, so your circles were being drawn, but then over-written with the lines that made up your deck chair.

So.. I think you copied and pasted the circles into the bottom of the double buffer program and they appeared but you didnt know why :)

You're doing really well, but you really need to ask more questions :P You're not asking enough!
Shockwave ^ Codigos
Challenge Trophies Won:

gooner

  • Guest
Re: Deck chair and beach ball
« Reply #13 on: July 25, 2008 »
Quality mate i've sussed it now its amazing how everything make more sense when your sober.
You're doing really well, but you really need to ask more questions :P You're not asking enough!
The reason i probably don't ask more questions is because i find it hard to put into words what i am actually asking for.But this is coming as my confidence is growing.I'm sure it will be less labourios for you if i ask rather than have to go through my whole code so i will certainly take this on board.Thanks once again mate you have my permission to open that bottle of wine he he hic
 :cheers:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Deck chair and beach ball
« Reply #14 on: July 25, 2008 »
The reason i probably don't ask more questions is because i find it hard to put into words what i am actually asking for.But this is coming as my confidence is growing.

If you get this scenario, the best thing is to post the source code and say what you expected it to do and then we'll be able to work out where you need to change it :)
Shockwave ^ Codigos
Challenge Trophies Won: