Author Topic: Gradient Backdrop  (Read 2854 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Gradient Backdrop
« on: October 04, 2007 »
Heres an example of how you can do gradient backdrops.

Code: [Select]
'
' Gradient Backdrop.
'

Option Static
Option Explicit

#Include Once "Tinyptc.bi"
#Include Once "Windows.bi"

Const XRES=640
Const YRES=480

Const XRES2=XRES/2
Const YRES2=YRES/2

Const PI = 3.141593
Const R2D=(PI/180)

Const ARES=XRES*YRES

Dim Shared ScreenBuffer( ARES )


Declare Sub InitializeExample()

Declare Sub Rect( ByVal xpos  As Integer,_
                  ByVal ypos  As Integer,_
                  ByVal SizeX As Integer,_
                  ByVal SizeY As Integer,_
                  ByVal Col   As integer=&HFFFFFF )

Declare Sub RunExample()



InitializeExample()
RunExample()
Ptc_Close()


Sub InitializeExample()
   
    If( ptc_open( "Gradient Backdrop", XRES, YRES ) = 0 ) Then
End -1                                   
End if

End Sub


Sub Rect( ByVal xpos As Integer, ByVal ypos As Integer, ByVal SizeX As Integer, ByVal SizeY As Integer, ByVal Col As integer=&HFFFFFF )
   
    Dim x,y
   
    For y=0 to SizeY-1
        for x=0 to SizeX-1
       
            ScreenBuffer( ( y+(ypos*SizeY)) * XRES + ( x+(Xpos*SizeX) ) ) = col
     
        Next
    Next
           
End Sub


Sub RunExample()

    Dim Key As String
   
    Dim x, y, Red, Grn, Blu, Col
   
    While Key<>Chr(27)
       
        For Y = 0 To YRES-1
       
            Red=Y*255/XRES
            Grn=0
            Blu=Y*128/XRES
       
            Col=( Red Shl 16 ) Or ( Grn Shl 8 ) Or ( Blu Shl 0 )
       
            Rect ( 0, Y, XRES, 1, Col )

        Next
       
        Ptc_Update @ScreenBuffer(0)
       
        Erase ScreenBuffer
       
        Key=Inkey()
       
    Wend
   
End Sub
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

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: Gradient Backdrop
« Reply #1 on: October 05, 2007 »
Lovely - nice and fast - wicked Clyde!

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

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Gradient Backdrop
« Reply #2 on: October 05, 2007 »
K+ for the nice gradient colours mate :)

Had you thought of using pointers to do this? It can be implimented very quickly and runs a lot faster... Hope you don't mind, I only altered a few lines of code.

Code: [Select]
'
' Gradient Backdrop.
'

Option Static
Option Explicit

#Include Once "Tinyptc.bi"
#Include Once "Windows.bi"

Const XRES=640
Const YRES=480

Const XRES2=XRES/2
Const YRES2=YRES/2

Const PI = 3.141593
Const R2D=(PI/180)

Const ARES=XRES*YRES

Dim Shared ScreenBuffer( ARES )


Declare Sub InitializeExample()

Declare Sub Rect( ByVal xpos  As Integer,_
                  ByVal ypos  As Integer,_
                  ByVal SizeX As Integer,_
                  ByVal SizeY As Integer,_
                  ByVal Col   As integer=&HFFFFFF )

Declare Sub RunExample()



InitializeExample()
RunExample()
Ptc_Close()


Sub InitializeExample()
   
    If( ptc_open( "Gradient Backdrop", XRES, YRES ) = 0 ) Then
End -1                                   
End if

End Sub


Sub Rect( ByVal xpos As Integer, ByVal ypos As Integer, ByVal SizeX As Integer, ByVal SizeY As Integer, ByVal Col As integer=&HFFFFFF )
   
    Dim x,y
    dim as uinteger ptr pp1
   
    For y=0 to SizeY-1
       
        pp1=@screenbuffer( ( y+(ypos*SizeY)) * XRES + ( x+(Xpos*SizeX) ) )
       
        for x=0 to SizeX-1
           
            *pp1 = col
             pp1+=1   
             
        Next
    Next
           
End Sub


Sub RunExample()

    Dim Key As String
   
    Dim x, y, Red, Grn, Blu, Col
   
    While Key<>Chr(27)
       
        For Y = 0 To YRES-1
       
            Red=Y*255/XRES
            Grn=0
            Blu=Y*128/XRES
       
            Col=( Red Shl 16 ) Or ( Grn Shl 8 ) Or ( Blu Shl 0 )
       
            Rect ( 0, Y, XRES, 1, Col )

        Next
       
        Ptc_Update @ScreenBuffer(0)
       
        Erase ScreenBuffer
       
        Key=Inkey()
       
    Wend
   
End Sub
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Gradient Backdrop
« Reply #3 on: October 05, 2007 »
Thanks DrewPee and Shockwave :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: