Exit Full View
Up

/Games/ChessPiece.foocad

ChessPiece

A chess set, made mostly from "solids of revolution". (All except the knight, which is in the shape of a double G) Get the joke?

I've never printed it. The Knight needs to be taller.

Also, if I did print it, I'd make cylindical hollows in the bases to weight the pieces with coins.

FooCAD Source Code
import static uk.co.nickthecoder.foocad.chamferedExtrude.v1.ChamferedExtrude.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*

class ChessPiece : Model {

    var boardSize = 25
    
    var profiles = SVGParser().parseFile( "chessProfiles.svg" )

    fun revolve(name : String ) = profiles.shapes[name].toOrigin().translateX(0.1).revolve()

    fun knight() : Shape3d {

        val gP = profiles.shapes["g"].offset(-0.3).rotate(90)
        val base = revolve( "knight" )
        val cham = 0.6
        val g = ExtrusionBuilder().apply {
            joinStrategy = OneToOneJoinStrategy.instance

            crossSection( gP )
            forward( cham )
            crossSection( cham )
            forward( 3 )
            crossSection( cham )
            forward( cham )
            crossSection( gP )

        }.build().rotateY(90).toOriginZ()
            //.rotateY(6)
            .translateX(0.3)
            .mirrorX().also()
            .centerY()
            .translateZ(base.size.z/2 )

        return g + base
    }

    override fun build() : Shape3d {

        profiles = SVGParser().parseFile( "chessProfiles.svg" )

        println( "Profiles : ${profiles.shapes.keySet()}" )
        
        return revolve("pawn").translateY(boardSize).repeatX( 5, boardSize ) +
            revolve("rook") +
            knight().translateX(boardSize) +
            revolve("bishop").translateX(boardSize*2) +
            revolve("queen").translateX(boardSize*3) +
            revolve("king").translateX(boardSize*4)
    }
}