clojure-art

meow 2015-09-21T13:52:34.000012Z

Anyone interested in the use of L-systems for generative art? https://github.com/decomplect/ion/blob/master/src/ion/ergo/l_system.cljc

quentin 2015-09-21T13:55:58.000016Z

nice, i have been playing with l systems before, will take a look at this :simple_smile:

meow 2015-09-21T13:56:06.000017Z

You can use it to easily create fractal data.

quentin 2015-09-21T13:56:52.000019Z

nice one :simple_smile:

2015-09-21T13:57:03.000020Z

l-system poetry is awesome too 😄

meow 2015-09-21T13:57:38.000021Z

@quentin: let me know what you think. I've worked hard on making the code as beautiful as the algorithm.

meow 2015-09-21T13:59:11.000022Z

The code for the fractal I posted is in a devcard here: https://github.com/decomplect/ive/blob/master/src/ive/ergo/lindenmayer.cljs

quentin 2015-09-21T13:59:53.000024Z

pkobrien: at first side it look like really nice code :simple_smile: but i will take some time to read it correctly and play with it (at work here^^)

meow 2015-09-21T14:00:07.000025Z

(defn dragon-sequence
  "Returns a lazy sequence of vectors."
  []
  (let [axiom [:F :x]
        rules {:x [:x :+ :y :F :+]
               :y [:- :F :x :- :y]}]
    (basic-system axiom rules)))

(def dragon-render-rules {:F [:fwd 30]
                          :+ [:right 90 :fwd 5 :left 45 :fwd 15 :right 45 :fwd 5]
                          :- [:left 90 :fwd 15 :right 45 :fwd 5 :left 45 :fwd 15]
                          \[ [:save]
                          \] [:restore]
                          :x []
                          :y []})

meow 2015-09-21T14:01:01.000026Z

@quentin: cool, thanks. It leverages transducers and a simple protocol for parametric systems.

meow 2015-09-21T14:02:20.000027Z

@coledubs: The l-system code is completely agnostic about the words and modules that it processes, so it should be completely possible to create poetry as well, though I've not tried that.

meow 2015-09-21T14:02:55.000028Z

@coledubs: have you created poetry with l-systems? Got any examples?

2015-09-21T14:03:39.000029Z

https://github.com/aparrish/linear-lsystem-poetry is one example

2015-09-21T14:04:28.000031Z

i cant find where the demo is hosted :< but instead of moving in directions its like "add a newline" or "add the next line from the poem" and so on

meow 2015-09-21T14:12:09.000032Z

@coledubs: very interesting - I'll have to add that to my list of ways to render l-systems data along with turtle graphics and music.

2015-09-21T14:12:44.000033Z

im working on a generative sequencer thing in overtone/clojure, now im wondering if i can add lsystems to it somehow O_O

meow 2015-09-21T14:12:54.000034Z

This looks like the link to the demo: http://static.decontextualize.com/lsys/

quentin 2015-09-21T14:13:28.000035Z

lsystems in music would be pretty cool :simple_smile:

meow 2015-09-21T14:13:34.000036Z

@coledubs: seriously? That would be awesome. Overtone was on my todo list, but I've also been looking closely at Alda.

meow 2015-09-21T14:15:40.000037Z

I haven't released my l-system code on clojars yet, but I think it's pretty solid and I'm now happy with how it handles parametric modules, which is basically just a simple protocol so any deftype or defrecord that implements the protocol can work.

2015-09-21T14:16:41.000038Z

the code im using to control drums is like [1 0.5 1 0.25 ] and so on, so an l-system could probably generate all the probabilities for me 😄 thus saving a whole lot of typing

meow 2015-09-21T14:16:57.000039Z

@coledubs: totally

2015-09-21T14:17:44.000040Z

and it could generate it live, or have the parameters be controlled by something else...

meow 2015-09-21T14:17:47.000041Z

not just that, but I support function calls, arbitrary parametric data, and changing of rules for each generation, so you can do some really crazy stuff

meow 2015-09-21T14:18:32.000042Z

here is an example, just to see how easy it is to write rules like I described:

(deftype TModule [key age]
  ls/Module
  (module [_] key)
  Object
  (toString [_] (str "&lt;" key " " age "&gt;")))

(defmethod clojure.core/print-method TModule [x writer]
  (.write writer (str x)))

(defn type-module-example
  []
  (let [axiom [(-&gt;TModule :A 0)]
        rules {:A (fn [g w i m]
                    [(-&gt;TModule :B 0)
                     :-
                     (-&gt;TModule (.key m) (inc (.-age m)))
                     :-
                     (-&gt;TModule :B 0)])
               :B (fn [g w i m]
                    [(-&gt;TModule :A 0)
                     :+
                     (-&gt;TModule (.key m) (inc (.-age m)))
                     :+
                     (-&gt;TModule :A 0)])}]
    (ls/parametric-context-sensitive-system axiom rules)))

meow 2015-09-21T14:19:56.000043Z

the g w i m is the context-sensitive data passed to the function: generation, word, index, module

2015-09-21T14:20:33.000044Z

hmmm that first example you pasted made more sense to me...but i'm intrigued!

meow 2015-09-21T14:22:07.000045Z

let's say you want to build into the rules that the sounds being generated get louder for each generation, you need a way to add those parameters to the module in a context-sensitive way, similar to the way I'm incrementing the age of the module

meow 2015-09-21T14:24:13.000046Z

suffice it to say that after numerous attempts to allow parametric systems that are easy to define and perform well, I think the best solution is to use deftype and defrecord and a protocol. This is only needed for this most advanced form of parametric context-sensitive and (optionally) stochastic systems.

meow 2015-09-21T14:25:10.000047Z

The dragon fractal I posted is just a basic system.

meow 2015-09-21T14:26:28.000048Z

But if I wanted it to have some randomness, or have segments that are a different color or thickness based on its neighbor segments, or I want to fiddle with the rules for each generation so it morphs over time, there has to be a way to define those characteristics in the rules.

meow 2015-09-21T14:27:29.000049Z

Similarly for music, I think there will need to be parameters to make the output something that doesn't sound overly robotic or dull.

meow 2015-09-21T14:32:38.000050Z

I've got some examples here: https://github.com/decomplect/ion/blob/master/examples/ion/ergo/l_system_examples.cljc

jellea 2015-09-21T14:38:50.000052Z

coledubs: do you have some code online for the gen drums? :simple_smile:

2015-09-21T14:39:44.000053Z

https://github.com/coleww/overtone-live-coding um it is probably not in a running state currently...you kinda have to eval the files in a very specific order O_O

jellea 2015-09-21T14:39:47.000055Z

Think core.logic would be fun as well for generative stuff. Generating input for the Lsystems for instance

2015-09-21T14:40:39.000056Z

https://github.com/coleww/overtone-live-coding/blob/master/src/my_symphony/sequencer.clj this is the main thing, and /songs/blzrs.clj should be working "data" for the current version. the other songs are deprecated 😆

2015-09-21T14:42:20.000058Z

@meow: i'm thinking that even a simple l-system applied to a drum loop would be useful. being able to write 4 notes and have it expand to 16 or 48 beats or what have you would be really powerful, especially if I change the l-system rules on the fly too

meow 2015-09-21T14:47:31.000059Z

@coledubs: I agree. I don't know Overtone, but let me know if there's anything I can do to help with the l-system. It should be very easy to start with something basic and then add complexity one little step at a time as you get comfortable with how it works.

meow 2015-09-21T14:48:32.000060Z

One of the next things I'm going to do is make it easier to support cellular automata in the L-system.

2015-09-21T14:48:47.000061Z

i remember coding a simple turtle graphic thing in javascript, i might just write a simple script specific to my horrible notation format I have created. but im definitely interested in working with the library if you publish it

meow 2015-09-21T14:50:00.000062Z

@coledubs: you could certainly use the library from github. I may publish it to clojure today or tomorrow as well.

meow 2015-09-21T14:51:05.000063Z

I was holding off because I just wasn't 100% happy with the code and it has gone through some major refactoring but I think I've got it as simplified and decomplected as I can, and I think the API will be stable.

meow 2015-09-21T14:51:50.000064Z

cellular automata support won't change the existing api

meow 2015-09-21T14:57:55.000065Z

@coledubs: to translate the l-system sequence into your drum notation format all you need to do is some variation of mapping, like was done with the dragon fractal I posted above. Here is the code that takes the l-system dragon output and turns it into turtle commands:

(defn dragon-render-sequence
  []
  (map #(into [] (comp (replace dragon-render-rules) cat) %) (dragon-sequence)))

meow 2015-09-21T14:59:36.000067Z

gotta love transducers :simple_smile: