Last active
October 19, 2024 16:50
-
-
Save nataliefreed/0ece932eaac6a50e3a3e754d10bd6fab to your computer and use it in GitHub Desktop.
Butterfly example with beziers and 2D/3D Export, OpenJSCAD
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
// title : OpenJSCAD Bezier, 2D/3D Export Example | |
// author : Natalie Freed | |
// sources : 2D/3D export technique from Lamp Shade Example | |
function getParameterDefinitions() { | |
return [{ name: 'height', type: 'float', initial: 6, caption: "height:" }, | |
{ | |
name: 'type', | |
type: 'choice', | |
values: ["2D", "3D"], | |
captions: ["2D (DXF output)", "3D (STL output)"], | |
caption: 'Export type:', | |
initial: "2D" | |
}]; | |
} | |
function main(params) { | |
//draw a butterfly wing with bezier curves | |
var wing = new CSG.Path2D([ [0,0] ], false); | |
wing = wing.appendBezier([ [-19, -158], [189, -38], [43, 20] ]); | |
wing = wing.appendBezier([ [100, 48], [46, 133], [0, 34] ]); | |
wing = wing.close(); | |
//make the curve into a surface | |
wing = wing.innerToCAG(); | |
//make a second wing, mirrored in X | |
var wing2 = wing.mirroredX(); | |
//connect the two wings | |
var wings = union(wing, wing2); | |
//mirror them in Y so they face forwards | |
wings = wings.mirroredY(); | |
//if we're in 2D mode, return the 2D shape | |
if(params.type === "2D") { | |
return [wings]; | |
} | |
//if we're in 2D mode, extrude the shape to make it 3D | |
else { | |
var wingsExtruded = wings.extrude({ offset: [0, 0, params.height]}); | |
return wingsExtruded; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
whats CSG?