SetPalette
SetPalette Palette()
 
Parameters:

    Palette() = Set the Palette array
Returns: NONE
 

     The SetPalette command sets the Palette Mappings libraries internal palette pointer to an integer array of your choice. The palette mapping functions work primarly in 16bit so the palette Array must be big enough to hold (2^16)=65336 colour values. Once you've seeded the an array as libraries current palette, you can set the colours by writing values into the palette array.


  
  
; dim the array to hold our colour values
  Dim Palette(65536)
  
; Pointer the internal palette pointer to look
; at the data in Palette() array
  SetPalette(Palette())
  
; fill palette with random colours
  For lp =0 To 65536
     Palette(lp)=RndRGB()
  Next
  
  





FACTS:


      * Warning: If you undim / redim your palette array, you'll need to call SetPalette to reseed the libraries internal pointer. Failure to do so may result in a crash, since the old internal pointer would now be looking at none existant data.




Tutorial



      In this example we're going to create an integer array called Palette(), then fill the first 256 fill it



 
Example Source: Download This Example
  // Include the palette Mapping library
  #Include "PaletteMapping"
  
  
  // -----------------------------------------------------------------
  // -----------------------------------------------------------------
  // Set Up Palette >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  // -----------------------------------------------------------------
  // -----------------------------------------------------------------
  
  // Define a palette big enough to hold 2^16 colours
  Dim Palette($10000)
  
  // Give palette mapping library address of the palette
  // we're using.
  SetPalette(Palette())
  
  // Set Colour Index zero to rgb(0,0,0) BLACK
  Palette(0)     = RGB(0,0,0)
  
  // Set Colour as out 2 as
  Palette(1)     = RGB(30,40,50)
  
  // This number of colours currently in our palette
  ColourCount=2
  
  // Load the Ship image from the media folder to folders down
  ShipImage=LoadNewImage(ProgramDir$()+"Help/Commands/Media/ship.bmp")
  
  
  CenterText 250,80,"ORIGINAL RGB IMAGE"
  DrawImage ShipImage,200,100,false3
  
  // Convert the images normally RGB formated pixels into our
  // current palette
  ColourCount=PaletteMapRGBImage(ShipImage,Palette(), ColourCount)
  CenterText 600,80,"Palette Mapped IMAGE"
  CenterText 600,170,"Colour Count:"+Str$(ColourCount)
  
  DrawImage ShipImage,550,100,false
  
  
  
  Sync
  Wait 1000
  Wait 1000
  
  
  // -----------------------------------------------------------------
  // -----------------------------------------------------------------
  // Create a PB image we'll be using as the Palette Mapped Display
  // -----------------------------------------------------------------
  // -----------------------------------------------------------------
  Screen=NewPaletteMapImage(GetScreenWidth(),GetScreenHeight())
  
  
  Dim BackupPalette($10000)
  CopyArray Palette(),BackUpPalette()
  
  // Limit the program to 75 frames per second or less
  SetFPS 75
  
  
  Do
     
     // direct all Pb rendering to out screen image
     RenderToImage Screen
     
     
     // Fill The Screen with colour index 1.
     // CLS doesn't understand palette mapping, so we have to
     // convert our colur index into RGB form for drawing to
     // the screen
     Cls IndexToRgb(1)
     
     
     // draw our grid of ship images to the screen at the mouses
     // position
     GridImage ShipImage,MouseX(),MouseY(),10,10,true
     
     
     // Draw a rotated version of the palette mapped ship image
     DrawRotatedImage ShipImage,400,300,FadeAngle#,1,1,0,0,true
     
     
     // render our palette mapped screen to the actual screen
     RenderToScreen
     DrawPaletteMapImage(Screen,0,0)
     
     // --------------------------------------
     // Fade palette in and out
     // --------------------------------------
     ScaleLevel=128+Cos(Fadeangle#)*128
     ScaleLevel=ClipRange(ScaleLevel,0,255)
     ShadeRGB=RGB(ScaleLevel,ScaleLevel,ScaleLevel)
     
     For lp =1 To ColourCount
        Palette(lp)=RgbAlphaMult(BackupPalette(lp),ShadeRGB)
     Next
     
     Fadeangle#=WrapAngle(Fadeangle#+1)
     
     
     // show everything to the user
     Sync
  Loop EscKey()=true
  
  
  
  
 
Related Info: CreateFxImageEx | DeleteIMage | DrawPaletteMappedStrip16 | IndexToRGB | PaletteMapRGBImage :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com