Exit Full View
Up

/GardenFurniture/Cooler.foocad

Cooler
FooCAD Source Code
import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*
import java.util.ArrayList

/*

A circular table, with a removable lid, which reveals a bucket. Fill the bucket with
ice cold water, and use it to keep drinks during a garden party.
NOTE. My bucket has handles, so two of the yellow connectors are lower than the others.

I used decking for all of the parts.

https://www.wickes.co.uk/Wickes-Deck-Board---25mm-x-120mm-x-2-4m/p/114551
https://www.wickes.co.uk/Wickes-Plasterer%27s-Rigid-Bucket---30L/p/103976

*/
class Cooler : Model {

    var ww=120 // wood width
    var wt=25 // wood thickness
    var gap=5 // Gap to allow for expansion of the lid and base.

    var diameter = 415 
    var connectorWidth = 35
    var height = 440 // Height of the side pieces. The total height is height + wt * 2 (top and feet)
    var pieces = 12 // Number of pieces of wood which make up the main body.

    fun angle() = 360/pieces

    fun lumber() = Lumber( "boards", ww, wt, "LightGreen" )
        .stockLength(2400)
    

    fun angled() = Lumber( "angled", PolygonBuilder()
        .moveTo( wt*Degrees.sin(angle()/2), 0 )
        .lineTo( ww-wt*Degrees.sin(angle()/2), 0 )
        .lineTo( ww, wt)
        .lineTo( 0, wt)
        .build()
    )

    fun slattedCircle (d: double) : Shape3d {
        val pieces : int = Math.ceil(d / (ww+gap))
        val slat = lumber().cut(d).rotate(90,0,0)
        val slats = slat.repeatX( pieces, ww+gap ).centerX().centerY()
        return slats.intersection( Cylinder( wt*3, d/2 ).center() )
    }

    fun top() =
            slattedCircle( diameter + wt*3 ) +
            slattedCircle( diameter ).rotate( 0,0,90 ).translate(0,0,-wt)

    fun base() = slattedCircle( diameter )

    fun sides() : Shape3d {
        val side = angled().cut(height).translate( -ww/2, diameter/2, 0 )
        val sidesList = ArrayList<Shape3d>()
        for ( i in 1..pieces ) {
            sidesList.add(side.rotate( 0, 0, angle()*i ))
        }
        return Union3d( sidesList ).color("Green")
    }

    fun connector() = ((
            Square( ww*0.4, connectorWidth*2 ).rotate( 360/pieces ).translate(ww/2,0) +
            Square( ww, connectorWidth*2 ).translate(-ww/2,0) +
            Square( ww*0.4, connectorWidth*2 ).translate(-ww*0.4,0).rotate( -360/pieces ).translate(-ww/2,0)
        ).translate(0,-diameter/2) - Circle( diameter/2 - connectorWidth )
        ).extrude( wt )

    fun foot() = Cylinder( wt, ww/2 ).translate(diameter/2-ww/2+wt/2,0,-wt).color( "Blue" )

    override fun build() : Shape3d {
        return top().translate( 0,0,height + 200) +
            sides() +
            connector().translate( 0,0, height*0.8).repeatAroundZ(pieces/2) +
            connector().translate( 0,0, height*0.3).repeatAroundZ(pieces/2) +
            base() +
            foot().repeatAroundZ(3)
    }
   

}