Fork me on GitHub
#devcards
<
2015-09-21
>
meow13:09:50

(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 20]
                          :+ [:right 90]
                          :- [:left 90]
                          \[ [:save]
                          \] [:restore]
                          :x []
                          :y []})

meow13:09:37

(defn show-x4! []
  (let [canvas (goog.dom/getElement "canvas-x4")
        context (.getContext canvas "2d")
        dragon (concat [:save] (nth (get-in @app-state [:dragon]) 10) [:restore])
        x4 (concat [:color-index 0]
                   dragon
                   [:right 90 :color-index 1]
                   dragon
                   [:right 90 :color-index 2]
                   dragon
                   [:right 90 :color-index 5]
                   dragon
                   )]
    (turtle/draw! (trc/->canvas context) x4 [900 900])))

meow14:09:45

@darwin: that looks sweet!

meow14:09:01

I still need to create a proper React component for a canvas in devcards.

meow14:09:24

What I have now is just a total hack.

darwin14:09:33

@meow: thanks, canvas should be pretty straightforward, I think, I use reagent, it gives me access to react lifecycle functions, so I can render graphs using some non-react js-library (d3)

darwin14:09:40

renders as svg

darwin14:09:29

also working on this: https://www.dropbox.com/s/0mte4cfz9d6p0lc/Screenshot%202015-09-21%2016.10.01.png?dl=0, to visualize how tools.reader with postprocessing parsed given source file

meow14:09:04

@darwin: Wow. Great stuff. Makes it so much easier when you can visualize stuff in living color, right? Very nice.

meow14:09:41

I agree that canvas should be easy, but nobody has done it from what I can find.

darwin14:09:39

@meow: and I have also tooltips and can encode some stuff into DOM, so I can easily inspect my nested data structures using devtools via “inspect element” simple_smile

meow14:09:09

@darwin: no matter what becomes of plastic, it seems like you are developing some awesome capabilities with the work you are doing.

darwin14:09:18

@meow: that last devcard with parsed data is quite handy, it is not obvious from the screenshot, but it is an overlay on top of original plain source code with some opacity, so I can immediately spot inconsistencies: https://www.dropbox.com/s/wjrqg4e9acc9rjd/Screenshot%202015-09-21%2016.34.54.png?dl=0

meow14:09:38

@darwin: now that's clever! simple_smile

darwin15:09:20

@meow: FYI, just hit https://github.com/bhauman/devcards/issues/35, relevant to your recent PR

darwin15:09:12

have to go...

bhauman17:09:02

you guys !!!! this is awesome.

bhauman18:09:19

@darwin can I post you devcards pngs on twitter? "Devcards in the wild"

meow18:09:58

@darwin: thanks for the bug report on devcards - I responded there.

bhauman18:09:01

@meow: love the fractals man

meow18:09:46

@bhauman: I've got on my todo list to set up my github so that I can "publish" my devcards - not sure how much time/effort that represents

meow18:09:16

I'm assuming that part of your project.clj file for devcards does this already for the cards you have at http://rigsomelight.com/devcards/#!/

meow18:09:48

Was hoping I could do something similar using github or github pages?

meow18:09:11

Would make it easier to show off the fractals.

bhauman18:09:20

I created a separate build that writes to a directory that I share with the gh-pages branch

meow18:09:38

@bhauman: Any chance of devcards getting a "publish to gh-pages" feature?

meow18:09:28

I actually have plans to create an entire site primarily using devcards so I could really use a feature like that.

meow18:09:03

by site I just mean I have a github org that I plan to use as a sort of gallery/tutorial site: https://github.com/algorithmic-beauty

meow18:09:02

If this was built into devcards then more of us might publish our cards, which would help spread the word about devcards... 😉

darwin18:09:51

@bhauman: you are welcome to share them

bhauman18:09:45

@meow Well look at the bottom of devcards core.cljs mount-namespace

darwin18:09:11

I will also soon want to build gh-pages branch for plastic where I will show some devcards and editor states

bhauman18:09:34

I wrote code to render a ns as a webpage but it is still early

bhauman18:09:23

The idea is you can call the mount namespace call from js at the bottom of your HTML file

meow18:09:44

This is one of those cases where I just want something easy. I don't really care how it works. simple_smile

bhauman18:09:08

@meow: can you post a shot of your cards I can share?

darwin18:09:59

@bhauman: I hope that at some point in future I will be able to present whole plastic editor instance as a devcard, so I will be able to show/test different editor states

darwin18:09:15

that will be my ultimate devcard simple_smile

bhauman18:09:25

That would be amazing!

bhauman18:09:59

@darwin did you look at the iDevcardOptions protocol? It allows you to intercept the devcard options and manipulate them.

darwin18:09:10

@bhauman: no, didn’t know about it, how it could help? btw. I solved my edn/code problem by building markdown code block and passing in a string

bhauman19:09:39

@darwin: it would let you implement your functionality without going so low level with register-card because you can intercept the options and change them as you will. for your case you could write a function that reifys a IDevcardOptions and just return the options as you need them, that way you don't have to mess with the path stuff etc.

bhauman19:09:48

I need to document it of course

darwin19:09:12

@bhauman: thanks, good to know, actually I started messing with macros and then switched to this low level solution, because top-level macro defcard didn’t work well for me, I needed to define documentation as string concatenation and the macro parameter detection logic worked against me, will look into IDevcardOptions

bhauman19:09:07

well this protocol would allow you to specify any parameters you want to the defcard macro (defcard name (mything options))

darwin19:09:11

why path isn’t part of the options? I like that I can simplify it, my namespaces are too long for display

bhauman19:09:50

well I just didn't think that would be a problem

meow19:09:53

@bhauman: I'll see if I can come up with a screenshot. Would really love to just be able to publish the darn page.

bhauman19:09:19

Yeah I get that

meow19:09:56

Have I mentioned that one way to view Devcards is as a publishing platform? 😉

bhauman19:09:48

That is beautiful

meow19:09:23

Cool. NP.

meow19:09:29

I'm really happy with my L-system code. Finally. Took a while to get it to where I wanted it to be. Can't wait to max it out and do really crazy things with it.

meow19:09:08

The fractals are nice, but they've been done to death.

bhauman19:09:44

That is great!!! I saw a talk yesterday about cellular automata

meow19:09:44

I need to do them, just because I can. But I really want to push beyond what's already been done.

meow19:09:30

Funny, the next thing I'm working on is supporting CA in L-systems. It can be done, but I want to make it even easier.

bhauman19:09:54

Very cool...

meow19:09:26

I'm really leveraging transducers, which worked out really well. I absolutely love those things. Transducers, for me, are one of the most foundational things that Clojure has brought to the table. I think transducers will be implemented in all sorts of languages and ultimately taken for granted.

meow19:09:41

And then working on support for parametric L-systems drove me to finally learn deftype, defrecord and protocol. And that worked out really well.

darwin19:09:50

transducers are cool, but for most common cases laziness is enough when working with sequences, that is why I don’t think many people will learn transducers and will be using them on day-to-day basis

meow19:09:39

I like that they allow me to think about a problem like these L-systems from a process point-of-view and that I can comp a bunch of xfs together and they will efficiently perform those operations on that data stream.

meow19:09:38

I'm still tickled that after having a number of variations of processes to support every variety of L-system that I can find documentation about that I've managed to boil it down to such a small amount of code, including recently getting it down to just one process function:

(defn produce
  "Returns a lazy sequence of words from a recursive, axiomatic, transducible
   process."
  [get-xf]
  (letfn [(process [w]
                   (lazy-seq
                     (when (seq w)
                       (let [v (vec w)
                             word (into [] (get-xf v) v)]
                         (cons word (process word))))))]
    (process jumpstart)))

meow19:09:57

And the most sophisticated L-system is built out of parts with just this little bit of code:

(defn parametric-context-sensitive-system
  "Returns a lazy sequence of words from a context-sensitive rewriting
   process. Allows a rewrite successor to (optionally) be a function that will
   get called with the current context as arguments."
  [axiom rules]
  (produce (gen (fn [g w]
                  (comp (modulating)
                        (rewriting axiom rules g)
                        (calling g w)
                        cat)))))

meow19:09:48

Anyhow, sorry for hijacking this channel...

meow19:09:31

@bhauman: What CA talk did you see?