Exit Full View
Up

/New/WhiskyBallTool.foocad

WhiskyBallTool
FooCAD Source Code
import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*
import static uk.co.nickthecoder.foocad.changefilament.v1.ChangeFilament.*

/*
    A sphere with one flat side containing a magnet.
    The same size as the ball bearing, so that it fits neatly in the tray.
*/
class WhiskeyBallTool3 : Model, PostProcessor {
    
    var ballSize = 19.5

    // Size of the void for the magnet.
    var voidDiameter = 9.0
    var voidHeight = 5.0

    var floor = 0.4
    var flat = 1.9

    var sides = 60

    override fun build() : Shape3d {
        
        val sphere = Sphere( ballSize/2 ).sides(sides).translateZ(ballSize/2 - flat )
        val removeFlat = Cube( 100, 100, flat + 0.01 ).translateZ(-flat-0.01).centerXY()

        val hole = Cylinder.hole( voidHeight, voidDiameter/2 )
            .translateZ( floor )

        val result = sphere - removeFlat - hole
        // Space them out well, so that the magnets don't jump together!
        return result.repeatX(4, ballSize+30) // Cube( 100,1,100 ).center()
         
    }

    override fun postProcess(gcode: GCode) {
        // NOTE, this is 'flat' too early, which gives some time to get ready!
        gcode.alertAtHeight( voidHeight, "Add magnet" )
    }
}