The cl-aristid Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-aristid Reference Manual

This is the cl-aristid Reference Manual, version 0.0.2, generated automatically by Declt version 3.0 "Montgomery Scott" on Wed Nov 04 11:56:23 2020 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

cl-aristid

Draw Lindenmayer Systems with Common LISP!

1. Introduction

A Lindenmayer system (L-system) is a model originally designed by Aristid Lindenmayer in the 60s to describe plant growth. Another common use for this system is as a technique to generate fractals, i.e, a self-similar geometric figure.

The main idea of this model is to start with a string of symbols such as "F G", and then, rewrite that original string N times, according to some rules such as "replace every F with 'F G F'" and "replace every G with 'G G F'". After doing this rewrite, we have a final string of symbols, and if we define some of those symbols to have some drawing action attached, such as 'F means draw a line forward' and 'G means draw a line to the right', we will end up with a drawing of our fractal.

An L-system requires 3 things to be defined:

The main idea of this program is to define each of this things that the system requires, and then draw it, exporting it to a .svg

2. Example

Go to the examples folder to look at the code for several fractals and see them in action by running make!

Drawing the Dragon Curve with cl-aristid

  1. First, we want to enter SBCL (just write sbcl in the terminal, inside the root of the repository) and load this package
(ql:update-dist "quicklisp")
(ql:quickload "cl-aristid")
  1. After the call to use-package we now have access to the symbols exposed by the package, detailed in Interface.
(use-package 'cl-aristid)
  1. defaristid

We now want to define the different aristids of our fractal. We are calling an 'aristid' to each symbol on our Lindenmayer alphabet that does something, that is, to any drawing function. If we check the Dragon Curve definition, we have 3 aristids (F, + and -). As LISP already has defined the + and - symbols, we will replace them with RIGHT and LEFT

(defaristid F :len 2) ; The letter F draws forward a line of length 2.
(defaristid LEFT :angle 90) ; LEFT will turn left 90 degrees
(defaristid RIGHT :angle -90) ; RIGHT will turn right 90 degrees
  1. defrule

After our aristids, we want to define the production rules. This rules are the ones that will rewrite our function string on each iteration. The Dragon Curve has only 2 rules: (X → X + Y F +) and (Y → − F X − Y). This means that on each iteration we will replace X with X + Y F + and the same happens to Y.

; We wrap every rule in a LISP list, to use as an argument later
(defparameter dragon-rules
    (list (defrule X -> (X RIGHT Y F RIGHT))
          (defrule Y -> (LEFT F X LEFT Y))))
  1. make-fractal

We have almost everything to define our fractal! Remember, a L-system consists of three things: the alphabet of symbols (our aristids), the production rules, and an axiom, which is the first string to be rewritten. In the Dragon Curve example, the axiom is (F X)

We want to call make-fractal with all of this attributes.

(defparameter dragon (make-fractal :name "dragon"
                                   :rules dragon-rules
                                   :axiom '(F X)))
  1. draw

We are now ready to draw! We just call the draw function that receives our fractal and the N iterations we want

(draw dragon 10)
  1. Result
  1. Let's pass it through vivus for one last look

3. Interface

defrule symbol -> (newsymbol newsymbol2) :prob 1.00

The macro defrule is used to create a new production rule to rewrite the string.

It recives the symbol to be rewritten, then an -> to symbolize the L-system rule, and then a list of the new symbols to be used. It can also receive a prob argument, which is explained in Stochastic L-systems and it can also use brackets symbols, which are explained in Brackets.

defaristid symbol :angle 0 :len 0 :nodraw nil :color "black"

The macro defaristid is used to create a new aristid.

It receives the name of the symbol we are defining, and a pack of optional arguments which serve as the drawing actions. angle means the change of direction in the current drawing, len means how many dots will be drawn forward (i.e, the length of the line), nodraw can be set to true to only move the direction without actually drawing, and color can be set to any of the 140 HTML color names or even a hex value.

make-fractal :name name :axiom axiom :rules rules

The function make-fractal serves as the constructor for the fractal structure. It receives a name as a string, an axiom which is a list of symbols and the rules which is a list of rules

draw fractal gen

The function draw takes a fractal structure and draws it's gen iteration, saving it in a .svg named fractalname_gen.svg. The function also has an optional background parameter, to change the background color of the drawing.

4. Cool stuff

Brackets

The bracket symbols ([ and ]) are symbols defined by Lindenmayer to save and restore the current direction of the l-system, so that when enclosing a list of symbols between brackets, a new "branch" starts to be drawn. One fractal plant has one of its rules as "(X → F+[[X]-X]-F[-FX]+X)". This can be achieved in cl-aristid with (defrule X -> (F RIGHT [ [ X ] LEFT X ] LEFT F [ LEFT F X ] RIGHT X))

Stochastic L-systems

cl-aristid supports stochastic L-systems, which are systems where rules can be chosen with a certain probability on each iteration of the rewrite. So for example, you want to draw a fractal in which one of it's symbols gets replaced by a list of new symbols only a third of the times it is called, you can define that rule with :prob such as (defrule A -> (A RIGHT B F RIGHT) :prob 0.33)

Colors

The aristids you define have a color argument which can be set to any of the 140 HTML color names or hex value. For example (defaristid A :len 8 :color "purple")

The whole drawing can have a colored background just by adding the background argument to any HTML color in the draw function, such as (draw fractal 10 :background "black")

Everything together

So I hear you want a fractal plant with a gray background which has some branches in white and some in salmon? Hold my parenthesis!

(defaristid F :len 4 :color "white")
(defaristid G :len 4 :color "salmon")
(defaristid LEFT :angle 25)
(defaristid RIGHT :angle -25)

(defparameter freaky-fractal-rules
    (list (defrule F -> (F G) :prob 0.45)
          (defrule G -> (F F) )
          (defrule X -> (F RIGHT [ [ X ] LEFT X ] LEFT F [ LEFT F X ] RIGHT X))))

(defparameter axiom '(LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT X))

(defparameter fractal (make-fractal :name "freaky-fractal-plant"
                                    :rules freaky-fractal-rules
                                    :axiom axiom))

(draw fractal 6 :background "gray")

Rainbows

Add :color "rainbow" to your aristid to give it more groove

(defaristid F :len 2 :color "rainbow")
(defaristid LEFT :angle 90)
(defaristid RIGHT :angle -90)

(defparameter rule-1 (defrule X -> (X F X LEFT Y F LEFT Y F RIGHT F X RIGHT F X LEFT Y F LEFT Y F F X RIGHT Y F RIGHT F X F X Y F LEFT F X RIGHT Y F RIGHT F X F X RIGHT Y F LEFT F X Y F LEFT Y F LEFT F X RIGHT F X RIGHT Y F Y F LEFT)))
(defparameter rule-2 (defrule Y -> (RIGHT F X F X LEFT Y F LEFT Y F RIGHT F X RIGHT F X Y F RIGHT F X LEFT Y F Y F LEFT F X LEFT Y F RIGHT F X Y F Y F LEFT F X LEFT Y F F X RIGHT F X RIGHT Y F LEFT Y F LEFT F X RIGHT F X RIGHT Y F Y)))

(defparameter axiom '(LEFT Y F))

(defparameter fractal (make-fractal :name "freaky-quadratic"
                                    :rules (list rule-1 rule-2)
                                    :axiom axiom))

(draw fractal 3)

<img src="./img/rainbow-quadratic_003.svg" wid


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 cl-aristid

Author

FdelMazo, JDSanto, camidvorkin, anitasec

License

MIT

Description

Draw Lindenmayer Systems with Common LISP!

Version

0.0.2

Dependencies
Source

cl-aristid.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 cl-aristid.asd

Location

cl-aristid.asd

Systems

cl-aristid (system)


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 cl-aristid/package.lisp

Parent

cl-aristid (system)

Location

package.lisp

Packages

cl-aristid


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.3 cl-aristid/cl-aristid.lisp

Dependency

package.lisp (file)

Parent

cl-aristid (system)

Location

cl-aristid.lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.4 cl-aristid/canvas.lisp

Dependency

cl-aristid.lisp (file)

Parent

cl-aristid (system)

Location

canvas.lisp

Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

3.1.5 cl-aristid/fractal.lisp

Dependency

canvas.lisp (file)

Parent

cl-aristid (system)

Location

fractal.lisp

Exported Definitions

make-fractal (function)

Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 cl-aristid

Source

package.lisp (file)

Use List

common-lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Macros

Macro: defaristid NAME &rest BODY
Package

cl-aristid

Source

cl-aristid.lisp (file)

Macro: defrule SYM -> REPLACE &key PROB
Package

cl-aristid

Source

cl-aristid.lisp (file)


Previous: , Up: Exported definitions   [Contents][Index]

5.1.2 Functions

Function: [ CANVAS
Package

cl-aristid

Source

cl-aristid.lisp (file)

Function: ] CANVAS
Package

cl-aristid

Source

cl-aristid.lisp (file)

Function: draw FRACTAL GEN &key BACKGROUND
Package

cl-aristid

Source

cl-aristid.lisp (file)

Function: make-fractal &key (NAME NAME) (AXIOM AXIOM) (RULES RULES)
Package

cl-aristid

Source

fractal.lisp (file)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Functions

Function: %make-canvas &key (MATRIX MATRIX) (DIR DIR) (POINT POINT) (PREV-POINT PREV-POINT) (CORNERS CORNERS) (STACK STACK)
Package

cl-aristid

Source

canvas.lisp (file)

Function: -> OLD NEW &optional PROB
Package

cl-aristid

Source

cl-aristid.lisp (file)

Function: apply-commands CANVAS COMMAND-ARR
Package

cl-aristid

Source

fractal.lisp (file)

Function: aristid &key ANGLE LEN NODRAW COLOR
Package

cl-aristid

Source

cl-aristid.lisp (file)

Function: canvas-corners INSTANCE
Function: (setf canvas-corners) VALUE INSTANCE
Package

cl-aristid

Source

canvas.lisp (file)

Function: canvas-dir INSTANCE
Function: (setf canvas-dir) VALUE INSTANCE
Package

cl-aristid

Source

canvas.lisp (file)

Function: canvas-matrix INSTANCE
Function: (setf canvas-matrix) VALUE INSTANCE
Package

cl-aristid

Source

canvas.lisp (file)

Function: canvas-move CANVAS
Package

cl-aristid

Source

canvas.lisp (file)

Function: canvas-p OBJECT
Package

cl-aristid

Source

canvas.lisp (file)

Function: canvas-point INSTANCE
Function: (setf canvas-point) VALUE INSTANCE
Package

cl-aristid

Source

canvas.lisp (file)

Function: canvas-prev-point INSTANCE
Function: (setf canvas-prev-point) VALUE INSTANCE
Package

cl-aristid

Source

canvas.lisp (file)

Function: canvas-stack INSTANCE
Function: (setf canvas-stack) VALUE INSTANCE
Package

cl-aristid

Source

canvas.lisp (file)

Function: commands N STR RULES
Package

cl-aristid

Source

fractal.lisp (file)

Function: copy-canvas INSTANCE
Package

cl-aristid

Source

canvas.lisp (file)

Function: copy-fractal INSTANCE
Package

cl-aristid

Source

fractal.lisp (file)

Function: create-svg CANVAS BG
Package

cl-aristid

Source

canvas.lisp (file)

Function: d2r DEGREES
Package

cl-aristid

Source

canvas.lisp (file)

Function: draw-fractal FRACTAL GEN BACKGROUND
Package

cl-aristid

Source

fractal.lisp (file)

Function: draw-point CANVAS &optional COLOR
Package

cl-aristid

Source

canvas.lisp (file)

Function: flatten TREE
Package

cl-aristid

Source

fractal.lisp (file)

Function: fractal-axiom INSTANCE
Function: (setf fractal-axiom) VALUE INSTANCE
Package

cl-aristid

Source

fractal.lisp (file)

Function: fractal-name INSTANCE
Function: (setf fractal-name) VALUE INSTANCE
Package

cl-aristid

Source

fractal.lisp (file)

Function: fractal-p OBJECT
Package

cl-aristid

Source

fractal.lisp (file)

Function: fractal-rules INSTANCE
Function: (setf fractal-rules) VALUE INSTANCE
Package

cl-aristid

Source

fractal.lisp (file)

Function: get-next-color ()
Package

cl-aristid

Source

canvas.lisp (file)

Function: make-canvas ()
Package

cl-aristid

Source

canvas.lisp (file)

Function: pop-stack CANVAS
Package

cl-aristid

Source

canvas.lisp (file)

Function: push-stack CANVAS
Package

cl-aristid

Source

canvas.lisp (file)

Function: random-increase COLOR
Package

cl-aristid

Source

canvas.lisp (file)

Function: rotate-dir DIR ANGLE
Package

cl-aristid

Source

canvas.lisp (file)

Function: string-rewrite STR RULES
Package

cl-aristid

Source

fractal.lisp (file)

Function: svg-add-iteration SVG CANVAS
Package

cl-aristid

Source

canvas.lisp (file)

Function: turn-angle CANVAS ANGLE
Package

cl-aristid

Source

canvas.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Structures

Structure: canvas ()
Package

cl-aristid

Source

canvas.lisp (file)

Direct superclasses

structure-object (structure)

Direct slots
Slot: matrix
Readers

canvas-matrix (function)

Writers

(setf canvas-matrix) (function)

Slot: dir
Readers

canvas-dir (function)

Writers

(setf canvas-dir) (function)

Slot: point
Readers

canvas-point (function)

Writers

(setf canvas-point) (function)

Slot: prev-point
Readers

canvas-prev-point (function)

Writers

(setf canvas-prev-point) (function)

Slot: corners
Readers

canvas-corners (function)

Writers

(setf canvas-corners) (function)

Slot: stack
Readers

canvas-stack (function)

Writers

(setf canvas-stack) (function)

Structure: fractal ()
Package

cl-aristid

Source

fractal.lisp (file)

Direct superclasses

structure-object (structure)

Direct slots
Slot: name
Readers

fractal-name (function)

Writers

(setf fractal-name) (function)

Slot: axiom
Readers

fractal-axiom (function)

Writers

(setf fractal-axiom) (function)

Slot: rules
Readers

fractal-rules (function)

Writers

(setf fractal-rules) (function)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   C   F   L  
Index Entry  Section

C
cl-aristid.asd: The cl-aristid․asd file
cl-aristid/canvas.lisp: The cl-aristid/canvas․lisp file
cl-aristid/cl-aristid.lisp: The cl-aristid/cl-aristid․lisp file
cl-aristid/fractal.lisp: The cl-aristid/fractal․lisp file
cl-aristid/package.lisp: The cl-aristid/package․lisp file

F
File, Lisp, cl-aristid.asd: The cl-aristid․asd file
File, Lisp, cl-aristid/canvas.lisp: The cl-aristid/canvas․lisp file
File, Lisp, cl-aristid/cl-aristid.lisp: The cl-aristid/cl-aristid․lisp file
File, Lisp, cl-aristid/fractal.lisp: The cl-aristid/fractal․lisp file
File, Lisp, cl-aristid/package.lisp: The cl-aristid/package․lisp file

L
Lisp File, cl-aristid.asd: The cl-aristid․asd file
Lisp File, cl-aristid/canvas.lisp: The cl-aristid/canvas․lisp file
Lisp File, cl-aristid/cl-aristid.lisp: The cl-aristid/cl-aristid․lisp file
Lisp File, cl-aristid/fractal.lisp: The cl-aristid/fractal․lisp file
Lisp File, cl-aristid/package.lisp: The cl-aristid/package․lisp file

Jump to:   C   F   L  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   %   (   -   [   ]  
A   C   D   F   G   M   P   R   S   T  
Index Entry  Section

%
%make-canvas: Internal functions

(
(setf canvas-corners): Internal functions
(setf canvas-dir): Internal functions
(setf canvas-matrix): Internal functions
(setf canvas-point): Internal functions
(setf canvas-prev-point): Internal functions
(setf canvas-stack): Internal functions
(setf fractal-axiom): Internal functions
(setf fractal-name): Internal functions
(setf fractal-rules): Internal functions

-
->: Internal functions

[
[: Exported functions

]
]: Exported functions

A
apply-commands: Internal functions
aristid: Internal functions

C
canvas-corners: Internal functions
canvas-dir: Internal functions
canvas-matrix: Internal functions
canvas-move: Internal functions
canvas-p: Internal functions
canvas-point: Internal functions
canvas-prev-point: Internal functions
canvas-stack: Internal functions
commands: Internal functions
copy-canvas: Internal functions
copy-fractal: Internal functions
create-svg: Internal functions

D
d2r: Internal functions
defaristid: Exported macros
defrule: Exported macros
draw: Exported functions
draw-fractal: Internal functions
draw-point: Internal functions

F
flatten: Internal functions
fractal-axiom: Internal functions
fractal-name: Internal functions
fractal-p: Internal functions
fractal-rules: Internal functions
Function, %make-canvas: Internal functions
Function, (setf canvas-corners): Internal functions
Function, (setf canvas-dir): Internal functions
Function, (setf canvas-matrix): Internal functions
Function, (setf canvas-point): Internal functions
Function, (setf canvas-prev-point): Internal functions
Function, (setf canvas-stack): Internal functions
Function, (setf fractal-axiom): Internal functions
Function, (setf fractal-name): Internal functions
Function, (setf fractal-rules): Internal functions
Function, ->: Internal functions
Function, apply-commands: Internal functions
Function, aristid: Internal functions
Function, canvas-corners: Internal functions
Function, canvas-dir: Internal functions
Function, canvas-matrix: Internal functions
Function, canvas-move: Internal functions
Function, canvas-p: Internal functions
Function, canvas-point: Internal functions
Function, canvas-prev-point: Internal functions
Function, canvas-stack: Internal functions
Function, commands: Internal functions
Function, copy-canvas: Internal functions
Function, copy-fractal: Internal functions
Function, create-svg: Internal functions
Function, d2r: Internal functions
Function, draw: Exported functions
Function, draw-fractal: Internal functions
Function, draw-point: Internal functions
Function, flatten: Internal functions
Function, fractal-axiom: Internal functions
Function, fractal-name: Internal functions
Function, fractal-p: Internal functions
Function, fractal-rules: Internal functions
Function, get-next-color: Internal functions
Function, make-canvas: Internal functions
Function, make-fractal: Exported functions
Function, pop-stack: Internal functions
Function, push-stack: Internal functions
Function, random-increase: Internal functions
Function, rotate-dir: Internal functions
Function, string-rewrite: Internal functions
Function, svg-add-iteration: Internal functions
Function, turn-angle: Internal functions
Function, [: Exported functions
Function, ]: Exported functions

G
get-next-color: Internal functions

M
Macro, defaristid: Exported macros
Macro, defrule: Exported macros
make-canvas: Internal functions
make-fractal: Exported functions

P
pop-stack: Internal functions
push-stack: Internal functions

R
random-increase: Internal functions
rotate-dir: Internal functions

S
string-rewrite: Internal functions
svg-add-iteration: Internal functions

T
turn-angle: Internal functions

Jump to:   %   (   -   [   ]  
A   C   D   F   G   M   P   R   S   T  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   A   C   D   M   N   P   R   S  
Index Entry  Section

A
axiom: Internal structures

C
corners: Internal structures

D
dir: Internal structures

M
matrix: Internal structures

N
name: Internal structures

P
point: Internal structures
prev-point: Internal structures

R
rules: Internal structures

S
Slot, axiom: Internal structures
Slot, corners: Internal structures
Slot, dir: Internal structures
Slot, matrix: Internal structures
Slot, name: Internal structures
Slot, point: Internal structures
Slot, prev-point: Internal structures
Slot, rules: Internal structures
Slot, stack: Internal structures
stack: Internal structures

Jump to:   A   C   D   M   N   P   R   S  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   C   F   P   S  
Index Entry  Section

C
canvas: Internal structures
cl-aristid: The cl-aristid system
cl-aristid: The cl-aristid package

F
fractal: Internal structures

P
Package, cl-aristid: The cl-aristid package

S
Structure, canvas: Internal structures
Structure, fractal: Internal structures
System, cl-aristid: The cl-aristid system

Jump to:   C   F   P   S