-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscadfile.scad.template
158 lines (125 loc) · 4.31 KB
/
scadfile.scad.template
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//================================
// Music Box Cylinder Generator
//================================
//
// Originally developed by gsyan ( https://gsyan888.blogspot.com/ )
// Refactor & fixes by PashaWNN ( https://github.com/PashaWNN )
/* [Global] */
/* [Direction Setting] */
// Bass pin is on the top (near the gear)
isTopFirst = true;
// Cylinder rotate direction
isCounterclockwise = true;
/* [Cylinder Size Setting] */
cylinderDiameter = 13;
cylinderThickness = 0.6;
cylinderHeight = 20;
/* [Internal Structure Settings] */
// Hollow, solid or ribbed cylinder
internalStructureType = "${internalStructureType}"; // [HOLLOW, RIBS, SOLID]
// Width of the rib (only for internalStructureType = ribs)
ribWidth = 1.0;
// Internal structure height delta (how much of the top is hollow)
structureHeightDelta = 4.0;
// Cylinder diameter tolerance
cylinderTolerance = 0.1;
/* [Combo Teeth Setting] */
teethTotalNumber = 18;
/* [Pins Size Setting] */
pinDiameter = 0.4;
pinBaseDiameter = 0.8;
pinHeight = 0.6;
// The distance between two pins
pinOffset = 0.9;
rOffset = 0.3; // How deep pins would protrude the cylinder
// The position of the first pin
firstPinPosition = 1.9 + pinBaseDiameter / 4;
/* [Cylinder Bottom Setting] */
cylinderBottomDiameter = 15.3;
cylinderBottomHeight = 1;
cylinderBottomHoleD1 = 5.4;
cylinderBottomHoleD2 = 4;
/* [Cylinder Top Lock Hole Setting] */
cylinderTopHoleWidth = 3.6;
cylinderTopHoleHeight = 1;
musicScore = ${musicScore};
/* [Hidden] */
// Total number of tones
tonesTotalNumber = 18;
module rib() {
ribLength = cylinderDiameter - cylinderTolerance - cylinderThickness;
difference() {
translate([-ribLength / 2, -ribWidth / 2, 0])
cube([ribLength, ribWidth, cylinderHeight - cylinderTopHoleHeight - structureHeightDelta]);
cylinder(d1 = cylinderBottomHoleD2, d2 = 0, h = cylinderBottomHeight, $fn = 64, center =
false);
}
}
// generate cylinder body
module cylinderBody() {
if (internalStructureType == "RIBS") {
rib();
rotate([0, 0, 90])
rib();
}
difference() {
cylinder(d = cylinderDiameter - cylinderTolerance, h = cylinderHeight, $fn = 100, center = false);
translate([0, 0, (internalStructureType == "SOLID" ? cylinderHeight - structureHeightDelta : 0)])
cylinder(d = cylinderDiameter - cylinderTolerance - cylinderThickness * 2, h =
(internalStructureType == "SOLID" ? structureHeightDelta : cylinderHeight), $fn = 100, center = false);
// top hole
translate([cylinderDiameter / -2, cylinderTopHoleWidth / -2, cylinderHeight - cylinderTopHoleHeight])
cube([cylinderDiameter, cylinderTopHoleWidth, cylinderTopHoleHeight]);
}
// bottom
translate([0, 0, -cylinderBottomHeight])
difference() {
cylinder(d = cylinderBottomDiameter, h = cylinderBottomHeight, $fn = 64, center = false);
cylinder(d1 = cylinderBottomHoleD1, d2 = cylinderBottomHoleD2, h = cylinderBottomHeight, $fn = 64, center =
false);
}
}
module pin() {
rotate([0, 90, 0])
union() {
cylinder(
d1 = pinBaseDiameter + .5,
d2 = pinDiameter,
h = (pinHeight + rOffset) / 1.5,
$fn = 20,
center = false
);
cylinder(
d1 = pinBaseDiameter,
d2 = pinDiameter,
h = pinHeight + rOffset,
$fn = 20,
center = false
);
}
}
module pinsFromScore(score) {
scoreLength = len(score);
offsetAngle = 360 / scoreLength;
for (i = [0:scoreLength - 1]) {
notes = score[i];
if (len(notes) > 0) {
for (noteIndex = [0:len(notes) - 1]) {
toothId = notes[noteIndex];
angle = (isCounterclockwise ? -1 : 1) * (offsetAngle * i);
radius = cylinderDiameter / 2 - rOffset;
x = radius * cos(angle);
y = radius * sin(angle);
z = firstPinPosition + pinOffset * (isTopFirst ? (tonesTotalNumber - toothId) : toothId);
translate([x, y, z])
rotate([0, 0, angle])
pin();
}
}
}
}
module generateMusicBoxCylinder() {
cylinderBody();
pinsFromScore(musicScore);
}
generateMusicBoxCylinder();