Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Botany with Bytes

Botany with Bytes

Botany with Bytes, for LA Ruby Conf 2015 and RubyConf 2015!

(Video coming soon)

Lito Nicolai

April 14, 2015
Tweet

More Decks by Lito Nicolai

Other Decks in Programming

Transcript

  1. RubyConf 2015 - Lito Nicolai - @lito_nico This talk uses

    graphics! $ gem install --pre graphics
  2. RubyConf 2015 - Lito Nicolai - @lito_nico A A B

    A B A A B A A B A B A A B A B A A B A A B A B A A B A A B incidentally, Fibonacci
  3. RubyConf 2015 - Lito Nicolai - @lito_nico What strings can

    you make with rules? Montana State University Mathematics (grids, lines… things) A ! AB B ! A
  4. RubyConf 2015 - Lito Nicolai - @lito_nico What strings can

    you match with these rules? -?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?
  5. RubyConf 2015 - Lito Nicolai - @lito_nico Organizing Grammars RegEx

    Lindenmayer & Prusinkiewicz (needs a DFA) (using computers)
  6. RubyConf 2015 - Lito Nicolai - @lito_nico (let’s ignore finite

    grammars) RegEx Lindenmayer & Prusinkiewicz
  7. RubyConf 2015 - Lito Nicolai - @lito_nico RegEx HTML Lindenmayer

    & Prusinkiewicz Chomsky Hierarchy (needs a stack)
  8. RubyConf 2015 - Lito Nicolai - @lito_nico RegEx HTML Lindenmayer

    & Prusinkiewicz C++ Chomsky Hierarchy (needs RAM)
  9. RubyConf 2015 - Lito Nicolai - @lito_nico Ruby? RegEx HTML

    Lindenmayer & Prusinkiewicz Chomsky Hierarchy C++
  10. RubyConf 2015 - Lito Nicolai - @lito_nico Chomsky Hierarchy Ruby?

    RegEx HTML Perl Lindenmayer & Prusinkiewicz C++
  11. RubyConf 2015 - Lito Nicolai - @lito_nico Chomsky Hierarchy RegEx

    HTML Perl Lindenmayer & Prusinkiewicz Ruby? C++
  12. RubyConf 2015 - Lito Nicolai - @lito_nico Chomsky Hierarchy RegEx

    HTML Perl Lindenmayer & Prusinkiewicz Ruby? C++
  13. RubyConf 2015 - Lito Nicolai - @lito_nico ((((((X)))))) Can match

    this ^ (regex can’t match either) Nested Balanced Parens ((((((())))))) But not this ^
  14. RubyConf 2015 - Lito Nicolai - @lito_nico class LSystem attr_reader

    :state def initialize state, rules @state = state @rules = rules end def step @state = @state.split("") .map {|s| @rules[s] } .join self end end
  15. RubyConf 2015 - Lito Nicolai - @lito_nico class LSystem attr_reader

    :state def initialize state, rules @state = state @rules = rules end def step @state = @state.split("") .map {|s| @rules[s] } .join self end end
  16. RubyConf 2015 - Lito Nicolai - @lito_nico @state = @state.split("")

    .map {|s| @rules[s] } .join "AB" "A" "B" "AB" "A" "ABA" split apply rules join
  17. RubyConf 2015 - Lito Nicolai - @lito_nico > l =

    LSystem.new "A", "A" => "AB", "B" => "A" > l.step => "AB" > l.step => "ABA" > l.step => "ABAAB" > l.step => "ABAABABA"
  18. RubyConf 2015 - Lito Nicolai - @lito_nico Leaf ! Stem

    LeftLeaf RightLeaf Stem ! Stem Stem Sprout
  19. RubyConf 2015 - Lito Nicolai - @lito_nico > turtle =

    Turtle.new “S[S", "S" => :forward, "L" => :forward, "[" => [:left, 60], "]" => [:right, 60], "." => :push, "," => :pop
  20. RubyConf 2015 - Lito Nicolai - @lito_nico > turtle =

    Turtle.new “S[S", "S" => :forward, "L" => :forward, "[" => [:left, 60], "]" => [:right, 60], "." => :push, "," => :pop
  21. RubyConf 2015 - Lito Nicolai - @lito_nico > turtle =

    Turtle.new “S[S", "S" => :forward, "L" => :forward, "[" => [:left, 60], "]" => [:right, 60], "." => :push, "," => :pop
  22. RubyConf 2015 - Lito Nicolai - @lito_nico > turtle =

    Turtle.new “S[S", "S" => :forward, "L" => :forward, "[" => [:left, 60], "]" => [:right, 60], "." => :push, "," => :pop
  23. RubyConf 2015 - Lito Nicolai - @lito_nico Leaf ! Stem

    LeftLeaf RightLeaf Stem ! Stem Stem Sprout
  24. RubyConf 2015 - Lito Nicolai - @lito_nico “LeftLeaf” SaveState TurnLeft

    Leaf . [ L “RightLeaf” RestoreState TurnRight Leaf , ] L At the end of a stem…
  25. RubyConf 2015 - Lito Nicolai - @lito_nico > turtle =

    Turtle.new sprout.state, "S" => :forward, "L" => :forward, "[" => [:left, 60], "]" => [:right, 60], "." => :push, "," => :pop > sprout = LSystem.new "L", "L" => “S.[L,]L", "S" => “SS”, "[" => "[", "]" => "]", "." => ".", "," => ","
  26. RubyConf 2015 - Lito Nicolai - @lito_nico (is what I

    used to say) Yes, they really look like this! Drosera Binata var. Multifida
  27. RubyConf 2015 - Lito Nicolai - @lito_nico btw, Alan Turing

    Hypothesis of General Phyllotaxis (…and later, even deeper work)
  28. RubyConf 2015 - Lito Nicolai - @lito_nico Start: Stem Rules:

    Stem ! Stem Rotate Leaf Leaf ! BiggerLeaf Use an L-System!
  29. RubyConf 2015 - Lito Nicolai - @lito_nico Start: Stem Rules:

    Stem ! Stem Rotate Leaf Leaf ! BiggerLeaf
  30. RubyConf 2015 - Lito Nicolai - @lito_nico Kinds of Surfaces

    Spherical Positive Curvature Flat No Curvature
  31. RubyConf 2015 - Lito Nicolai - @lito_nico Kinds of Surfaces

    Spherical Positive Curvature Flat No Curvature Hyperbolic Negative Curvature
  32. RubyConf 2015 - Lito Nicolai - @lito_nico Kinds of Surfaces

    Spherical Positive Curvature Flat No Curvature Hyperbolic Negative Curvature Plants!
  33. RubyConf 2015 - Lito Nicolai - @lito_nico Lito:~$ perl -E

    'sub dunno() { 3 } say dunno + 4' 7 Lito:~$ _
  34. RubyConf 2015 - Lito Nicolai - @lito_nico Lito:~$ perl -E

    'sub dunno() { 3 } say dunno + 4' 7 Lito:~$ perl -E 'sub dunno { 3 } say dunno + 4'
  35. RubyConf 2015 - Lito Nicolai - @lito_nico Lito:~$ perl -E

    'sub dunno() { 3 } say dunno + 4' 7 Lito:~$ perl -E 'sub dunno { 3 } say dunno + 4’ 3 Lito:~$ _
  36. RubyConf 2015 - Lito Nicolai - @lito_nico Lito:~$ perl -E

    'sub dunno() { 3 } say dunno + 4' 7 Lito:~$ perl -E 'sub dunno { 3 } say dunno + 4’ 3 Lito:~$ _ no args (‘nullary’) some args
  37. RubyConf 2015 - Lito Nicolai - @lito_nico perl -E 'BEGIN

    { *dunno = sub() { 3 } } say dunno + 4'
  38. RubyConf 2015 - Lito Nicolai - @lito_nico perl -E 'BEGIN

    { *dunno = sub() { 3 } } say dunno + 4' BEGIN { *dunno = sub { 3 } } say dunno + 4
  39. RubyConf 2015 - Lito Nicolai - @lito_nico perl -E 'BEGIN

    { *dunno = sub() { 3 } } say dunno + 4' BEGIN { *dunno = sub { 3 } } say dunno + 4 BEGIN { if # SOME_CONDITION *dunno = sub { 3 } else { *dunno = sub() { 3 } } } say dunno + 4 any code!