class: center, middle, inverse, title-slide # > 👨🎨 🥼
> functional programming
> for artists (and scientists) ###
danielle navarro
--- layout: true <div class="my-footer"> <!-- <span> <a href="https://robust-tools.djnavarro.net" target="_blank">robust-tools.djnavarro.net</a> </span> --> </div> --- class: middle, inverse ## https://github.com/djnavarro/ashtree --- class: middle background-image: url("img/scrawl_17-1000-400-100-5.png") background-size: cover .pull-left-wide[ .bigly-hotpink-text[scrawl]<br> .embolden[ ... that thing we did last time! 😄] ] --- class: middle background-image: url("img/scrawl_17-1000-400-100-5.png") background-size: cover <br><br><br><br><br><br> ## github.com/djnavarro/scrawl --- class: inverse .hand[our goals!] - write your own R functions - use functions to write a new generative art system - introduction to functional programming with "purrr" --- class: middle background-image: url("img/fern_20_13.png") background-size: cover .pull-left-wide[ .biggish-hotpink-text[flametree]<br> ] --- class: middle background-image: url("img/fern_21_13.png") background-size: cover <br><br><br><br><br><br><br><br><br><br> ## <span style="color:white;font-weight:800%">github.com/djnavarro/flametree</span> --- class: middle background-image: url("img/ashtree2.png") background-size: cover .pull-left-wide[ .biggish-hotpink-text[ashtree]<br> ] --- class: middle background-image: url("img/ashtree2.png") background-size: cover -- .pull-left-wide[ .bigly-hotpink-text[why?]<br> ] .pull-right[ <br><br> .embolden[ why write with functions?] ] --- class: middle - breaks code into meaningful chunks - breaks code into reusable chunks - assign helpful names to code chunks - separate user-relevant and internal code - building blocks for packages --- class: middle background-image: url("img/ashtree.png") background-size: cover .pull-left-wide[ .bigly-hotpink-text[how?]<br> ] .pull-right[ <br><br><br><br><br> .embolden[ how do we write R functions?] ] --- class: inverse, middle ## .hand[live coding #1...] --- class: inverse .hand[ Let's take a look at the structure of this function! ] ![](img/function_00.png)<!-- --> --- class: middle background-image: url("img/ashtree3.png") background-size: cover .pull-left-wide[ .bigly-hotpink-text[what]<br> .embolden[ what are the parts of a function?] ] --- ![](img/function_01.png)<!-- --> -- - functions are regular R objects - given a name using `<-` - arguments are "labels" for user input - return an object to the user --- ![](img/function_02.png)<!-- --> -- - things in the function "body" are hidden - i.e. function runs in its own "environment" --- class: inverse, middle ## .hand[live coding #2...] --- class: middle background-image: url("img/ashtree6.png") background-size: cover --- class: inverse ![](img/Relations1.png)<!-- --> --- class: inverse ![](img/Relations2.png)<!-- --> --- class: inverse ![](img/Relations3.png)<!-- --> --- class: inverse ![](img/Relations4.png)<!-- --> --- class: inverse ![](img/Grow1.png)<!-- --> --- class: inverse ![](img/Grow2.png)<!-- --> --- class: inverse ![](img/Grow3.png)<!-- --> --- class: inverse, middle ## .hand[sweetie, we need to talk...] ## .hand[...about iteration] --- class: inverse ![](img/Tree1.png)<!-- --> --- class: inverse ![](img/Tree2.png)<!-- --> --- class: inverse ![](img/Tree3.png)<!-- --> --- class: inverse ![](img/Tree4.png)<!-- --> --- background-color: #8B3A62 ![](img/For1.png)<!-- --> --- background-color: #8B3A62 ![](img/For2.png)<!-- --> --- background-color: #8B3A62 ![](img/For3.png)<!-- --> --- background-color: #8B3A62 ![](img/For4.png)<!-- --> --- background-color: #8B3A62 ![](img/For5.png)<!-- --> --- background-color: #8B3A62 ![](img/For6.png)<!-- --> --- background-color: #8B3A62 ![](img/For7.png)<!-- --> --- background-color: #8B3A62 ![](img/For8.png)<!-- --> --- background-color: #8B3A62 ![](img/For9.png)<!-- --> --- background-color: #8B3A62 ![](img/For10.png)<!-- --> --- background-color: #8B3A62 ![](img/For11.png)<!-- --> --- background-color: #8B3A62 ![](img/For12.png)<!-- --> --- background-color: #8B3A62 ![](img/For13.png)<!-- --> --- background-color: #8B3A62 ![](img/For14.png)<!-- --> --- background-color: #8B3A62 ![](img/For15.png)<!-- --> --- background-color: #8B3A62 ![](img/For16.png)<!-- --> --- background-color: #8B3A62 ![](img/For17.png)<!-- --> --- background-color: #8B3A62 ![](img/For18.png)<!-- --> --- class: inverse, middle ## .hand[ugh, feels so clunky.] ## .hand[surely there's a simpler way?] --- ![](img/Map1.png)<!-- --> --- ![](img/Map2.png)<!-- --> --- ![](img/Map3.png)<!-- --> --- ![](img/Map4.png)<!-- --> --- ![](img/Map5.png)<!-- --> --- ![](img/Map6.png)<!-- --> --- ![](img/Map7.png)<!-- --> --- class: inverse, middle ## .hand[um... but...] ## .hand[that doesn't solve our problem!] --- .hand[Problem: grow_multi() doesn't transform **three** tips] ![](img/Tree4.png)<!-- --> --- .hand[Solution: don't include .x value in our recipe!] --- .hand[Before:] ![](img/Map7.png)<!-- --> --- .hand[After:] ![](img/Map8.png)<!-- --> --- class: inverse, middle ## .hand[okay, can we do use this in "ashtree"?] ## .hand[live coding #3...] --- class: middle background-image: url("img/ashtree5.png") background-size: cover --- class: inverse, middle ## .hand[iteration problems vary...] --- class: inverse ![](img/Tree1.png)<!-- --> --- class: inverse ![](img/Tree2.png)<!-- --> --- class: inverse ![](img/Tree3.png)<!-- --> --- class: inverse ![](img/Tree4.png)<!-- --> --- class: inverse ![](img/Tree5.png)<!-- --> --- class: inverse ![](img/Tree6.png)<!-- --> --- class: inverse ![](img/Tree7.png)<!-- --> --- class: inverse ![](img/Tree8.png)<!-- --> --- class: inverse ![](img/Tree9.png)<!-- --> --- ![](img/Acc1.png)<!-- --> --- ![](img/Acc2.png)<!-- --> --- ![](img/Acc3.png)<!-- --> --- ![](img/Acc4.png)<!-- --> --- ![](img/Acc5.png)<!-- --> --- ![](img/Acc6.png)<!-- --> --- ![](img/Acc7.png)<!-- --> --- ![](img/Acc8b.png)<!-- --> --- class: inverse, middle ## .hand[so let's try to use accumulate()] ## .hand[... a.k.a., live coding #4] --- class: middle background-image: url("img/ashtree4.png") background-size: cover --- class: inverse, middle ## .hand[live coding #5...] ## .hand[... let's make it pretty!] --- class: middle background-image: url("img/flametree3.png") background-size: cover .pull-right-wide[ .biggish-hotpink-text[thanks!] ] <br><br><br><br><br><br><br> ## github.com/djnavarro/ashtree ## github.com/djnavarro/flametree