This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #include ~/kojo-includes/ka-bridge.kojo | |
def setup() { | |
pinMode(2, INPUT) | |
pinMode(3, OUTPUT) | |
pinMode(4, OUTPUT) | |
pinMode(5, OUTPUT) | |
} | |
def loop() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a simple game - you need to keep the rectangle within the canvas | |
// the rectangle moves and grows in size; its speed goes up as its size increases | |
// you can rotate it by pressing the 'P' key; you can make it smaller by clicking on it | |
cleari() | |
drawStage(black) | |
val rect = fillColor(lightGray) * penColor(lightGray) -> PicShape.rect(40, 60) | |
draw(rect) | |
animate { | |
rect.translate(1, 0) | |
rect.scale(1.001) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shape.clear() | |
setBackgroundH(black, blue) | |
val (height, breadth) = (100, 20) | |
def stem = Shape.rectangle(breadth, height).outlined(lightGray).filled(lightGray) | |
def tree(n: Double): Shape = { | |
if (n == 0) | |
stem | |
else | |
// on2 places shapes on each other without centering | |
tree(n-1) .rotated(30) .scaled(0.7) .translated(0, height * 0.95) on2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shape.clear() | |
def r(w: Int, h: Int) = Shape.rectangle(w, h) .outlined(black) | |
def sq(l: Int) = r(l, l) | |
def vgap(l: Int) = Shape.gap(0, l) | |
def hgap(l: Int) = Shape.gap(l, 0) | |
val eyes = sq(50) beside hgap(100) beside sq(50) filled(lightGray) | |
val nose = r(30, 100) .filled(orange) | |
val mouth = r(100, 20) .filled(red) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear() | |
setSpeed(fast) | |
setPenColor(darkGray) | |
repeat(18) { | |
forward(100) | |
right(100) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2012 Lalit Pant <pant.lalit@gmail.com> | |
* | |
* The contents of this file are subject to the GNU General Public License | |
* Version 3 (the "License"); you may not use this file | |
* except in compliance with the License. You may obtain a copy of | |
* the License at http://www.gnu.org/copyleft/gpl.html | |
* | |
* Software distributed under the License is distributed on an "AS | |
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class LSystem(axiom: String, angle: Double, len: Int = 100, sf: Double = 0.6)(rules: PartialFunction[Char, String]) { | |
var currVal = axiom | |
var currGen = 0 | |
def evolve() { | |
currGen += 1 | |
currVal = currVal.map { c => | |
if (rules.isDefinedAt(c)) rules(c) else c | |
}.mkString.replaceAll("""\|""" , currGen.toString) | |
} | |