[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 for AIX: Graphics Library (GL) Technical Reference

## doily.c Example C Language Program

```/*
doily.c:```
```Draws a doily depending on how many points you give
it (range is
currently set between 3..100).  point count is equivale
nt to how
many line segments make up the circle's edge.
*/```
```#include <gl/gl.h>
#include <gl/device.h>
#include <math.h>```
`#define PI 3.1415926535`
`float points;`
```main(argc, argv)
int argc;
char *argv[];
{```
```  int val,dev;
long numpts;            /* First figure out how many points there are. */```
```  if (argc != 2) {
printf("Usage: %s <point_count>\n", argv);
exit(0);
}```
```  numpts = atoi(argv); /* convert argument to internal format */
if (numpts > 100) {
printf("Too many points\n");
exit(0);
}
else if (numpts < 3) {
printf("Too few points\n"); exit(0);
}```
```  initialize(numpts);
while (TRUE) {
if (qtest()) {
if (dev == ESCKEY) {
gexit();
exit(0);
}
else if (dev == REDRAW) {
reshapeviewport();
drawdoily(numpts);
}
}
}```
`}`
```initialize(numpts)
long numpts;
{```
```  int gid;
long i;    /* Now get the x and y coordinates of numpts equally-
* spaced points around the unit circle.
*/
for (i = 0; i < numpts; i++) {```
```    points[i] = cos((i*2.0*PI)/numpts);
points[i] = sin((i*2.0*PI)/numpts);
}
keepaspect(1,1);
prefposition(XMAXSCREEN/4,XMAXSCREEN*3/4,YMAXSCREEN/4,
YMAXSCREEN*3/4);
gid = winopen("doily");
qdevice(ESCKEY);
qdevice(REDRAW);
qenter(REDRAW,gid);
ortho2(-1.2, 1.2, -1.2, 1.2);```
`}`
```drawdoily(numpts)
long numpts;
{```
`  long i,j;    `
```  color(BLACK);
clear();
color(RED);
for (i = 0; i < numpts; i++)
for (j = i+1; j < numpts; j++) {
move2(points[i], points[i]);
draw2(points[j], points[j]);
}```
`}`
```/*
Changes:
- exit(); to exit(1);
*/```

### Related Information

The keepaspect subroutine, prefposition subroutine.

[ Previous | Next | Contents | Glossary | Home | Search ]