I’m pleased to announce a new release of Kojo. Highlights include:
0. New Installers
The primary Kojo installers for Linux, Windows, and Mac now come with Java 8 bundled inside, making it easier to get going with Kojo without worrying about installing a compatible version of Java before installing Kojo. The new Kojo installers are built using Install4j.
1. Richer color handling
You can now mix rich colors in Kojo using the ColorMaker:
ColorMaker.hsla(hue, saturation, lightness, opacity) ColorMaker.rgba(red, green, blue, opacity)
I’m calling these colors rich because they can be modified in a controlled fasion in many different ways — by:
- Rotating their hues.
- Changing their saturation, lightness, or opacity.
- Increasing, or decreasing their saturation, lightness, or opacity by absolute or relative amounts.
Here is an example that increments the hue of a color by 20 degrees in a loop that runs for 18 repitions, thus covering the whole range of hues from 0 to 360 degrees:
clear() setSpeed(fast) var clr = ColorMaker.hsla(0, 1.00, 0.5, 0.36) setPenColor(black) repeat(18) { setFillColor(clr) repeat(5) { forward(100) right(72) } right(20) clr = clr.spin(20) }
The full list of color manipulation methods is available here.
There are also 147 predefined colors, which you can easily access via code completion — by typing in ColorMaker. and then pressing Ctrl-Space or Ctrl+Alt+Space:
Richer colors in Kojo are based on the Doodle Color class.
2. Arduino fixes
This release provides a fix for Kojo’s Arduino support which allows Kojo to work with the latest version of the Arduino IDE. Instructions for programming Arduino boards with Kojo can be found via the ‘Tools -> Arduino Programming’ menu item. Also, the latest code, instructions, and samples for working with Arduino can be found in the kojo-arduino repository.
Here is an example Arduino program that controls an LED (at pin 12) based on inputs from a light sensor (at analog pin 0):
// #include ~/kojo-includes/ka-bridge.kojo def setup() { pinMode(12, OUTPUT) } def loop() { val light = analogRead(0) println(light) if (light < 170) { digitalWrite(12, HIGH) } else { digitalWrite(12, LOW) } // delay(100) }
3. Bundled scalatest for out of the box testing
Scalatest is now bundled with Kojo. This allows for easy testing of functions written within Kojo:
Tests that pass show up in green in the output pane. Failing tests show up in red, and report the exact nature of the problem:
4. Picture enhancements
This includes various syntactic enhancements to make working with pictures easier:
- You can create picture based shapes (rectangles, circles, text, etc) using the Picture object:
val r = Picture.rectangle(40, 60) val t = Picture.text("Hello", 20)
Earlier, this was supported (and still is) by the PicShape object.
- The Picture translate and offset methods can now take vector arguments in addition to (x, y) arguments.
- The draw method now works better with a sequence of pictures (specifically Lists and Vectors), without requiring unpacking via ‘_ : *’.
5. Gaming Enhancements
The following commands have been added:
- showFps(color, fontSize) — show frames per second during the game on the top-left of the canvas.
- showGameTime(seconds, endMessage, color, fontSize) – shows the seconds since the start of the game on the bottom-left of the canvas using the given color and fontSize. If the specified number of seconds have elapsed since the start of the game, the game is stopped and the specified messgage is shown in the center of the canvas.
- drawCenteredMessage(message, color, size): draws the specified message with the given color and size in the center of the canvas.
6. Angles playground
An angles playground is now available for young children to experiment with the angles that they use to turn the turtle. The playground can be launched via the ‘Samples -> Math Learning Modules -> Playing with Angles’ menu item:
7. Support for step animations (for younger children)
There is a new command — clearStepDrawing() — to enable children to make fun step animations as a first step along the path of animating their drawings. Here’s an example that draws a growing, rotating square:
def square(n: Int) { repeat(4) { forward(n) right(90) } } clear() repeatFor(10 to 100 by 5) { n => clearStepDrawing() setSpeed(superFast) setPenColor(ColorMaker.darkGreen) setFillColor(ColorMaker.darkKhaki) right(n * 3 - 30) square(n) pause(0.5) }
That’s it for this release. As always, the new version is available from the Kojo Download Page. If you run into any difficulties, let us know.
Enjoy!