Function:s2qlw

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 02:25, 23 November 2007
S2plot admin (Talk | contribs)

← Previous diff
Current revision
S2plot admin (Talk | contribs)

Line 18: Line 18:
==Code Example== ==Code Example==
<code><pre> <code><pre>
-#include <stdio.h>+include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
 +#include <time.h>
#include "s2plot.h" #include "s2plot.h"
Line 27: Line 28:
if (lkc != *kc) { /* Space bar pressed? */ if (lkc != *kc) { /* Space bar pressed? */
- s2slw(drand48()*10+1); /* Choose random linewidth */+ //s2slw(drand48()*10+1); /* Choose random linewidth */
 + s2slw((float)rand() / (float)RAND_MAX * 10. + 1.);
} }
int qlw = s2qlw(); /* Query line width */ int qlw = s2qlw(); /* Query line width */
- char string[32]; + char string[32];
sprintf(string,"line width = %d",qlw); /* Write to string */ sprintf(string,"line width = %d",qlw); /* Write to string */
s2textxy(0,0,0,string); /* Display text */ s2textxy(0,0,0,string); /* Display text */
int N = 2; /* Number of points in line */ int N = 2; /* Number of points in line */
- float x[2], y[2], z[2]; + float x[2], y[2], z[2];
x[0] = -0.8; y[0] = -0.4; z[0] = 0.0; /* Coordinates of line */ x[0] = -0.8; y[0] = -0.4; z[0] = 0.0; /* Coordinates of line */
x[1] = +0.8; y[1] = -0.4; z[1] = 0.0; x[1] = +0.8; y[1] = -0.4; z[1] = 0.0;
Line 48: Line 50:
fprintf(stderr,"Press the <spacebar> to change line width"); fprintf(stderr,"Press the <spacebar> to change line width");
 + srand48((long)time(NULL)); /* Seed random numbers */
s2opend("/s2mono", argc, argv); /* Open in mono mode */ s2opend("/s2mono", argc, argv); /* Open in mono mode */
s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */ s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */ s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
- + 
cs2scb(cb); /* Install dynamic callback */ cs2scb(cb); /* Install dynamic callback */
s2show(1); /* Open the s2plot window */ s2show(1); /* Open the s2plot window */
Line 57: Line 60:
return 1; return 1;
} }
 +
</pre></code> </pre></code>
[[S2PLOT:Function List | Back]] to S2PLOT function list. [[S2PLOT:Function List | Back]] to S2PLOT function list.
__NOTOC__ __NOTOC__
__NOEDITSECTION__ __NOEDITSECTION__

Current revision

s2qlw

Query the line width.

Prototype

int s2qlw(void);

Description

Query the line width.

See Also

s2slwSet the line width

Code Example

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

void cb(double *t, int *kc)
{
   static int lkc = 0;                          /* Count of key presses */

   if (lkc != *kc) {                            /* Space bar pressed? */
     //s2slw(drand48()*10+1);                   /* Choose random linewidth */
     s2slw((float)rand() / (float)RAND_MAX * 10. + 1.);
   }

   int qlw = s2qlw();                           /* Query line width */
   char string[32];
   sprintf(string,"line width = %d",qlw);       /* Write to string */
   s2textxy(0,0,0,string);                      /* Display text */

   int N = 2;                                   /* Number of points in line */
   float x[2], y[2], z[2];
   x[0] = -0.8; y[0] = -0.4; z[0] = 0.0;        /* Coordinates of line */
   x[1] = +0.8; y[1] = -0.4; z[1] = 0.0;
   s2line(N, x, y, z);                          /* Draw the line */

   lkc = *kc;                                   /* Update count */
}

int main(int argc, char *argv[])
{
   fprintf(stderr,"Press the <spacebar> to change line width");

   srand48((long)time(NULL));                   /* Seed random numbers */
   s2opend("/s2mono", argc, argv);              /* Open in mono mode */
   s2swin(-1.,1., -1.,1., -1.,1.);              /* Set the window coordinates */
   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);  /* Draw coordinate box */

   cs2scb(cb);                                  /* Install dynamic callback */
   s2show(1);                                   /* Open the s2plot window */

   return 1;
}

Back to S2PLOT function list.