content/blog/in-progress/lisp-pens-and-trees.markdown @ 1aa828894145

New entry, plus some other stuff
author Steve Losh <steve@stevelosh.com>
date Thu, 25 Aug 2022 23:05:04 -0400
parents (none)
children (none)
(:title "Lisp, Pens, and Trees"
 :snip "Growing something pretty."
 :date "2022-07-27T00:00:00Z"
 :draft t)

I've been meaning to document a fun little project I did a few years ago, so
here we go.  The actual project itself is a lot more complicated and has a lot
more code behind it, but I wanted to distill it down to the essence here.

<div id="toc"></div>

## Drawing Lines

First we want to be able to draw some lines.

## Turtle Graphics

[Turtle graphics][] are a simple way to draw lines with instructions like:

1. Start at the center, facing north.
2. Move forward.
3. Turn right 90°.
4. Move forward.
5. Turn right 90°.
6. Move forward.
7. Move forward again.

The result would look something like:

[![Example of a simple Turtle graphics script](/static/images/blog/2022/07/trivial-turtle.png)](/static/images/blog/2022/07/trivial-turtle.png)

The name "turtle" came from the [original robots][], which looked
and moved like turtles.

We can use a more compact notation for our turtle instructions:

* `F` move forward one step (while drawing).
* `S` skip forward one step (without drawing).
* `+` rotate a set amount counterclockwise.
* `-` rotate a set amount clockwise.

We'll add some other instructions later, but this is enough for now.  Let's
implement a simple turtle.

[Turtle graphics]: https://en.wikipedia.org/wiki/Turtle_graphics
[original robots]: https://blog.adafruit.com/2018/05/03/the-history-of-turtle-bots-part-1-hardware/

## L-Systems
## Mutation
## Plotting