-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest5.c
101 lines (89 loc) · 2.4 KB
/
test5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
opencscad : little library to do metaprogramming of OpenSCAD
Copyright (C) 2011 Stephen M. Cameron
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "opencscad.h"
double percent(double n)
{
return (n/100.0 * rand()) / (double) RAND_MAX;
}
void crenelation(double h, double r)
{
onion();
cube(r * 0.25, r * 3.0, h * 0.12, 1);
rotate(90.0, 0.0, 0.0, 1.0);
cube(r * 0.25, r * 3.0, h * 0.12, 1);
endrotate();
rotate(45.0, 0.0, 0.0, 1.0);
cube(r * 0.25, r * 3.0, h * 0.12, 1);
endrotate();
rotate((45.0 + 90.0), 0.0, 0.0, 1.0);
cube(r * 0.25, r * 3.0, h * 0.12, 1);
endrotate();
endonion();
}
void tower(double r, double h)
{
int i;
double h1, r1, angle, nx, ny, nz;
onion();
diff();
cylinder(h, r, r * 0.85);
cylinder(h, r * 0.85, r * 0.75);
enddiff();
xlate(0, 0, h * 0.95);
diff();
onion();
cylinder(h * 0.15, r * 0.85, r * 1.25);
xlate(0, 0, h * 0.12);
diff();
cylinder(h * 0.15, r * 1.25, r * 1.25);
cylinder(h * 0.15 + 1, r * 0.95, r * 0.95);
enddiff();
endxlate();
endonion();
xlate(0, 0, 0.25 * h);
crenelation(h, r);
endxlate();
enddiff();
endxlate();
for (i = 0; i < 5; i++) {
angle = (360.0 * rand()) / RAND_MAX * 3.1415927 / 180.0;
nx = cos(angle) * r * 0.85;
ny = sin(angle) * r * 0.85;
nz = 0.25 * h + (percent(55.0) * h);
r1 = percent(40.0) * r;
h1 = percent(50.0) * h;
if (r1 < 5)
continue;
if (h1 < 20)
continue;
xlate(nx, ny, nz);
tower(r1, h1);
endxlate();
}
xlate(0, 0, -h / 5.0);
cylinder(h / 5.0, r * 0.1, r);
endxlate();
endonion();
}
int main(int argc, char *argv[])
{
opencscad_init();
tower(70.0, 70*5.0);
finalize();
}