Author Topic: Jerky rastar  (Read 7595 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Jerky rastar
« Reply #20 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 :)
Shockwave ^ Codigos
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 #21 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
Shockwave ^ Codigos
Challenge Trophies Won:

gooner

  • Guest
Re: Jerky rastar
« Reply #22 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

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Jerky rastar
« Reply #23 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?
Shockwave ^ Codigos
Challenge Trophies Won:

gooner

  • Guest
Re: Jerky rastar
« Reply #24 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                         

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 #25 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
« Last Edit: July 23, 2008 by rain_storm »

Challenge Trophies Won:

gooner

  • Guest
Re: Jerky rastar
« Reply #26 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: