Congratulations to the devs for this awesome project! I am just getting started in Kojo and wrote a little small program to draw some rhombus-type Penrose tilings. So this here is really my first program using Kojo (and in fact, also my first program ever in Scala):
var baseOne = 2 * math.sin(math.Pi * 54 / 180)
var baseTwo = 2 * math.sin(math.Pi * 18 / 180)
def triangleOne(depth: Int, length: Double,
mirrored: Int): Unit = {
if(depth == 0) {
setFillColor(cm.green)
forward(length)
right(mirrored * 72)
forward(length)
right(mirrored * 144)
hop(length * baseOne)
right(mirrored * 144)
} else {
right(mirrored * 36)
hop(length)
left(mirrored * 144)
triangleOne(depth - 1, length / baseOne, -mirrored)
hop(length / baseOne)
right(180)
triangleTwo(depth - 1, length / baseOne, -mirrored)
hop(length / baseOne)
right(-mirrored * 36)
hop(length / baseOne)
right(180)
triangleOne(depth - 1, length / baseOne, mirrored)
hop(length * baseOne)
right(mirrored * 144)
}
}
def triangleTwo(depth: Int, length: Double,
mirrored: Int): Unit = {
if(depth == 0) {
setFillColor(cm.blue)
forward(length)
right(mirrored * 144)
forward(length)
right(mirrored * 108)
hop(length * baseTwo)
right(mirrored * 108)
} else {
hop(length * baseTwo * baseTwo)
right(mirrored * 108)
triangleTwo(depth - 1, length * baseTwo, mirrored)
hop(length * baseTwo)
right(mirrored * 180)
triangleOne(depth - 1, length * baseTwo, mirrored)
left(mirrored * 36)
hop(length * baseTwo)
right(mirrored * 108)
}
}
def decagon(depth: Int, length: Double) {
clear()
setBackground(cm.black)
setSpeed(superFast)
invisible()
setPenColor(cm.black)
left(90)
hop(length)
right(180)
repeat(5) {
triangleTwo(depth, length, 1)
triangleTwo(depth, length, -1)
right(72)
hop(length * baseTwo)
left(36)
hop(length * baseTwo)
left(108)
}
}
clear()
toggleFullScreenCanvas()
var depth = 0
repeat(7) {
decagon(depth, 400)
depth = depth + 1
Thread.sleep(3000)
}
My compliments to the Kojo devs for creating an environment that makes it surprisingly easy to do things like this…