Skip to content

Instantly share code, notes, and snippets.

View pencelab's full-sized avatar
☯️

Glenn pencelab

☯️
View GitHub Profile
panel {
val square = square {
lines = 8
char = 'd'
}
space()
val triangle = triangle {
lines = 8
char = 'd'
}
infix fun Shape.intersection(shape: Shape): ComposedShape {
return ComposedShape(this, shape, ComposedShape.Operation.INTERSECTION)
}
infix fun Shape.union(shape: Shape): ComposedShape {
return ComposedShape(this, shape, ComposedShape.Operation.UNION)
}
panel {
val square = square {
lines = 8
char = 'd'
}
space()
val triangle = triangle {
lines = 8
char = 'd'
}
panel {
val square = square {
lines = 8
char = 'd'
}
space()
val triangle = triangle {
lines = 8
char = 'd'
}
fun Panel.space() {
this.addShape(Space)
}
class RhombusBuilder: ShapeBuilder() {
override fun build() = Rhombus(lines, char)
}
class TriangleBuilder: ShapeBuilder() {
override fun build() = Triangle(lines, char)
}
class SquareBuilder: ShapeBuilder() {
override fun build() = Square(lines, char)
}
abstract class ShapeBuilder {
private companion object {
const val DEFAULT_CHAR = '*'
}
var char = DEFAULT_CHAR
var lines = 0
abstract fun build(): Shape