Skip to content

Instantly share code, notes, and snippets.

@nataliefreed
Created October 9, 2016 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nataliefreed/a805deda01aae3a43a8101fa87705f3c to your computer and use it in GitHub Desktop.
Save nataliefreed/a805deda01aae3a43a8101fa87705f3c to your computer and use it in GitHub Desktop.
OpenJSCAD parametric pumpkin
// title : OpenJSCAD Pumpkin
// author : Natalie Freed
function getParameterDefinitions() {
return [
{ name: 'numSegments', type: 'int', initial: 10, caption: "Number of segments:" },
{ name: 'proportions', type: 'choice', caption: 'Proportions:', values: ["tall", "wide", "medium"], captions: ["tall", "wide", "medium"], initial: "medium" }
];
}
function main(params) {
var segments = [];
var heightScale;
if(params.proportions === "tall") {
heightScale = 1.5;
} else if(params.proportions == "wide") {
heightScale = 0.5;
} else {
heightScale = 0.75;
}
var angle = 0;
var angleChange = 360/params.numSegments*2;
for(var i=0;i<params.numSegments/2;i++) {
segments.push(torus({ ri: 1.5, ro: 3})
.rotateX([90])
.rotateZ(angle));
angle = angle + angleChange;
}
//var stem = cylinder({d1: 1.5, d2: 1, h: 1}).translate([0, 0, 4*heightScale]);
var stem = cylinder({start: [0, 0, 4*heightScale], end: [0, 0.25, 4*heightScale+1.5], r1: 1, r2: 0.75});
stem = stem.setColor([109/255, 57/255, 27/255]);
var pumpkin = union(segments).scale([1,1,heightScale]);
pumpkin = pumpkin.setColor = pumpkin.setColor([244/255, 131/255, 66/255]);
var pumpkinWithStem = union(pumpkin, stem).translate(4.5*heightScale);
return pumpkinWithStem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment