| 1 |
greg |
1.1 |
#ifndef lint |
| 2 |
greg |
1.3 |
static const char RCSid[] = "$Id: genflake.c,v 1.2 2003/08/01 14:14:24 schorsch Exp $"; |
| 3 |
greg |
1.1 |
#endif |
| 4 |
|
|
/* |
| 5 |
|
|
* genflake.c - program to make snowflakes |
| 6 |
|
|
* |
| 7 |
|
|
* 11/12/86 |
| 8 |
|
|
* |
| 9 |
|
|
* cc genflake.c primout.o mfio.o syscalls.o misc.o |
| 10 |
|
|
*/ |
| 11 |
|
|
|
| 12 |
|
|
#include "meta.h" |
| 13 |
|
|
|
| 14 |
|
|
#include "random.h" |
| 15 |
|
|
|
| 16 |
|
|
#define FSIZE 6144 |
| 17 |
|
|
#define FACT(a) (int)((a)*5321L/FSIZE) |
| 18 |
|
|
#define CENTER 8192 |
| 19 |
|
|
|
| 20 |
|
|
char *progname; |
| 21 |
|
|
|
| 22 |
|
|
int branch = 6; /* number of branches */ |
| 23 |
|
|
|
| 24 |
|
|
main(argc, argv) |
| 25 |
|
|
int argc; |
| 26 |
|
|
char *argv[]; |
| 27 |
|
|
{ |
| 28 |
|
|
int i; |
| 29 |
|
|
int seed = 0; |
| 30 |
|
|
int nflakes = 1; |
| 31 |
|
|
|
| 32 |
|
|
progname = argv[0]; |
| 33 |
|
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 34 |
|
|
switch (argv[i][1]) { |
| 35 |
|
|
case 's': /* seed */ |
| 36 |
|
|
seed = atoi(argv[++i]); |
| 37 |
|
|
break; |
| 38 |
|
|
case 'b': /* number of branches */ |
| 39 |
|
|
branch = atoi(argv[++i]); |
| 40 |
|
|
break; |
| 41 |
|
|
case 'n': /* number of flakes */ |
| 42 |
|
|
nflakes = atoi(argv[++i]); |
| 43 |
|
|
break; |
| 44 |
|
|
default: |
| 45 |
|
|
fprintf(stderr, "%s: unknown option: %s\n", |
| 46 |
|
|
progname, argv[i]); |
| 47 |
|
|
exit(1); |
| 48 |
|
|
} |
| 49 |
|
|
while (seed-- > 0) |
| 50 |
|
|
random(); |
| 51 |
|
|
while (nflakes-- > 0) { |
| 52 |
|
|
genflake(0, 0, 0, FSIZE, branch); |
| 53 |
|
|
pglob(PEOP, 0200, NULL); |
| 54 |
|
|
} |
| 55 |
|
|
writeof(stdout); |
| 56 |
|
|
exit(0); |
| 57 |
|
|
} |
| 58 |
|
|
|
| 59 |
|
|
|
| 60 |
|
|
genflake(x0, y0, x1, y1, nb) /* make a flake */ |
| 61 |
|
|
int x0, y0, x1, y1; |
| 62 |
|
|
int nb; |
| 63 |
|
|
{ |
| 64 |
|
|
int bx0, by0, bx1, by1; |
| 65 |
|
|
int i; |
| 66 |
|
|
|
| 67 |
|
|
symvect(x0, y0, x1, y1); |
| 68 |
|
|
for (i = 0; i < nb; i++) { |
| 69 |
|
|
bx0 = random()%FSIZE; |
| 70 |
|
|
by0 = y0 + (y1-y0)*(long)bx0/FSIZE; |
| 71 |
|
|
bx0 = x0 + (x1-x0)*(long)bx0/FSIZE; |
| 72 |
|
|
bx1 = FACT(y0-y1); |
| 73 |
|
|
by1 = FACT(x1-x0); |
| 74 |
|
|
if (random()&1) { |
| 75 |
|
|
bx1 += (x1-x0)/2; |
| 76 |
|
|
by1 += (y1-y0)/2; |
| 77 |
|
|
} else { |
| 78 |
|
|
bx1 -= (x1-x0)/2; |
| 79 |
|
|
by1 -= (y1-y0)/2; |
| 80 |
|
|
} |
| 81 |
|
|
bx1 = bx0 + bx1*(i+1)/(2*nb); |
| 82 |
|
|
by1 = by0 + by1*(i+1)/(2*nb); |
| 83 |
|
|
genflake(bx0, by0, bx1, by1, i); |
| 84 |
|
|
} |
| 85 |
|
|
} |
| 86 |
|
|
|
| 87 |
|
|
|
| 88 |
|
|
symvect(x0, y0, x1, y1) /* output with symmetry */ |
| 89 |
|
|
int x0, y0, x1, y1; |
| 90 |
|
|
{ |
| 91 |
|
|
symvect2(x0, y0, x1, y1); |
| 92 |
|
|
symvect2(x0, -y0, x1, -y1); |
| 93 |
|
|
symvect2(-x0, y0, -x1, y1); |
| 94 |
|
|
symvect2(-x0, -y0, -x1, -y1); |
| 95 |
|
|
} |
| 96 |
|
|
|
| 97 |
|
|
|
| 98 |
|
|
symvect2(x0, y0, x1, y1) |
| 99 |
|
|
int x0, y0, x1, y1; |
| 100 |
|
|
{ |
| 101 |
|
|
int x0p, x1p, y0p, y1p; |
| 102 |
|
|
|
| 103 |
|
|
plseg(0, CENTER+x0, CENTER+y0, CENTER+x1, CENTER+y1); |
| 104 |
|
|
plseg(0, CENTER+x0/2+FACT(-y0), CENTER+y0/2+FACT(x0), |
| 105 |
|
|
CENTER+x1/2+FACT(-y1), CENTER+y1/2+FACT(x1)); |
| 106 |
|
|
plseg(0, CENTER+x0/2+FACT(y0), CENTER+y0/2+FACT(-x0), |
| 107 |
|
|
CENTER+x1/2+FACT(y1), CENTER+y1/2+FACT(-x1)); |
| 108 |
|
|
} |