Created
April 10, 2018 20:17
-
-
Save bddap/19eb3cd1a025c0979b18de282201a071 to your computer and use it in GitHub Desktop.
jscad speaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const len = 100; // length of longest resonator | |
const count = 8; | |
const irr = (Math.sqrt(5) + 1) / 2; // a very irrational number | |
const s = 1 / irr; // length ratio between largest and smallest resonator | |
function main() { | |
return Array(count).fill(0) | |
.map((_, i) => resonator(Math.pow(s, i / (count - 1)))) | |
.reduce(combine); | |
} | |
function resonator(length) { | |
return cube({ | |
center: [1, 1, 0] | |
}).scale([length, 0.06, 0.005]) | |
.scale(len) | |
} | |
function combine(a, b) { | |
return union( | |
a.rotateZ(180 / count) | |
.translate([0, 0, 0.01 * len]), | |
cylinder({ | |
r: 0.06 * len / 2, | |
start: [0, 0, 0.01 * len], | |
end: [0, 0, 0.005 * len] | |
}), | |
b | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment