Ooops
March 01, 2021, 11:08:54 PM

Author Topic: [bb] Gradient Fill Image by Grey Alien [ 1+ years ago ]  (Read 417 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Gradient Fill Image by Grey Alien [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : Gradient Fill Image
Author : Grey Alien
Posted : 1+ years ago

Description : This code can be used to gradient fill and image from top to bottom.

Code :
Code: BlitzBasic
  1. ; -----------------------------------------------------------------------------
  2. ; ccGradientFill
  3. ; -----------------------------------------------------------------------------
  4. Function ccGradientFill(Temp%, SourceCol%, StartCol%, EndCol%)
  5.         ;temp is an image
  6.         ;-1 ($ffffffff) is white (good for sourcecol)
  7.         SetBuffer ImageBuffer(Temp)
  8.         LockBuffer ImageBuffer(Temp)
  9.  
  10.         Local x
  11.         Local y#
  12.         Local col = 0
  13.        
  14.         For y = 0 To ImageHeight(Temp)-1
  15.                 col = ccBlendColours(StartCol, EndCol, y/ImageHeight(Temp))
  16.                 For x = 0 To ImageWidth(Temp)-1
  17.                         r = ReadPixelFast(x, y)        
  18.                         If r = SourceCol Then                          
  19.                                 WritePixelFast(x, y, col)
  20.                         EndIf
  21.                 Next
  22.         Next
  23.        
  24.         UnlockBuffer ImageBuffer(Temp)
  25.  
  26.         ;don't reset buffer, calling proc must do it if it wants to.
  27. End Function
  28.  
  29. ; -----------------------------------------------------------------------------
  30. ; ccBlendColours
  31. ; -----------------------------------------------------------------------------
  32. Function ccBlendColours%(st%, en%, ratio#)
  33.         ;use RGB values adjusted with ARGB_Black
  34.         ;ratio# must be 0 to 1
  35.         Rst = (st Shr 16) And 255
  36.         Gst = (st Shr 8 ) And 255
  37.         Bst = st And 255               
  38.  
  39.         Ren = (en Shr 16) And 255
  40.         Gen = (en Shr 8 ) And 255
  41.         Ben = en And 255               
  42.                        
  43.         Rdiff=  Rst-Ren
  44.         Gdiff=  Gst-Gen
  45.         Bdiff=  Bst-Ben
  46.  
  47.         Rdiff = Rdiff * ratio#
  48.         Gdiff = Gdiff * ratio#
  49.         Bdiff = Bdiff * ratio#
  50.                        
  51.         Return (((Rst-Rdiff) Shl 16) Or ((Gst-Gdiff) Shl 8) Or (Bst-Bdiff))                            
  52. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal