Skip to content

Instantly share code, notes, and snippets.

@litan
litan / LSystem-Kojo.scala
Created May 20, 2012 07:51
Playing with LSystems in Kojo
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)
}
@litan
litan / ScalariformTokenMaker.scala
Created November 21, 2012 17:04
A Scalariform based Lexer for RSyntaxTextArea
/*
* 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
@litan
litan / repeat-pattern.kojo
Created September 12, 2017 12:59
A turtle drawing
clear()
setSpeed(fast)
setPenColor(darkGray)
repeat(18) {
forward(100)
right(100)
}
@litan
litan / shape-face.kojo
Created September 12, 2017 13:18
A ‘shape’ drawing
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)
@litan
litan / shape-tree.kojo
Created September 12, 2017 13:20
A tree with shapes
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
@litan
litan / simple-game.kojo
Last active June 29, 2022 14:02
A simple game
// 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)
@litan
litan / arduino-sample.kojo
Created September 12, 2017 13:28
Controlling an arduino board
// #include ~/kojo-includes/ka-bridge.kojo
def setup() {
pinMode(2, INPUT)
pinMode(3, OUTPUT)
pinMode(4, OUTPUT)
pinMode(5, OUTPUT)
}
def loop() {
@litan
litan / 00-hunted-versions.md
Last active February 4, 2023 04:26
Hunted - various versions