Changing The 16 Standard Colors


If you aren't happy with the 16 standard colors that Pro-SiMPLE provides, you can use the setrgbpalette function in C++ to change them to 16 colors of your own choosing.

The following listing is an illustration of how you might create a task that changes all the palette colors (except for black) to a "rainbow" selection of colors:

   Task new palette
   Common Int r[]={0,63,63,63,63,63,47,31,31,47,47,47,55,59,59,63}
   Common Int g[]={0,31,39,47,55,63,63,63,55,47,39,31,31,31,31,31}
   Common Int b[]={0,31,31,31,31,31,31,31,47,63,63,63,63,63,52,42}
   graph on
   Do i=1,15
      +setpalette (i_, i_);
      +setrgbpalette (i_, r_[i_], g_[i_], b_[i_]);
   Loop
To try out the newpalette task, let's write a program that will first display an image in the 16 Standard colors. Then, after delaying for about a second, it will switch to the new palette colors:
   Pro-SiMPLE
   real=-0.77195; imag=-0.116
   incr=0.0000025
   Do y=0,479
      r=real
      Do x=0,639
         color=mandelbrot (r, imag, 256)
         If (color!=256) color=1+color%15
         point color (color); plot (x, y)
         r=r+incr
      Loop
      imag=imag+incr
   Loop
   delay (1000)
   new palette @
   delay (1000)



"Animating" The New Color Palette

After you have established a new set of colors in the palette, it is possible to create some interesting animation effects simply by continually incrementing (or decrementing) each color entry to be that of its neighbor, as is shown in the following task. [The delta calling parameter specifies whether the colors are to be cycled forward (+1) or backward (-1) through the palette.]

   Task cycle colors (Int delta)
   Common Int offset=0
   lo=1; hi=15
   If delta>0
      lo=15; hi=1
   Endif
   flushkbd
   Do
      read quitkey
      offset=cycle (offset+delta, 15)
      Do k=lo,hi
         color=1+(k+offset-1)%15
         +setpalette (k_, color_);
      Loop
      delay (50)
   Loop
To use this task to animate the spiral image that our previous program generates, simply include a "cyclecolors(-1)@" statement at the very end of the program. (The animation will continue until any key is pressed.)


"Animating" The Standard Color Palette

Suppose you are happy with the original 16 Standard colors. Can you just invoke the cyclecolors task to animate them? Unfortunately, no. (Actually, you can. But some of the colors will appear slightly darker than they should.) To remedy the problem, simply invoke the following systempalette task to set the original system colors as the "new" ones to be used in the palette:

   Task system palette
   Common Int r[]={0,0,0,0,2,2,2,2,1,1,1,1,3,3,3,3}
   Common Int g[]={0,0,2,2,0,0,1,2,1,1,3,3,1,1,3,3}
   Common Int b[]={0,2,0,2,0,2,0,2,1,3,1,3,1,3,1,3}
   graph on
   Do i=0,15
      +setpalette (i_, i_);
      +setrgbpalette (i_, 21*r_[i_], 21*g_[i_], 21*b_[i_]);
   Loop
Then the cyclecolors task will work just fine for animating the 16 Standard colors. (You can also use the systempalette task to restore the Standard colors back into the palette if you should ever need to do so.)

The following example program draws a series of concentric solid circles (in the Standard 16 colors), and then "animates" them:

   Pro-SiMPLE
   Do r=240,10,-10
      solid color (1+(r/10)%15)
      solid circle (320, 240, r)
   Loop
   system palette @
   cycle colors (-1) @



  [ Webmaster | FAQ's | Home Page | Contact Us ]