Function:s2scr

From S2PLOT

(Difference between revisions)
Jump to: navigation, search

Current revision

s2scr

Set colour representation, ie. define a colour associated with an index.

Prototype

void s2scr(int idx, float r, float g, float b);

Description

Set colour representation associated with index idx. Once defined this colour can be selected and used. The default colours (indices 0..15) can be redefined.

Note that for historical reasons, the variable type (float) used in setting and querying the colour index is not the same as the variable type of the COLOUR data structure (double).

See Also

s2sci Set the pen colour by index.
s2scir Set the range of colour indices used for shading.

PGPLOT Equivalent

PGSCR

Code Example

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "s2plot.h"

int main(int argc, char *argv[])
{
   int i;					/* Loop variable */
   int N = 50;					/* Number of points */
   float x[50], y[50], z[50];			/* Coordinates of points */
   float r, g, b;				/* RGB colours */
   int symbol = 1;				/* Point symbol */
   int offset = 32;				/* Starting colour */

   srand48((long)time(NULL));			/* Seed random numbers */
   for (i=0;i<N;i++) {
      x[i] = drand48()*2.0 - 1.0;
      y[i] = drand48()*2.0 - 1.0;
      z[i] = drand48()*2.0 - 1.0;
   }

   s2opend("/?",argc, argv);			/* Open the display */
   s2swin(-1.,1., -1.,1., -1.,1.);		/* Set the window coordinates */
   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);	/* Draw coordinate box */

   s2slw(5);					/* Sets size of point */
   s2scir(offset, offset+N);			/* Set the colour index range */
   for (i=offset;i<(offset+N);i++) {
      r = drand48();				/* Choose random red value */
      g = r;					/* Green = Blue = Red */ 
      b = r;					/*  means grey-scale! */
      s2scr(i, r, g, b);			/* Set colour representation */
   }
   
   for (i=0;i<N;i++) {
      s2sci(offset+i);				/* Set the colour */
      s2pt1(x[i],y[i],z[i],symbol);		/* Draw a single point */
   }
   s2show(1);					/* Open the s2plot window */
   
   return 1;
}

Back to S2PLOT function list.


Personal tools