FooCAD Source Codeimport static uk.co.nickthecoder.foocad.changefilament.v1.ChangeFilament.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*
include PlantPot.foocad
/**
Creates a striped plant pot, by pausing the printer at various heights, allowing
you to change the colour of filament.
When designing, use piece "preview", so that you can see the colours in OpenSCAD.
When you are ready to print, set the piece back to <No Piece>.
The stl file will then be built from the "regular" pot, rather than one made from many slices
(which would take ages).
Also note that when piece=preview, the slices have gaps between them, because otherwise
OpenSCAD renders all the slices in a single colour.
Print Notes
Use lots of perimeters for a solid pot (> 3)
*/
class StripedPlantPot : Model, PostProcessor {
@Custom
var potSize = Vector2(95,90)
@Custom
var potType = "6"
@Custom
var potLip = 4.0
@Custom
var potThickness = 1.2
@Custom
var baseThickness = 2.4
@Custom( lines = 10 )
var colors = """0.7 DarkBlue
2 White
10 Orange
2 White
19 FireBrick
2 White
13 DarkBlue
2 White
19 FireBrick
2 White
10 Orange
2 White
14 DarkBlue
15 White
"""
@Custom( lines = 3 )
var text = ""
var preview = false
fun pot() : Shape3d {
val pot = PlantPot().apply {
type = potType
potDiameter = potSize.x
potHeight = potSize.y
thickness = potThickness
lip = potLip
showInner = false
}
pot.baseThickness = baseThickness
pot.text = text
return pot.build()
}
var sliceCount = 0
var pot : Shape3d = null
var z = 0
var pauses = listOf<double>()
fun layer(thickness : double, color: String) : Shape3d {
if (sliceCount == 0) {
pot = pot()
}
sliceCount ++
val slice = Cube( pot.size.x*2, pot.size.y*2, thickness ).bottomTo( z ).centerXY()
z += thickness
pauses.add(z)
return (pot.translateX(1).rotateZ(sliceCount*3)/slice).color( color )
}
override fun build() = build( true )
@Piece
fun preview() = build( true )
fun build( preview : bool ) : Shape3d {
this.preview = preview
val slices = listOf<Shape3d>()
for (line in colors.split("\n")) {
val space = line.indexOf(" ")
println( "Line : $line space=$space" )
if ( space > 0 ) {
val h = line.substring(0, space).toDouble()
val color = line.substring(space).trim()
val layer = layer( h, color )
slices.add(layer)
}
}
println( "Pauses : $pauses" )
return if (preview) {
Union3d( slices )
} else {
pot
}
}
override fun postProcess(gcode: GCode) {
if ( !preview ) {
val top = pot.size.z
for ( p in pauses ) {
if (p < top ) pauseAtHeight( gcode, p, "Change Filament" )
}
}
}
}