Function:s2qcr

From S2PLOT

Revision as of 08:37, 27 October 2007; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

s2qcr

Query colour representation.

Prototype

void s2qcr(int idx, float *r, float *g, float *b);

Description

Query colour representation, ie. obtain the red, green and blue components of the given colour index.

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.
s2scr Set colour representation, ie. define a colour associated with an index.
struct_COLOUR Data structure for (r,g,b) colour indices.

PGPLOT Equivalent

PGQCR

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++) {
      s2qcr(offset+i, &r, &g, &b);		/* Query colour representation */
      s2scr(offset+i, r, 1.0, g);		/* Make it greenish */
      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