Exit Full View
Up

/Kobo/Buttons.foocad

Buttons
FooCAD Source Code
import static uk.co.nickthecoder.foocad.layout.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.Layout3d.*
class Buttons : Model {
    
    @Custom
    var piece = "all"

    val dx = 13/2
    val dy = 13/2
    val gap = 1.0
    
    fun outline() : Shape2d {
        val shape = SVGParser().parseFile("kobo.svg").shapes["buttons"].center()
        val svgWidth = shape.size.x
        return shape.scale( 26/svgWidth, 25/svgWidth )
    }

    fun down() = PolygonBuilder().apply {
            moveTo( 2,-5 )
            lineTo( 8,-12 )
            lineTo( -8,-12 )
            lineTo( -2,-5 )
        }.build()

    fun right() = PolygonBuilder().apply {
            moveTo( 5,2 )
            lineTo( 13,6 )
            lineTo( 13,-6 )
            lineTo( 5, -2 )
        }.build()

    fun diagonal() = PolygonBuilder().apply {
            moveTo( 0.5,2 )
            lineTo( 10, 12 )
            lineTo( 12,7.5 )
            lineTo( 2,1 )
        }.build()

    fun ok() = Square( 7,7 ).roundAllCorners(1).center()

    fun bottom() : Shape3d {
        val outline = outline()
        val around = (outline.offset(2) - outline).extrude(2)
 
        val sheet = (
            down().mirrorY().also() +
            right().mirrorX().also() +
            diagonal().mirrorX().also() +
            Square( 7 ).center()
        ).extrude( 0.2 )

        val nipple = Cube( 1.2, 1.2, 1.5 )
        val nipples = nipple.repeatX( 3, dx ).centerXY() +
            nipple.repeatY( 2, dy * 2 ).centerXY()
        return sheet + nipples + around
    }

    fun top() : Shape3d {
        val outline = outline()

        val button = ok()
        val arrows = (
                right().mirrorX().also() +
                down().mirrorY().also()
            ).intersection( outline.offset(-2) )
      
        val base = (
            right().mirrorX().also() +
            down().mirrorY().also() +
            diagonal().mirrorX().also()
        ).intersection( outline ).extrude(0.4).color("Yellow")

        val buttons = (
            arrows.extrude(3) +
            button.extrude( 4 )
            ).color("Orange")

        val edge = (outline - (arrows+button).offset(gap)).extrude(1.5)
        
        return base + buttons + edge
    }

    override fun build() : Shape3d {
        
        return bottom() + top().translateX(30)

    }
}