FooCAD Source Codeimport static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*
class Buttons : Model {
@Custom
var piece = "all"
val dx = 13/2
val dy = 13/2
val gap = 1.3
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 bottom() : Shape3d {
val outline = outline()
val around = (outline.offset(2) - outline).extrude(2)
val sheet2d = outline.offset(2) -
Square(gap,dy*3).repeatX(2,dx).center() -
Square(dx,gap).repeatX(2, dx*2).repeatY(2,dy).center() -
Square(dx*2,gap).center().translateY(dy/2)
val sheet = sheet2d.extrude(0.4)
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 base = (
Square( dx-gap, dy*1.5 ).centerX() +
Square( dx-gap, dy ).center().translateY(-dy-gap/2) +
Square( dx, dy-gap).center().translateX(dx+gap/2).mirrorX().also()
).extrude(0.4).color("Green")
val button = Square( dx-gap, dy-gap )
val buttons = (
button.repeatX(2,dx*2).center() +
button.repeatY(2,dy*2).center()
).extrude(3) +
button.center().extrude( 4 )
val edge = (
outline -
Square( dx * 3, dy ).center() -
Square( dx, dy * 3 ).center()
).extrude(1.5)
return base + buttons + edge
}
override fun build() : Shape3d {
return bottom() + top().translateX(30)
}
}