An open API service indexing awesome lists of open source software.

https://github.com/samdvr/l-system


https://github.com/samdvr/l-system

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

# L-System

[L-System](https://en.wikipedia.org/wiki/L-system)
Image generator using [Doodle library](https://github.com/creativescala/doodle).
Example generated images are in [here](https://github.com/samdvr/L-System/tree/master/examples).

Sample Language and Interpreter

```scala
import algebra._
import doodle.turtle._
import doodle.turtle.Instruction._
import doodle.syntax._
import Draw._

object Implicits {

object Generator extends SequenceGenerator[Language]

implicit val rule: ProductionRule[Language] = {
case A => List(B, TurnLeft, A, TurnLeft, B)
case B => List(A, TurnRight, B, TurnRight, A)
case TurnLeft => List(TurnLeft)
case TurnRight => List(TurnRight)
}

implicit val drawer: Drawer[Language] = new Drawer[Language] {
override def convert: List[Language] => List[Instruction] = _.flatMap {
case A => List(forward(5))
case B => List(forward(5))
case TurnLeft => List(turn(-60.degrees))
case TurnRight => List(turn(60.degrees))
}
}
}

object Runner extends App {
override def main(args: Array[String]): Unit = {
import Implicits._
val data = Generator.sequenceNumber(List(A, B), 10)
drawer.convert(data).draw
}
}

```

[L-System]: https://en.wikipedia.org/wiki/L-system