Exit Full View
ZipUp

/Games/Snake.foocad

Snake
FooCAD Source Code
class Snake : Model {

    var width = 30
    var height = 20
    var gap = 0.3

    meth segmentShape() : Shape2d {
        val c = Circle(width/2)
        val main = Hull2d( c.translateX( width/2 ).also() )
        val cut = c.offset( gap ).translateX(-width/2)

        return main - cut
    }
    
    meth segmentA() : Shape3d {
        val shape = segmentShape()
        val topBottom = shape.extrude( height/3 )
            .topTo( height ).also()

        val middle = shape.mirrorX().extrude( height/3 )
            .bottomTo( height / 3 )

        return topBottom + middle
    }

    override fun build() : Shape3d {
        val a = segmentA().color("Green")
        val b = segmentA().translateX(width).color("Orange")

        return a + b //.mirrorX().also()
    }

}