Created
May 12, 2025 10:56
-
-
Save pgmrDohan/90c56270cd5531077e132bf92107e88c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Using p5.js | |
| function roundedBox(length, width, height, radius) { | |
| // Draw walls (three orthogonal boxes) | |
| box(length, width - radius, height - radius); | |
| box(length - radius, width, height - radius); | |
| box(length - radius, width - radius, height); | |
| // Draw 8 corner spheres | |
| for (let xSign = -1; xSign <= 1; xSign += 2) { | |
| for (let ySign = -1; ySign <= 1; ySign += 2) { | |
| for (let zSign = -1; zSign <= 1; zSign += 2) { | |
| push(); | |
| translate( | |
| xSign * (length - radius)/2, | |
| ySign * (width - radius)/2, | |
| zSign * (height - radius)/2 | |
| ); | |
| sphere(radius/2, 10, 10); | |
| pop(); | |
| } | |
| } | |
| } | |
| // Draw 12 edge cylinders | |
| // X-axis aligned edges | |
| [-1, 1].forEach(ySign => { | |
| [-1, 1].forEach(zSign => { | |
| push(); | |
| translate(0, ySign * (width - radius)/2, zSign * (height - radius)/2); | |
| rotateZ(-HALF_PI); | |
| cylinder(radius/2, length - radius, 10, 1, false, false); | |
| pop(); | |
| }); | |
| }); | |
| // Y-axis aligned edges | |
| [-1, 1].forEach(xSign => { | |
| [-1, 1].forEach(zSign => { | |
| push(); | |
| translate(xSign * (length - radius)/2, 0, zSign * (height - radius)/2); | |
| cylinder(radius/2, width - radius, 10, 1, false, false); | |
| pop(); | |
| }); | |
| }); | |
| // Z-axis aligned edges | |
| [-1, 1].forEach(xSign => { | |
| [-1, 1].forEach(ySign => { | |
| push(); | |
| translate(xSign * (length - radius)/2, ySign * (width - radius)/2, 0); | |
| rotateX(HALF_PI); | |
| cylinder(radius/2, height - radius, 10, 1, false, false); | |
| pop(); | |
| }); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment