FooCAD Source Codeimport uk.co.nickthecoder.foocad.smartextrusion.v1.*
import static uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*
class CustomRiskBoard : Model {
var name = "Test"
var sideLength = 40
var sides = 6
var baseThickness = 0.6
var wallSize = Vector2(2, 1.5)
var clearance = 0.3
var style = TextStyle(DEFAULT_FONT)
.fontSize(10)
meth bump( scale : double ) : Shape2d {
return PolygonBuilder().apply {
moveTo( 0, -1 )
lineTo( 0.5, -0.3 )
lineTo( 1.5, -1 )
lineTo( 2.5, 0 )
lineTo( 1.5, 1 )
lineTo( 0.5, 0.3 )
lineTo( 0, 1 )
}.build()
.scale( scale*0.8, scale )
.roundCorner(5, scale*0.3)
.roundCorner(4, scale*0.6)
.roundCorner(3, scale*0.7)
.roundCorner(2, scale*0.6)
.roundCorner(1, scale*0.3)
}
meth polygon( sides : int ) : Shape2d {
val outside = PolygonBuilder().apply {
var x = 0.0
var y = 0.0
var angle = Math.PI
moveTo( x, y )
for ( i in 0 until sides ) {
x += sideLength * Math.sin(angle)
y += sideLength * Math.cos(angle)
angle += Math.PI * 2 / sides
println( "$x,$y")
lineTo( x, y )
}
}.build().center()
.offset( -clearance/2 )
val bumpScale = sideLength*0.15
val bump = bump( bumpScale )
val indent = bump.mirrorX()
.offset(clearance)
val bumps = bump
.centerYTo( -sideLength * 0.2 )
.leftTo( outside.right - bumpScale*0.2 )
.repeatAround( sides )
val indents = indent
.centerYTo( sideLength * 0.2 )
.rightTo( outside.right + bumpScale*0.2 + clearance*2 )
.repeatAround( sides )
return outside + bumps - indents
}
meth territory( shape : Shape2d ) : Shape3d {
val base = shape
.smartExtrude( baseThickness )
.bottom( Chamfer(wallSize.y / 3) )
val wall = (shape - shape.offset( -wallSize.x ))
.smartExtrude( wallSize.y )
.outsideTop( Chamfer(wallSize.y / 3) )
.bottomTo( base.top )
return base + wall
}
meth polygon() = polygon( sides )
meth rect2x1() : Shape2d {
val square = polygon( 4 )
val shape = square.translateX( sideLength/2 )
.rotate(180).also() +
Square( sideLength ).center().offset(-clearance/2 )
return shape
}
override fun build() : Shape3d {
val hexDX = sideLength * 1.73
val squareDX = sideLength
val hex1 = territory( polygon(6) )
val hex2 = hex1
.translateX( hexDX )
val square = territory( polygon(4) )
.translateX( hexDX *1.5 + squareDX / 2 )
val rect = territory( rect2x1() )
.translateX( - hexDX * 0.5 - squareDX )
return hex1 + hex2 + square + rect
}
}