Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: gooner on July 15, 2008

Title: Jerky rastar
Post by: gooner 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
 :)
Title: Re: Jerky rastar
Post by: rain_storm 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?
Title: Re: Jerky rastar
Post by: gooner 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
Title: Re: Jerky rastar
Post by: Jim on July 15, 2008
Seems to run smoothly here - I suspect possibly you have hit some limit on your PC?

Jim
Title: Re: Jerky rastar
Post by: DrewPee on July 15, 2008
Works smooth here to dude! nice work!

Andy
Title: Re: Jerky rastar
Post by: gooner on July 15, 2008
Thanks for your feedback chaps it must be my labtop i'm using or my dodgy eyes
 ;)
Title: Re: Jerky rastar
Post by: Clyde on July 15, 2008
Looking good welldone.
Title: Re: Jerky rastar
Post by: gooner 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  :)
Title: Re: Jerky rastar
Post by: Clyde 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.
Title: Re: Jerky rastar
Post by: gooner on July 15, 2008
Thanks for the tip mate i give that a try before zzz.
 O0 :cheers:
Title: Re: Jerky rastar
Post by: rain_storm 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.
Title: Re: Jerky rastar
Post by: gooner 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

 :)
Title: Re: Jerky rastar
Post by: rain_storm on July 16, 2008
Thats much nicer. great choice of colours the colours I used were crap compared to that
Title: Re: Jerky rastar
Post by: Shockwave 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 :)

Title: Re: Jerky rastar
Post by: gooner 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  :)
Title: Re: Jerky rastar
Post by: Shockwave 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
Title: Re: Jerky rastar
Post by: Xalthorn 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.
Title: Re: Jerky rastar
Post by: gooner 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:
Title: Re: Jerky rastar
Post by: Shockwave 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


Title: Re: Jerky rastar
Post by: gooner 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
Title: Re: Jerky rastar
Post by: Shockwave on July 23, 2008
Your challenge for tonight is to go through that listing and make a new topic asking what every part of it that you don't understand 100% does and to keep asking until you understand it all :)
Title: Re: Jerky rastar
Post by: Shockwave on July 23, 2008
Pick the bones out of this too :)

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()
    DECLARE SUB DRAW_BAR(BYVAL BARPOS AS INTEGER)

    DIM SHARED AS DOUBLE ADD1,ADD2,ADD3
   
    DIM SHARED AS INTEGER SCREEN_Y(YRES) 
   
'-------------------------------------------------------------------------------   
' MAIN LOOP; 
'-------------------------------------------------------------------------------
DO
   'MOVE BARS;
    ADD1=ADD1+.6
    ADD2=ADD2+1.3
    ADD3=ADD3+.7
   
    PLOT_BARS()
    DOUBLE_BUFFER()   
   
LOOP UNTIL INKEY$<>""
END


'-------------------------------------------------------------------------------
SUB DRAW_BAR(BYVAL BARPOS AS INTEGER)
    DIM AS INTEGER L,C
    C=0
    FOR L=BARPOS TO BARPOS+31
        SCREEN_Y(L)=RGB(C,C,C)
        C=C+8
    NEXT
    FOR L=BARPOS+32 TO BARPOS+63
        C=C-8
        SCREEN_Y(L)=RGB(C,C,C)       
    NEXT   
   
END SUB

SUB PLOT_BARS()
    DIM AS INTEGER F
   
    FOR F=1 TO 500 STEP 20
    DRAW_BAR(200+(100*SIN((F+ADD1)*3.14/180))-(40*COS((F+ADD2)*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),SCREEN_Y(Y)
    NEXT
   
   
    SLEEP 2
END SUB
Title: Re: Jerky rastar
Post by: gooner on July 23, 2008
Lets start with the first challenge then
Quote
' RASTER BARS!
'

OPTION EXPLICIT


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

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

'   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) RED
    DIM SHARED AS INTEGER SCREEN_G(YRES) GREEN
    DIM SHARED AS INTEGER SCREEN_B(YRES) BLUE
 
' MAIN LOOP; 
DO
   'MOVE BARS;
    ADD1=ADD1+.6WHAT EFFECT DO THESES HAVE?
    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)NOT A BETTY BOO
    C2=60+59*cos(add3*3.14/360)
    C3=60+59*sin(add3*3.14/720)
   
   
    FOR Y=0 TO YRES, 0 TO 480
       
        SCREEN_R(Y)=120+(C1*SIN((Y-ADD2)*3.14/180))NOT A SCOOBY
        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)) KNOW THE LINE BIT  NOT SURE ABOUT THE BIT AFTER RGB
    NEXT
   
   
    SLEEP 2
END SUB
Right the comments in red i understand ,if i haven't commented i also understand,the  comments in lime green i need some explanations please.

thanks goon
 :P
Title: Re: Jerky rastar
Post by: Shockwave on July 23, 2008
    ADD1=ADD1+.6WHAT EFFECT DO THESES HAVE?
    ADD2=ADD2+.3
    ADD3=ADD3+.7

ADD1, ADD2,ADD3 are variables and they are "doubles" That means that they can hold numbers containing a decimal point which means that we can add very small amounts to them.
This is useful when we want to use things like sin and cos which might need a fraction of a degree added to them to get a nice movement :)



    C1=60+59*sin(add3*3.14/180)NOT A BETTY BOO
    C2=60+59*cos(add3*3.14/360)
    C3=60+59*sin(add3*3.14/720)

The important things here are SIN and COS

Both these commands have one thing in common, they return a number between -1 and +1 depending on what angle (the math jargon is theta) that you give it.
So..
X=sin(100) will put a number somewhere between -1 and +1 in x, this will change according to the number in the brackets.
Sin and Cos are trig functions, as a default they use something called radians.
We tend to think of angles in degrees.
To convert a radian into a degree;

angle = radian multiplied by pi divided by 180

Pi is about 3.14
so..

add3*3.14/180

Turns the radian "add3" into a degree

Bear in mind that the values from these calculations are stored in C1,C2,C3

Anyway..

We're talking about waveforms here, COS (or cosine) is inverse sine

X = RADIUS * SIN (THETA)
Y = RADIUS * COS (THETA)

Where theta ranges between 0 and 359 ( for THETA = 0 TO 359 )

Will actually plot a circle :)

All you need to know at this stage is that you can use sin and cos to make a nice number that bounces smoothly within a range!

Y= 100*SIN(ANGLE)

Because you are multiplying it by 100, remember sin returns -1 to +1 you increase this range to -100 and +100 ;)

Since -100 is off the screen, you can add 100 on to make the range between 0 and 200

Y= 100+(100*SIN(ANGLE))

Remember that expressions inside the brackets are evaluated first :)


    SCREEN_R(Y)=120+(C1*SIN((Y-ADD2)*3.14/180))NOT A SCOOBY
    SCREEN_G(Y)=120+(C2*COS((Y+ADD2)*3.14/180))
    SCREEN_B(Y)=120+(C3*SIN((Y-ADD1)*3.14/180))


SCREEN_R(Y) etc..

These are arrays. are you ok with arrays or do you need more practice?
Title: Re: Jerky rastar
Post by: gooner on July 23, 2008
Cheers for that Shockmeister i will print your explanations off i've got a feeling i might be refering back to it quite a bit.
Quote
C1=60+59*sin(add3*3.14/180)
    C2=60+59*cos(add3*3.14/360)  .
    C3=60+59*sin(add3*3.14/720)
                                               
        The numbers on the end  ie 180,360,720 seem to double themselves. Is there any reason for this and what effect do they have
                                                         
Quote
These are arrays. are you ok with arrays or do you need more practice?

Yes
 :o                         
Title: Re: Jerky rastar
Post by: rain_storm on July 23, 2008
Okay some trig basics a radian is another way of measuring angles, humans normally measure angles in degrees. There are 360 degress because the number 360 will divide nicely into many numbers (2,3,4,5,6,10,12,15,20,30,45,60,90,180, etc) but the true natural angle is measured in radians, A radian is equal to the ammount of distance along the circumference of a circle that will be covered by the distance of the radius (radians = radius as an angle). Pi is the number of DIAMETERS that are required to cover the distance of the entire circumference of a circle ie diameter*3.14
Code: [Select]
circumference = 2*pi*radius
is the exact same as
Code: [Select]
circumference = pi*diameter
so to convert any angle from radians to degrees you must first multiply the angle in radians by 2*pi then divide by 360. remember that pi = number of diameters in a circle but radians are measured in radius not diameter so its 2*pi instead of *pi. raidans*2*pi/360 can be optimised to radians*pi/180 you can play around with the numbers to give you greater control. This is a heavy explaination but for now you can just take it as a given that radians*pi/180 will convert radians to degrees



As for arrays. well you know what a variable is, an array is similar but with variables you assign one name for one item of data. An array allows you to assign a single name to many items of data. The number of items in the array is specified when the array is declared.

Code: [Select]
DIM SHARED AS INTEGER SCREEN_R(YRES) RED
Here an array is declared with the name SCREEN_R. This array contains an ammount of data items equal to YRES

Now to access a single item within the array you must specify that items index. You can do this with a hardcoded value
Code: [Select]
someVariable = SCREEN_R(1)

but it is much better to assign a variable that will be used as the index this allows arrays to be used easily in loops
Code: [Select]
For index = 1 to ArraySize
someVariable = SCREEN_R(index)
Next
This for next loop accesses every data item in the array using the for next loop counter (index) as the index into the array
Title: Re: Jerky rastar
Post by: gooner on July 24, 2008
Rain that is a perfect explanation for me to understand.I knew pi was 22 divided by 7
i just didn't realise the relevance of them in circles.As for arrays i probably knew what they were i just didn't distingish between between a variable and an arrray but i've got it now.You deserve several pints of Murphys but you'll have to settle for karma+ for now.Thanks a lot mate
 :cheers: