Author Topic: Jerky rastar  (Read 7609 times)

0 Members and 1 Guest are viewing this topic.

gooner

  • Guest
Jerky rastar
« on: July 15, 2008 »
Hello everybody i'm on to rastar bars now.Basically Shockwave coded 95% of this routine and i just changed a few numbers basically to see what effect it had which is probably why it doesn't run smoothly.I'm gunner do my own tomorrow from scratch so any tips would be greatly appreciated.


Code: [Select]
' RASTER BARS!
'

OPTION EXPLICIT


'   SCREEN MODE 18 IS 640 * 480
'   USING IT HERE SO I CAN DRAW SHORTER LINES TO FILL THE SCREEN (MORE SPEED)

    SCREEN 18,32,2,
    SCREENSET 1,0


'   SUBROUTINES;

    DECLARE SUB DOUBLE_BUFFER()
    DECLARE SUB DRAW_BACKGROUND()
    DECLARE SUB DRAW_BARS()

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

    DIM SHARED AS INTEGER ADD1,ADD2
 
' MAIN LOOP; 
DO
   'MOVE BARS;
    ADD1=ADD1+1
    ADD2=ADD2+2
   
   
    DRAW_BACKGROUND()
    DRAW_BARS()
    DOUBLE_BUFFER()   
   
LOOP UNTIL INKEY$<>""
END


'-------------------------------------------------------------------------------
SUB DOUBLE_BUFFER()

    SCREENCOPY
    CLS
    SLEEP 1
END SUB


SUB DRAW_BARS()
    DIM AS INTEGER A,B,C,D
FOR C=1 TO 1000 STEP 6
    D=300+100*SIN((C+ADD1)*3.14/180)+100*COS((C+ADD2)*4.14/180)
    B=3000
    FOR A=D TO D+50
        IF A<=D+6 THEN
            B=B+3000
        ELSE
            B=B=0
        END IF
        COLOR RGB (B,B,B)
        LINE(a,C)-(a,600)
    NEXT   


    D=290+200*SIN((C+ADD2)*4.14/180)+100*COS((C+ADD2)*4.14/180)
    B=0
    FOR A=D TO D+60
        IF A<=D+6 THEN
            B=B+3000
        ELSE
            B=B=10
        END IF
        COLOR RGB(C,C,C)
        LINE(A,C+3)-(A,480)
    NEXT   

NEXT

END SUB



SUB DRAW_BACKGROUND()
    DIM AS INTEGER A,B
    B=0 
    FOR A=0 TO 800
       COLOR RGB  (A,A,A)
        LINE (0,A)-(640,A)
        B=B-1
    NEXT
END SUB

Btw thanks for the code Shockie
 :)
« Last Edit: July 15, 2008 by gooner »

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Jerky rastar
« Reply #1 on: July 15, 2008 »
Not too bad at all. Its good to see that you are moving onto sub-routines. See how much more modular the code looks now. There are little units of code each doing its own job.
Tips well how about some multi colour? You could create variables red,grn,blu like this
Code: [Select]
dim as single red = 1.0
dim as single grn = 0.5
dim as single blu = 0.8
give these variables a value between 0.0 and 1.0 (because they are single precission floating point numbers not integers) then you can
do this to make them more colourful
Code: [Select]
        COLOR RGB(C*red,C*grn,C*blu)


edit - There are some lines that can be commented out without making a difference can you find them?
« Last Edit: July 15, 2008 by rain_storm »

Challenge Trophies Won:

gooner

  • Guest
Re: Jerky rastar
« Reply #2 on: July 15, 2008 »
Cheers for that rain i have struggling to work out how to make the colours up when using RGB i usually end up with dark blue or black.So i'll give that a try tomorrow.Thanks mate
  O0

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Jerky rastar
« Reply #3 on: July 15, 2008 »
Seems to run smoothly here - I suspect possibly you have hit some limit on your PC?

Jim
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Jerky rastar
« Reply #4 on: July 15, 2008 »
Works smooth here to dude! nice work!

Andy
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

gooner

  • Guest
Re: Jerky rastar
« Reply #5 on: July 15, 2008 »
Thanks for your feedback chaps it must be my labtop i'm using or my dodgy eyes
 ;)

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Jerky rastar
« Reply #6 on: July 15, 2008 »
Looking good welldone.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

gooner

  • Guest
Re: Jerky rastar
« Reply #7 on: July 15, 2008 »
Quote
Tips well how about some multi colour? You could create variables red,grn,blu like this



Code: [Select]
dim as single red = 1.0
dim as single grn = 0.5
dim as single blu = 0.8

Sorry to trouble you again Rain.I've created the variables but when i run it come up with "varibles not declared".Wherever i declared it came up with either "syntax error or expected next found declared." Any ideas 
cheers mate  :)

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Jerky rastar
« Reply #8 on: July 15, 2008 »
Try using Dim Shared ( this makes the variables available to all parts of the program, subroutines and functions ) as your using Option Explicit.


Hope that helps.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

gooner

  • Guest
Re: Jerky rastar
« Reply #9 on: July 15, 2008 »
Thanks for the tip mate i give that a try before zzz.
 O0 :cheers:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Jerky rastar
« Reply #10 on: July 16, 2008 »
You can make them shared variables (global variables) but it is best to keep them as local variables (only accessible from within the subroutine / function that uses them) To declare them as local you simply put those "dim as single xx" inside the subroutine itself this makes them invisible to all outside code. There are reasons why it is best to use local variables whenever possible but you dont need to worry about it for now just accept it as a given.

Sorry I am really rusty on my FreeBasic I thought that any variables declared in the main code was accesible to all sub routines inside main. I guese I was wrong about that.

Challenge Trophies Won:

gooner

  • Guest
Re: Jerky rastar
« Reply #11 on: July 16, 2008 »
No worries Rain i'll use your local variables when i do mine from scratch.Should be interesting he he.Thanks for the tips on the colours Shockie did tell me on saturday but i think we were on our third bottle of rioja by then.
cheers mate   :cheers:

@Clyde Worked a treat putting them in as global variables looks a bit more colourful now
Thanks for your help

 :)

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Jerky rastar
« Reply #12 on: July 16, 2008 »
Thats much nicer. great choice of colours the colours I used were crap compared to that

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Jerky rastar
« Reply #13 on: July 16, 2008 »
There seem to be lots of bugs, please post the code and I'll have a look at what you're doing.

Btw, it's glitching on your laptop because it's running out of muscle power :)

Shockwave ^ Codigos
Challenge Trophies Won:

gooner

  • Guest
Re: Jerky rastar
« Reply #14 on: July 16, 2008 »
Heres the code
Code: [Select]
' RASTER BARS!
'

OPTION EXPLICIT


'   SCREEN MODE 18 IS 640 * 480
'   USING IT HERE SO I CAN DRAW SHORTER LINES TO FILL THE SCREEN (MORE SPEED)

    SCREEN 18,32,2,
    SCREENSET 1,0


'   SUBROUTINES;

    DECLARE SUB DOUBLE_BUFFER()
    DECLARE SUB DRAW_BACKGROUND()
    DECLARE SUB DRAW_BARS()
   
'   COUPLE OF VARIABLES USED AS GENERAL COUNTING VARIABLES, THESE NEED TO BE SHARED;

    DIM SHARED AS INTEGER ADD1,ADD2
  dim shared red = 1.0
dim shared grn = 0.5
dim shared blu = 0.8
' MAIN LOOP; 
DO
   'MOVE BARS;
    ADD1=ADD1+1
    ADD2=ADD2+2
   
   
    DRAW_BACKGROUND()
    DRAW_BARS()
    DOUBLE_BUFFER()   
   
LOOP UNTIL INKEY$<>""
END


'-------------------------------------------------------------------------------
SUB DOUBLE_BUFFER()

    SCREENCOPY
    CLS
    SLEEP 1
END SUB


SUB DRAW_BARS()
    DIM AS INTEGER A,B,C,D
FOR C=1 TO 1000 STEP 6
    D=300+100*SIN((C+ADD1)*3.14/180)+100*COS((C+ADD2)*4.14/180)
    B=3000
    FOR A=D TO D+50
        IF A<=D+6 THEN
            B=B+3000
        ELSE
            B=B=0
        END IF
       
   
   
       
             COLOR RGB(d*red,C*grn,C*blu)
        LINE(a,C)-(a,600)
    NEXT   


    D=290+200*SIN((C+ADD2)*4.14/180)+100*COS((C+ADD2)*4.14/180)
    B=0
    FOR A=D TO D+60
        IF A<=D+6 THEN
            B=B+3000
        ELSE
            B=B=10
        END IF
        COLOR RGB(D*grn,C*red,D*blu)
        LINE(A,C+3)-(A,480)
    NEXT   

NEXT

END SUB



SUB DRAW_BACKGROUND()
    DIM AS INTEGER A,B,C,D
    B=0 
    FOR A=0 TO 800
       COLOR RGB  (D*grn,D*grn,D*grn)
        LINE (0,A)-(640,A)
        B=B-1
    NEXT
END SUB
Basically i changed some of the numbers of your original code you supplied to see what effect i would get without really knowing why so its possible i have made a few mathmatical errors along the way.So any points in the right direction would be put to good use in the future.Thanks for being honest i will learn more this way  :)

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Jerky rastar
« Reply #15 on: July 16, 2008 »
Thanks for posting the code, I have not fixed it because I already gave you the working version, but I added some comments so you can see some of the errors.

By the way, all the answers you need are in the examples you have, when we worked on integers, doubles, arrays etc.

So.. Instead of altering a piece of code that you don't quite understand yet, how about loading in the template and making something by yourself and post your progress so that we can help you with it?

The challenge I gave you is to make horizontal raster bars with nice colours ;)
If you feel like trying your own ideas, go for it. It can't hurt you.

Code: [Select]
' RASTER BARS!
'

OPTION EXPLICIT


'   SCREEN MODE 18 IS 640 * 480
'   USING IT HERE SO I CAN DRAW SHORTER LINES TO FILL THE SCREEN (MORE SPEED)

    SCREEN 18,32,2,
    SCREENSET 1,0


'   SUBROUTINES;

    DECLARE SUB DOUBLE_BUFFER()
    DECLARE SUB DRAW_BACKGROUND()
    DECLARE SUB DRAW_BARS()
   
'   COUPLE OF VARIABLES USED AS GENERAL COUNTING VARIABLES, THESE NEED TO BE SHARED;

    DIM SHARED AS INTEGER ADD1,ADD2
   
   
    ' errors below, these variable are not declared as doubles (floating point)
    ' so by default are integers (whole numbers).
   
    dim shared red = 1.0
    dim shared grn = 0.5
    dim shared blu = 0.8
   
' MAIN LOOP; 
DO
   'MOVE BARS;
    ADD1=ADD1+1
    ADD2=ADD2+2
   
   
    DRAW_BACKGROUND()
    DRAW_BARS()
    DOUBLE_BUFFER()   
   
LOOP UNTIL INKEY$<>""
END


'-------------------------------------------------------------------------------
SUB DOUBLE_BUFFER()

    SCREENCOPY
    CLS
    SLEEP 1
END SUB


SUB DRAW_BARS()
    DIM AS INTEGER A,B,C,D
   
' 1000 ?????????????????!!!!!!!!!!!!!!!!!!!!!
' screen is 480 pixels high. \/

FOR C=1 TO 1000 STEP 6
    D=300+100*SIN((C+ADD1)*3.14/180)+100*COS((C+ADD2)*4.14/180)
    B=3000

    ' This is messed up.
    ' what do you think this loop is doing? It draws a bar.
    ' you are increasing the variable "b" which I used for colours but not using
    ' B anywhere, why add 3000 to b? Makes no sense.
   
    '\/
    FOR A=D TO D+50
        IF A<=D+6 THEN
            B=B+3000
        ELSE
            B=B=0
        END IF
       
             'red, grn,blu all contain flase values
             'as they were declared as integers so there is no point having them.
             
             COLOR RGB(d*red,C*grn,C*blu)
        LINE(a,C)-(a,600)
    NEXT   

' I'll echo my comments in the above loop for this part..

    D=290+200*SIN((C+ADD2)*4.14/180)+100*COS((C+ADD2)*4.14/180)
    B=0
    FOR A=D TO D+60
        IF A<=D+6 THEN
            B=B+3000
        ELSE
            B=B=10
        END IF
        COLOR RGB(D*grn,C*red,D*blu)
        LINE(A,C+3)-(A,480)
    NEXT   

NEXT

END SUB



SUB DRAW_BACKGROUND()
    'red, grn,blu all contain flase values
    'as they were declared as integers so there is no point having them.
    ' d was never assigned a value so D*grn etc is always 0, thats why theres no background colour.
    DIM AS INTEGER A,B,C,D
    B=0 
    FOR A=0 TO 800
       COLOR RGB  (D*grn,D*grn,D*grn)
        LINE (0,A)-(640,A)
        B=B-1
    NEXT
END SUB
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Re: Jerky rastar
« Reply #16 on: July 16, 2008 »
I'm not sure quite what effect you're aiming for, but I had a quick look through the code looking for anything obvious.

Code: [Select]
' RASTER BARS!
'

OPTION EXPLICIT


'   SCREEN MODE 18 IS 640 * 480
'   USING IT HERE SO I CAN DRAW SHORTER LINES TO FILL THE SCREEN (MORE SPEED)

    DIM SHARED AS UINTEGER XRES=640
    DIM SHARED AS UINTEGER YRES=480

    SCREEN 18,32,2,
    SCREENSET 1,0


'   SUBROUTINES;

    DECLARE SUB DOUBLE_BUFFER()
    DECLARE SUB DRAW_BACKGROUND()
    DECLARE SUB DRAW_BARS()
   
'   COUPLE OF VARIABLES USED AS GENERAL COUNTING VARIABLES, THESE NEED TO BE SHARED;

    DIM SHARED AS INTEGER ADD1,ADD2
    dim shared as single red = 1.0
    dim shared as single grn = 0.5
    dim shared as single blu = 0.8
' MAIN LOOP; 
DO
   'MOVE BARS;
    ADD1=ADD1+1
    ADD2=ADD2+2
   
   
    DRAW_BACKGROUND()
    DRAW_BARS()
    DOUBLE_BUFFER()   
   
LOOP UNTIL INKEY$<>""
END


'-------------------------------------------------------------------------------
SUB DOUBLE_BUFFER()
    SCREENCOPY
    CLS
    SLEEP 1
END SUB


SUB DRAW_BARS()
    DIM AS INTEGER A,B,C,D
    FOR C=1 TO YRES STEP 6
        D=300+100*SIN((C+ADD1)*3.14/180)+100*COS((C+ADD2)*4.14/180)
        B=3000
       
        ' I moved the colour setting out of the inner loop as it doesn't
        ' change in there
        COLOR RGB(d*red,C*grn,C*blu)
        FOR A=D TO D+50
            IF A<=D+6 THEN
                B=B+3000
            ELSE
                B=B=0
            END IF
       
            LINE(a,C)-(a,600)
        NEXT A   

        D=290+200*SIN((C+ADD2)*4.14/180)+100*COS((C+ADD2)*4.14/180)
        B=0

        ' I moved the colour setting out of the inner loop as it doesn't
        ' change in there
        COLOR RGB(D*grn,C*red,D*blu)
        FOR A=D TO D+60
            IF A<=D+6 THEN
                B=B+3000
            ELSE
                B=B=10
            END IF
            LINE(A,C+3)-(A,480)
        NEXT A
    NEXT C

END SUB

SUB DRAW_BACKGROUND()
    DIM AS INTEGER A,B
    B=480
    FOR A=0 TO YRES
        LINE (0,A)-(640,A)
        COLOR RGB(0,B*grn,0)
        B=B-1
    NEXT
END SUB

As Shockwave has already pointed out, there are some areas where you're not quite understanding what his code did.  One thing I did was to declare an X and Y resolution of your screen at the start so that you can use these variables when you're referring to the screen dimensions rather than just a number.

For example, you have a loop running from 1 to 1000, when the screen is only 480 pixels high.  Using the YRES variable means that you won't be tempted to change it at a whim.

I also changed your declarations of red, grn, and blu to be 'single' types, values that can hold some degree of a decimal number.  This means that the gradual effect I *think* you were looking for can now be done, and this includes your shaded background (I assume that's what you were trying to do).

Another optimisation I did was to take the RGB calculations out of an inner loop where it isn't needed.  This is something to keep an eye on as it is so easy to do.

For example:

Code: [Select]
        COLOR RGB(D*grn,C*red,D*blu)
        FOR A=D TO D+60
            IF A<=D+6 THEN
                B=B+3000
            ELSE
                B=B=10
            END IF
            LINE(A,C+3)-(A,480)
        NEXT A

You initially had the colour code inside the 'A' loop, but as D and C don't change inside that loop, there is no need to recalculate it.  It might not save you much processing time, but it's always worthwhile.

I apologise if I have fixed things that weren't a problem, or that changed the intention of your code, but I'm not quite sure what you were aiming for.
Challenge Trophies Won:

gooner

  • Guest
Re: Jerky rastar
« Reply #17 on: July 16, 2008 »
Thanks to everbody for their honest comments everthing has been taken on board i hope.I haven't had to use my brain like this since i left school so thats a challenge in itself.I wasn't really aiming for any effect i posted it because i didn't really understand what was happening.But thanks to you guys comments hopefuly i've now grasped it. I will now attempt to do the horizontal rastar bars and will post any pacific things i don't understand .
Thanks Wayne  :cheers:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Jerky rastar
« Reply #18 on: July 22, 2008 »
Here's an idea for you, this effect is a very old fashioned one of red, green and blue rasters with the colours blending into each other.

You probably wont get everything thats going on here but it'll be something else for you to alter and see what happens.

It works with an array that just holds the colour value for each line.

Code: [Select]
' RASTER BARS!
'

OPTION EXPLICIT


'   SCREEN MODE 18 IS 640 * 480
'   USING IT HERE SO I CAN DRAW SHORTER LINES TO FILL THE SCREEN (MORE SPEED)

    SCREEN 18,32,2,
    SCREENSET 1,0
   
    DIM SHARED AS INTEGER YRES = 480 :' DRAW HEIGHT
    DIM SHARED AS INTEGER XRES = 640 :' DRAW WIDTH

'   SUBROUTINES;

    DECLARE SUB DOUBLE_BUFFER()
    DECLARE SUB PLOT_BARS()

'   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+.6
    ADD2=ADD2+.3
    ADD3=ADD3+.7
   
    PLOT_BARS()
    DOUBLE_BUFFER()   
   
LOOP UNTIL INKEY$<>""
END


'-------------------------------------------------------------------------------
SUB PLOT_BARS()
   
    DIM AS INTEGER y,c1,c2,c3
   
    C1=60+59*sin(add3*3.14/180)
    C2=60+59*cos(add3*3.14/360)
    C3=60+59*sin(add3*3.14/720)
   
   
    FOR Y=0 TO YRES
       
        SCREEN_R(Y)=120+(C1*SIN((Y-ADD2)*3.14/180))
        SCREEN_G(Y)=120+(C2*COS((Y+ADD2)*3.14/180))
        SCREEN_B(Y)=120+(C3*SIN((Y-ADD1)*3.14/180))
       
    NEXT
   
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))
    NEXT
   
   
    SLEEP 2
END SUB


Shockwave ^ Codigos
Challenge Trophies Won:

gooner

  • Guest
Re: Jerky rastar
« Reply #19 on: July 23, 2008 »
Wow! i like the effect the last time i saw something like this was when i looked through a stain glass window in my my local church on the way home from pub.he he
You probably wont get everything thats going on here but it'll be something else for you to alter and see what happens
Oh well another late night then.Where did i put that corkscrew?

 :D