import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.* import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.* class SevenSegmentDisplay : Model { // The number of digits @Custom var digits = 1 @Custom var includeDecimalPoint = false // Width of a digit (not including margins etc). @Custom var width = 25.0 @Custom var height = 40.0 // Total thickness. // Must be larger than your LED's head height plus the 'back' thickness. @Custom var thickness = 8.0 // Thickness of the back of the digits // (where the led's legs stick through // Use a value of 0 if you don't want a back (for example, if the // LEDs are mounted on a circuit board, and this print is placed on top. @Custom var back=0.9 // The space around the digits var marginX = 2.0 // The space around the digits var marginY = 3.0 // The gap between digits. // If printing a single digit, this has no effect. var spacing = 1.0 fun digitShape() : Shape2d { val name = if (includeDecimalPoint) "italic-dot" else "italic" return SVGParser().parseFile( "sevenSegmentDisplay.svg" ) .shapes[name] .toOrigin() .convexity( 10 ) } fun digit() : Shape3d { val shape = digitShape() val actualX = (width - marginX*2 - spacing * (digits-1)) / digits val actualY = height - marginY*2 val scaled = shape.scale( actualX / shape.size.x, actualY / shape.size.y ) val solid = Cube( width, height, thickness ) val digitHoles = scaled .extrude( thickness + back + 1 ) .tileX(digits,spacing) .translate( marginX, marginY, back ) // I Used this to check the size, to make sure a 3mm LED would fit. val debugLED = Cylinder(6,3/2).sides(10).color("Green") .translate(3.9,9,0) return solid - digitHoles // + debugLED } override fun build() : Shape3d { return digit() } }