I've been evaluating Kojo for the purposes of introducing my kids to programming. Yesterday I tried to rewrite this example from the Tweetable Mathematical Art contest on codegolf.stackexchange.com. It works, but is extremely slow - painting a 200x200 square takes over 20 seconds. (I had to paint dot-by-dot because I could not figure out if there is a pixel graphics API - if there is, a pointer would be appreciated.)
import Staging._
import Staging.{screenSize, dot}
reset
screenSize(200, 200)
println(screenWidth)
background(black)
class ColorGen {
var map = Array.ofDim[Int](200, 200)
map(0)(0) = random(256)
for (i <- 1 until 200) {
map(i)(0) = if (random(5) == 0) random(256) else map(i-1)(0)
map(0)(i) = if (random(5) == 0) random(256) else map(0)(i-1)
}
def get(i: Int, j: Int): Int = {
if (map(i)(j) == 0) {
val d = random(3) + 1
map(i)(j) = if (random(1000) == 0) random(256)
else {get((200+i-(d&1)) % 200, (200+j-(d >> 1)) % 200)}
}
map(i)(j)
}
}
val r = new ColorGen
val g = new ColorGen
val b = new ColorGen
for (x <- 0 until 200; y <- 0 until 200) {
stroke(color(r.get(x,y), g.get(x,y), b.get(x,y)))
dot(x, y)
}
println("DONE")
I then did the same sample in Processing and found it capable of repainting a 200x200 square over thirty times per second.
Does this happen because Kojo is inherently slower, or because it is not suitable for pixel graphics?