1 |
greg |
1.1 |
#ifndef lint |
2 |
|
|
static const char RCSid[] = "$Id$"; |
3 |
|
|
#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 |
|
|
#ifdef CPM |
33 |
|
|
fixargs("genflake", &argc, &argv); |
34 |
|
|
#endif |
35 |
|
|
progname = argv[0]; |
36 |
|
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
37 |
|
|
switch (argv[i][1]) { |
38 |
|
|
case 's': /* seed */ |
39 |
|
|
seed = atoi(argv[++i]); |
40 |
|
|
break; |
41 |
|
|
case 'b': /* number of branches */ |
42 |
|
|
branch = atoi(argv[++i]); |
43 |
|
|
break; |
44 |
|
|
case 'n': /* number of flakes */ |
45 |
|
|
nflakes = atoi(argv[++i]); |
46 |
|
|
break; |
47 |
|
|
default: |
48 |
|
|
fprintf(stderr, "%s: unknown option: %s\n", |
49 |
|
|
progname, argv[i]); |
50 |
|
|
exit(1); |
51 |
|
|
} |
52 |
|
|
while (seed-- > 0) |
53 |
|
|
random(); |
54 |
|
|
while (nflakes-- > 0) { |
55 |
|
|
genflake(0, 0, 0, FSIZE, branch); |
56 |
|
|
pglob(PEOP, 0200, NULL); |
57 |
|
|
} |
58 |
|
|
writeof(stdout); |
59 |
|
|
exit(0); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
genflake(x0, y0, x1, y1, nb) /* make a flake */ |
64 |
|
|
int x0, y0, x1, y1; |
65 |
|
|
int nb; |
66 |
|
|
{ |
67 |
|
|
int bx0, by0, bx1, by1; |
68 |
|
|
int i; |
69 |
|
|
|
70 |
|
|
symvect(x0, y0, x1, y1); |
71 |
|
|
for (i = 0; i < nb; i++) { |
72 |
|
|
bx0 = random()%FSIZE; |
73 |
|
|
by0 = y0 + (y1-y0)*(long)bx0/FSIZE; |
74 |
|
|
bx0 = x0 + (x1-x0)*(long)bx0/FSIZE; |
75 |
|
|
bx1 = FACT(y0-y1); |
76 |
|
|
by1 = FACT(x1-x0); |
77 |
|
|
if (random()&1) { |
78 |
|
|
bx1 += (x1-x0)/2; |
79 |
|
|
by1 += (y1-y0)/2; |
80 |
|
|
} else { |
81 |
|
|
bx1 -= (x1-x0)/2; |
82 |
|
|
by1 -= (y1-y0)/2; |
83 |
|
|
} |
84 |
|
|
bx1 = bx0 + bx1*(i+1)/(2*nb); |
85 |
|
|
by1 = by0 + by1*(i+1)/(2*nb); |
86 |
|
|
genflake(bx0, by0, bx1, by1, i); |
87 |
|
|
} |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
|
91 |
|
|
symvect(x0, y0, x1, y1) /* output with symmetry */ |
92 |
|
|
int x0, y0, x1, y1; |
93 |
|
|
{ |
94 |
|
|
symvect2(x0, y0, x1, y1); |
95 |
|
|
symvect2(x0, -y0, x1, -y1); |
96 |
|
|
symvect2(-x0, y0, -x1, y1); |
97 |
|
|
symvect2(-x0, -y0, -x1, -y1); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
symvect2(x0, y0, x1, y1) |
102 |
|
|
int x0, y0, x1, y1; |
103 |
|
|
{ |
104 |
|
|
int x0p, x1p, y0p, y1p; |
105 |
|
|
|
106 |
|
|
plseg(0, CENTER+x0, CENTER+y0, CENTER+x1, CENTER+y1); |
107 |
|
|
plseg(0, CENTER+x0/2+FACT(-y0), CENTER+y0/2+FACT(x0), |
108 |
|
|
CENTER+x1/2+FACT(-y1), CENTER+y1/2+FACT(x1)); |
109 |
|
|
plseg(0, CENTER+x0/2+FACT(y0), CENTER+y0/2+FACT(-x0), |
110 |
|
|
CENTER+x1/2+FACT(y1), CENTER+y1/2+FACT(-x1)); |
111 |
|
|
} |