Function:ns2line

From S2PLOT

(Difference between revisions)
Jump to: navigation, search

Revision as of 01:32, 30 October 2007

ns2line

Draw a line from one point to another in a specific colour.

Prototype

void ns2line(float x1, float y1, float z1, float x2, float y2, float z2, float red, float green, float blue);

Description

Draw a line from (x1,y1,z1) to (x2,y2,z2) using RGB colour (red,green,blue).

See Also

ns2vline Draw a line from one point to another in a specific colour - vector input.
ns2thline Draw a thick line from one point to another in a specific colour.
ns2vthline Draw a thick line from one point to another in a specific colour - vector input.
ns2cline Draw a coloured line, with colour blended between the two given colours along the line.
ns2vcline Draw a coloured line, with colour blended between the two given colours along the line - vector input.


Code Example

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

int main(int argc, char *argv[])
{
   float x1, y1, z1;				/* Start of line */
   float x2, y2, z2;				/* End of line */
   float r, g, b;				/* Colour of line segment */
   int N = 10;					/* Number of lines */
   int i;					/* Loop variable */

   srand48((long)time(NULL));			/* Seed random numbers */
   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 */

   s2sci(S2_PG_YELLOW);				/* Set colour */
   for (i=0;i<N;i++) {
      x1 = drand48()*2.0 - 1.0;			/* Random (x,y,z) coordinates */
      y1 = drand48()*2.0 - 1.0;
      z1 = drand48()*2.0 - 1.0;
      x2 = drand48()*2.0 - 1.0;			/* Random (x,y,z) coordinates */
      y2 = drand48()*2.0 - 1.0;
      z2 = drand48()*2.0 - 1.0;
      r  = drand48();
      g  = drand48();
      b  = drand48();
      ns2line(x1,y1,z1, x2,y2,z2, r,g,b);	/* Draw the line */
   }

   s2show(1);					/* Open the s2plot window */
   
   return 1;
}

Back to S2PLOT function list.


Personal tools