Skip to content

Instantly share code, notes, and snippets.

@hrgdavor
Created October 10, 2021 08:17
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 hrgdavor/08e61d2014ed7b62078fa9106380f634 to your computer and use it in GitHub Desktop.
Save hrgdavor/08e61d2014ed7b62078fa9106380f634 to your computer and use it in GitHub Desktop.
test fruit holder
const jscad = require('@jscad/modeling')
const { cube, cuboid, cylinder, cylinderElliptic, ellipsoid, geodesicSphere, roundedCuboid, roundedCylinder, sphere, torus } = jscad.primitives
const { translate ,rotate} = jscad.transforms
const { colorize } = jscad.colors
const { union, subtract, intersect } = jscad.booleans
const { degToRad } = jscad.utils
const { hull, hullChain } = jscad.hulls
const getParameterDefinitions = () => {
return [
{ name: 'R', caption: '直径(ミリ):', type: 'float', initial: 60, min: 20, max: 200 },
{ name: 'g', type: 'choice', caption: 'ギザギザの数', values: [0, 1,], captions: ['6', '12'], default: 0 }
]
}
const main = (params) => {
if(params.g===0){
const aroundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)-(2-(19/params.R))/2, (params.R/4)/2], roundedCuboid({ size: [2.66+params.R/20, 2-(19/params.R), params.R/4], roundRadius: 0.4, segments: 20 })))
const broundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)*0.8, (params.R/6.66)/2], roundedCuboid({ size: [2.66+params.R/20, 1, params.R/6.66], roundRadius: 0.2, segments: 20 })))
const croundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)*0.7,(params.R/8.88)/2 ], roundedCuboid({ size: [2.66+params.R/20, 1, params.R/8.88], roundRadius: 0.2, segments: 20 })))
const droundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)*0.6, (params.R/13)/2], roundedCuboid({ size: [2.66+params.R/20, 1, params.R/13], roundRadius: 0.2, segments: 20 })))
const eroundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)*0.4, (params.R/28)/2], roundedCuboid({ size: [2.66+params.R/20, 1, params.R/28], roundRadius: 0.2, segments: 20 })))
const froundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)*0.19,params.R/200], roundedCuboid({ size: [2.66+params.R/20, 1, params.R/400], roundRadius: 0.002, segments: 20 })))
const acylinder =cylinder({ radius: 0.2+(params.R/2), height: 2 , segments: 100})
const ahullChain=hullChain(aroundedCuboid ,broundedCuboid,croundedCuboid,droundedCuboid,eroundedCuboid ,froundedCuboid )
const rotations = [degToRad(0), degToRad(0), degToRad(0)]
const arotations = [degToRad(0), degToRad(0), degToRad(60)]
const brotations = [degToRad(0), degToRad(0), degToRad(120)]
const crotations = [degToRad(0), degToRad(0), degToRad(180)]
const drotations = [degToRad(0), degToRad(0), degToRad(240)]
const erotations = [degToRad(0), degToRad(0), degToRad(300)]
let rotated = rotate(rotations, ahullChain)
let arotated = rotate(arotations, ahullChain)
let brotated = rotate(brotations, ahullChain)
let crotated = rotate(crotations, ahullChain)
let drotated = rotate(drotations, ahullChain)
let erotated = rotate(erotations, ahullChain)
const aunion= union(acylinder,rotated,arotated,brotated,crotated,drotated,erotated)
return [
translate([0, 0, 0],aunion),
]
}
else{
const aroundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)-(2-(19/params.R))/2, (params.R/4)/2], roundedCuboid({ size: [2+params.R/30, 2-(19/params.R), params.R/4], roundRadius: 0.4, segments: 20 })))
const broundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)*0.8, (params.R/6.66)/2], roundedCuboid({ size: [2+params.R/30, 1, params.R/6.66], roundRadius: 0.2, segments: 20 })))
const croundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)*0.7,(params.R/8.88)/2 ], roundedCuboid({ size: [2+params.R/30, 1, params.R/8.88], roundRadius: 0.2, segments: 20 })))
const droundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)*0.6, (params.R/13)/2], roundedCuboid({ size: [2+params.R/30, 1, params.R/13], roundRadius: 0.2, segments: 20 })))
const eroundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)*0.4, (params.R/28)/2], roundedCuboid({ size: [2+params.R/30, 1, params.R/28], roundRadius: 0.2, segments: 20 })))
const froundedCuboid = colorize([4, 7, 0], translate([0, (params.R/2)*0.18,params.R/400], roundedCuboid({ size: [2+params.R/30, 1, params.R/200], roundRadius: 0.002, segments: 20 })))
const acylinder =cylinder({ radius: 0.2+(params.R/2), height: 2 , segments: 100})
const ahullChain=hullChain(aroundedCuboid ,broundedCuboid,croundedCuboid,droundedCuboid,eroundedCuboid ,froundedCuboid )
const rotations = [degToRad(0), degToRad(0), degToRad(0)]
const arotations = [degToRad(0), degToRad(0), degToRad(30)]
const brotations = [degToRad(0), degToRad(0), degToRad(60)]
const crotations = [degToRad(0), degToRad(0), degToRad(90)]
const drotations = [degToRad(0), degToRad(0), degToRad(120)]
const erotations = [degToRad(0), degToRad(0), degToRad(150)]
const frotations = [degToRad(0), degToRad(0), degToRad(180)]
const grotations = [degToRad(0), degToRad(0), degToRad(210)]
const hrotations = [degToRad(0), degToRad(0), degToRad(240)]
const irotations = [degToRad(0), degToRad(0), degToRad(270)]
const jrotations = [degToRad(0), degToRad(0), degToRad(300)]
const krotations = [degToRad(0), degToRad(0), degToRad(330)]
let rotated = rotate(rotations, ahullChain)
let arotated = rotate(arotations, ahullChain)
let brotated = rotate(brotations, ahullChain)
let crotated = rotate(crotations, ahullChain)
let drotated = rotate(drotations, ahullChain)
let erotated = rotate(erotations, ahullChain)
let frotated = rotate(frotations, ahullChain)
let grotated = rotate(grotations, ahullChain)
let hrotated = rotate(hrotations, ahullChain)
let irotated = rotate(irotations, ahullChain)
let jrotated = rotate(jrotations, ahullChain)
let krotated = rotate(krotations, ahullChain)
const aunion= union(acylinder,rotated,arotated,brotated,crotated,drotated,erotated,frotated,grotated,hrotated,irotated,jrotated,krotated)
return [
translate([0, 0, 0],aunion),
]
}
}
module.exports = { main,getParameterDefinitions }
// 直径に応じてブレードの厚みを変える
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment