Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pentatonic pineapple draft
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@moonmilk

This comment has been minimized.

Copy link
Owner Author

@moonmilk moonmilk commented Apr 9, 2019

// openjscad

const TWO_PI = 2.0 * 3.14159265;

function getParameterDefinitions () {
  return ([
    {name: 'height', type: 'float', initial: 50,caption: 'Height'},
    {name: 'topWidth', type: 'float', initial: 50, caption: 'Top width'},
    {name: 'bottomWidth', type: 'float', initial: 30,  caption: 'Bottom width'},
    {name: 'bumpSize', type: 'float', initial: 5, caption: 'bump size'}
  ]);
}

var tiltAngle, tiltLength;

function main(params) {
    tiltAngle = -90 + 360 / TWO_PI * Math.atan2(params.height, params.bottomWidth/2-params.topWidth/2);
    var diff = params.topWidth/2 - params.bottomWidth / 2;
    tiltLength = Math.sqrt(params.height*params.height + diff*diff);
    
    params.bumpSize = tiltLength / 6;
    
    /*
    return union(
        cone(),
        bumps()
    );
    */
    //return positive();
    return mold();
    //return thinPositive();
}   

function mold() {
    return difference(
        scale([1.1,1.1,1.0], cone()),
        positive()
    )
}

function thinPositive() {
    return difference(
        positive(),
        scale([0.82,0.82,1.0], cone())
    )
}

function positive() {
    return difference(
        cone(),
        bumps()
    );
}

function cone() {
    return cylinder({r1:params.bottomWidth/2, r2:params.topWidth/2, h:params.height});
}

function bumps() {
    var bs = [];
    for (var j=0; j<6; j++) {
        var n = [15,18,20,24,27,30][j]
        for (var i=0; i<n; i++) {
            bs.push(bump(8*j,360 * i / n));
        }
    }
    return union(
        bs
    );
}


function bump(h, a) {
    return translate([0,0,h], 
        rotate([0,0,a], 
            translate([extrapolatedRadius(h)+params.bumpSize/2,0,params.bumpSize/2.0], 
                rotate([0, tiltAngle, 0],
                    bevelBump()
                    //simpleBump()
                )
            )
        )
    );
}

// no good
function simpleBump() {
    return rotate([45,45,45], cube({size: params.bumpSize, center:true}))
}

function bevelBump() {
    return intersection(
      rotate([0,0,45], cube({size: params.bumpSize, center:true})),
      rotate([45,0,45], cube({size: params.bumpSize*1.1, center:true})),
      rotate([0,45,45], cube({size: params.bumpSize*1.1, center:true}))
    )
}

function extrapolatedRadius(h) {
    let t = h / params.height;
    return params.bottomWidth/2 + (params.topWidth/2 - params.bottomWidth/2) * t;
}

@moonmilk

This comment has been minimized.

Copy link
Owner Author

@moonmilk moonmilk commented Apr 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment