├── doc ├── clojure.core$conj_arg0.png ├── clojure.core$conj_arg1.png ├── clojure.core$conj_post.png ├── clojure.core$cons_arg0.png ├── clojure.core$cons_arg1.png ├── clojure.core$cons_post.png ├── clojure.core$rest_arg0.png ├── clojure.core$rest_post.png ├── clojure.core$sort_arg0.png ├── clojure.core$sort_post.png ├── clojure.core$take_arg0.png ├── clojure.core$take_arg1.png ├── clojure.core$take_post.png ├── clojure.core$concat_arg0.png ├── clojure.core$concat_arg1.png ├── clojure.core$concat_post.png ├── clojure.core$dedupe_arg0.png ├── clojure.core$dedupe_post.png ├── clojure.core$filter_arg1.png ├── clojure.core$filter_post.png ├── clojure.core$mapcat_arg1.png ├── clojure.core$mapcat_post.png ├── clojure.core$remove_arg1.png ├── clojure.core$remove_post.png ├── clojure.core$butlast_arg0.png ├── clojure.core$butlast_post.png ├── clojure.core$conj_arg0_list.png ├── clojure.core$conj_arg0_vec.png ├── clojure.core$conj_arg1_list.png ├── clojure.core$conj_arg1_vec.png ├── clojure.core$conj_post_list.png ├── clojure.core$conj_post_vec.png ├── clojure.core$distinct_arg0.png ├── clojure.core$distinct_post.png ├── clojure.core$drop_last_arg0.png ├── clojure.core$drop_last_arg1.png ├── clojure.core$drop_last_post.png ├── clojure.core$flatten_arg0.png ├── clojure.core$flatten_post.png ├── clojure.core$interpose_arg0.png ├── clojure.core$interpose_arg1.png ├── clojure.core$interpose_post.png ├── clojure.core$nthnext_arg0.png ├── clojure.core$nthnext_arg1.png ├── clojure.core$nthnext_post.png ├── clojure.core$nthrest_arg0.png ├── clojure.core$nthrest_arg1.png ├── clojure.core$nthrest_post.png ├── clojure.core$partition_arg0.png ├── clojure.core$partition_arg1.png ├── clojure.core$partition_post.png ├── clojure.core$replace_arg0.png ├── clojure.core$replace_arg1.png ├── clojure.core$replace_post.png ├── clojure.core$reverse_arg0.png ├── clojure.core$reverse_post.png ├── clojure.core$shuffle_arg0.png ├── clojure.core$shuffle_post.png ├── clojure.core$split_at_arg0.png ├── clojure.core$split_at_arg1.png ├── clojure.core$split_at_post.png ├── clojure.core$take_nth_arg0.png ├── clojure.core$take_nth_arg1.png ├── clojure.core$take_nth_post.png ├── clojure.core$conj_arg0_multi.png ├── clojure.core$conj_arg1_multi.png ├── clojure.core$conj_arg2_multi.png ├── clojure.core$conj_post_multi.png ├── clojure.core$interleave_arg0.png ├── clojure.core$interleave_arg1.png ├── clojure.core$interleave_post.png ├── clojure.core$split_with_arg1.png ├── clojure.core$split_with_post.png ├── clojure.core$partition_all_arg0.png ├── clojure.core$partition_all_arg1.png ├── clojure.core$partition_all_post.png ├── clojure.core$partition_by_arg1.png └── clojure.core$partition_by_post.png ├── .gitignore ├── project.clj ├── src └── functions_as_patterns │ ├── core.clj │ ├── seq.clj │ ├── klipse.cljs │ └── color.clj ├── README.md └── resources └── index.html /doc/clojure.core$conj_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_post.png -------------------------------------------------------------------------------- /doc/clojure.core$cons_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$cons_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$cons_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$cons_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$cons_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$cons_post.png -------------------------------------------------------------------------------- /doc/clojure.core$rest_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$rest_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$rest_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$rest_post.png -------------------------------------------------------------------------------- /doc/clojure.core$sort_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$sort_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$sort_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$sort_post.png -------------------------------------------------------------------------------- /doc/clojure.core$take_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$take_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$take_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$take_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$take_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$take_post.png -------------------------------------------------------------------------------- /doc/clojure.core$concat_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$concat_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$concat_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$concat_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$concat_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$concat_post.png -------------------------------------------------------------------------------- /doc/clojure.core$dedupe_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$dedupe_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$dedupe_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$dedupe_post.png -------------------------------------------------------------------------------- /doc/clojure.core$filter_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$filter_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$filter_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$filter_post.png -------------------------------------------------------------------------------- /doc/clojure.core$mapcat_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$mapcat_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$mapcat_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$mapcat_post.png -------------------------------------------------------------------------------- /doc/clojure.core$remove_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$remove_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$remove_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$remove_post.png -------------------------------------------------------------------------------- /doc/clojure.core$butlast_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$butlast_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$butlast_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$butlast_post.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_arg0_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_arg0_list.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_arg0_vec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_arg0_vec.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_arg1_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_arg1_list.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_arg1_vec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_arg1_vec.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_post_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_post_list.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_post_vec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_post_vec.png -------------------------------------------------------------------------------- /doc/clojure.core$distinct_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$distinct_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$distinct_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$distinct_post.png -------------------------------------------------------------------------------- /doc/clojure.core$drop_last_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$drop_last_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$drop_last_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$drop_last_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$drop_last_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$drop_last_post.png -------------------------------------------------------------------------------- /doc/clojure.core$flatten_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$flatten_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$flatten_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$flatten_post.png -------------------------------------------------------------------------------- /doc/clojure.core$interpose_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$interpose_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$interpose_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$interpose_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$interpose_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$interpose_post.png -------------------------------------------------------------------------------- /doc/clojure.core$nthnext_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$nthnext_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$nthnext_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$nthnext_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$nthnext_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$nthnext_post.png -------------------------------------------------------------------------------- /doc/clojure.core$nthrest_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$nthrest_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$nthrest_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$nthrest_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$nthrest_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$nthrest_post.png -------------------------------------------------------------------------------- /doc/clojure.core$partition_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$partition_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$partition_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$partition_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$partition_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$partition_post.png -------------------------------------------------------------------------------- /doc/clojure.core$replace_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$replace_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$replace_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$replace_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$replace_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$replace_post.png -------------------------------------------------------------------------------- /doc/clojure.core$reverse_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$reverse_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$reverse_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$reverse_post.png -------------------------------------------------------------------------------- /doc/clojure.core$shuffle_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$shuffle_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$shuffle_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$shuffle_post.png -------------------------------------------------------------------------------- /doc/clojure.core$split_at_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$split_at_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$split_at_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$split_at_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$split_at_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$split_at_post.png -------------------------------------------------------------------------------- /doc/clojure.core$take_nth_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$take_nth_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$take_nth_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$take_nth_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$take_nth_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$take_nth_post.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_arg0_multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_arg0_multi.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_arg1_multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_arg1_multi.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_arg2_multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_arg2_multi.png -------------------------------------------------------------------------------- /doc/clojure.core$conj_post_multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$conj_post_multi.png -------------------------------------------------------------------------------- /doc/clojure.core$interleave_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$interleave_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$interleave_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$interleave_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$interleave_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$interleave_post.png -------------------------------------------------------------------------------- /doc/clojure.core$split_with_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$split_with_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$split_with_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$split_with_post.png -------------------------------------------------------------------------------- /doc/clojure.core$partition_all_arg0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$partition_all_arg0.png -------------------------------------------------------------------------------- /doc/clojure.core$partition_all_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$partition_all_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$partition_all_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$partition_all_post.png -------------------------------------------------------------------------------- /doc/clojure.core$partition_by_arg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$partition_by_arg1.png -------------------------------------------------------------------------------- /doc/clojure.core$partition_by_post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephwilk/functions-as-patterns/HEAD/doc/clojure.core$partition_by_post.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | pom.xml 5 | pom.xml.asc 6 | *.jar 7 | *.class 8 | /.lein-* 9 | /.nrepl-port 10 | .hgignore 11 | .hg/ 12 | .DS_Store 13 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject functions-as-patterns "0.1.0-SNAPSHOT" 2 | :description "Exploring understanding functions through patterns" 3 | :url "http://github.com/josephwilk/functions-as-patterns" 4 | :license {:name "Eclipse Public License" 5 | :url "http://www.eclipse.org/legal/epl-v10.html"} 6 | :dependencies [[org.clojure/clojure "1.8.0"] 7 | [net.mikera/imagez "0.12.0"] 8 | [com.evocomputing/colors "1.0.3"]]) 9 | -------------------------------------------------------------------------------- /src/functions_as_patterns/core.clj: -------------------------------------------------------------------------------- 1 | (ns functions-as-patterns.core 2 | (:require 3 | [mikera.image.colours :refer [rand-colour]] 4 | [functions-as-patterns.color :as color])) 5 | 6 | (defmacro view [[fn-to-view & args]] 7 | (let [v (vec args)] 8 | `(color/example->color {:fn ~fn-to-view :args ~v}))) 9 | 10 | (defmacro view-as-colors [[fn-to-view & args]] 11 | (let [v (vec args)] 12 | `(color/example->forced-color {:fn ~fn-to-view :args ~v}))) 13 | 14 | (defmacro render-titled 15 | [dir prefix [fn-to-view & args]] 16 | (let [v (vec args)] 17 | `(color/example->color {:fn ~fn-to-view :args ~v :dir ~dir :prefix ~prefix}))) 18 | 19 | (defmacro render 20 | [dir [fn-to-view & args]] 21 | (let [v (vec args)] 22 | `(color/example->color {:fn ~fn-to-view :args ~v :dir ~dir :prefix ""}))) 23 | 24 | (defmacro render-as-colors [dir [fn-to-view & args]] 25 | (let [v (vec args)] 26 | `(color/example->forced-color {:fn ~fn-to-view :args ~v :dir ~dir :prefix ""}))) 27 | 28 | (comment 29 | (view-as-colors (partition-all 2 [1 2 3])) 30 | 31 | (view (identity [[[(rand-colour) (rand-colour)]] [(rand-colour) (rand-colour)]])) 32 | (view (identity [[(rand-colour)] [(rand-colour) (rand-colour)]])) 33 | (view (identity [[(rand-colour) (rand-colour) (rand-colour)]])) 34 | (view (identity [[[[(rand-colour)]]]])) 35 | (view (identity [[(rand-colour) (rand-colour) (rand-colour)]])) 36 | (view (identity [(rand-colour)])) 37 | (view (identity [[(rand-colour)]])) 38 | (view (identity [[[(rand-colour)]]])) 39 | (view (identity [[[[(rand-colour)]]]])) 40 | ) 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Functions as patterns :rainbow: 2 | 3 | Exploring patterns as a means of understanding and documenting functions. 4 | 5 | Inspired by the work of Alex McLean ([@yaxu](https://github.com/yaxu)) using visual patterns to explain the live coding language Tidal: 6 | [Tidal Pattern Language for Live Coding of Music](https://www.academia.edu/467099/TIDAL_PATTERN_LANGUAGE_FOR_LIVE_CODING_OF_MUSIC) 7 | 8 | ### Install: 9 | 10 | Add to your project.clj file: 11 | 12 | ``` 13 | [functions-as-patterns "0.1.0-SNAPSHOT"] 14 | ``` 15 | 16 | ### Example: 17 | 18 | ```clojure 19 | (require 'functions-as-patterns.core :refer :all) 20 | 21 | (view-as-colors 22 | (partition 3 (range 10))) 23 | 24 | (view-as-colors 25 | (partition-all 3 (range 10)))) 26 | ``` 27 | 28 | #### `(partition 3` ) 29 | ***;;=>*** 30 |  31 | 32 | #### `(partition-all 3` ) 33 | ***;;=>*** 34 |  35 | 36 | ## Api: 37 | 38 | ```clojure 39 | ;;Render to file, assume arguments are colors 40 | (render "/tmp/" (partition 2 (hues 10))) 41 | 42 | ;;Render to file, convert arguments to colors 43 | (render-as-colors "/tmp/" (partition 2 (range 10))) 44 | 45 | ;;Render assuming arguments are colors 46 | (view (partition 2 (hues 10))) 47 | 48 | ;;Render mapping arguments to colors 49 | (view-as-colors (partition 2 (range 10))) 50 | ``` 51 | 52 | # License 53 | 54 | Copyright © 2017-present Joseph Wilk 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 57 | 58 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 59 | 60 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 61 | 62 | For full license information, see the LICENSE file. 63 | -------------------------------------------------------------------------------- /src/functions_as_patterns/seq.clj: -------------------------------------------------------------------------------- 1 | (ns functions-as-patterns.seq 2 | (:require 3 | [functions-as-patterns.color :as color] 4 | [functions-as-patterns.core :refer :all])) 5 | 6 | (def doc-dir (str (clojure.string/replace (:out (clojure.java.shell/sh "pwd")) "\n" "") "/doc" )) 7 | 8 | ;;Get shorter 9 | ;;;distinct filter remove take-nth for 10 | 11 | (render doc-dir (distinct (concat (take 2 (color/color-seq 2 color/rgb-highlight-color)) (take 2 (drop 3 (color/hues 5))) (color/color-seq 1 color/rgb-highlight-color)))) 12 | 13 | (render doc-dir (dedupe (concat (take 2 (color/color-seq 2 color/rgb-highlight-color)) (take 2 (drop 3 (color/hues 5))) (color/color-seq 1 color/rgb-highlight-color)))) 14 | 15 | ;;The pattern is more the fn than the filter/remove 16 | (render doc-dir (filter (fn [x] (= 0 (mod x 3))) (color/hues 10))) 17 | (render doc-dir (remove (fn [x] (= 0 (mod x 3))) (color/hues 10))) 18 | 19 | (render doc-dir (take-nth 3 (color/hues 7))) 20 | (render doc-dir (take 5 (for [x (range 5) y (range 5) :while (< y x)] [(color/int->color x) 21 | (color/int->color y)]))) 22 | 23 | ;;Get longer 24 | ;;;cons conj concat lazy-cat mapcat cycle interleave interpose 25 | 26 | (render doc-dir (cons color/rgb-highlight-color (color/color-seq 3 (last (color/hues 4))))) 27 | (render doc-dir (conj (color/color-seq 3 color/rgb-highlight-color) (last (color/hues 4)))) 28 | (render doc-dir (concat (color/color-seq 3) (color/color-seq 3 color/rgb-highlight-color))) 29 | 30 | (render doc-dir (cons color/rgb-highlight-color (color/color-seq 3 (last (color/hues 4))))) 31 | (render doc-dir (conj [(last (color/hues 4))] (color/color-seq 3 color/rgb-highlight-color) )) 32 | 33 | (render-titled doc-dir "vec" (conj [(last (color/hues 4))] (apply vector (color/color-seq 3 color/rgb-highlight-color)))) 34 | (render-titled doc-dir "list" (conj (list (last (color/hues 4))) (apply vector (color/color-seq 3 color/rgb-highlight-color)))) 35 | 36 | (render doc-dir (concat (color/color-seq 3) (color/color-seq 3 color/rgb-highlight-color))) 37 | 38 | 39 | ;; (view (lazy-cat (color/color-seq 3) (color/color-seq 3 color/rgb-highlight-color))) 40 | 41 | (render doc-dir (mapcat (fn [x] x) [(color/color-seq 3) (color/color-seq 3 color/rgb-highlight-color)])) 42 | (render doc-dir (interpose color/rgb-highlight-color (color/color-seq 5))) 43 | (render doc-dir (interleave (color/hues 30 2 color/highlight-color) (color/color-seq 5))) 44 | 45 | ;;Tail-items 46 | ;;;rest nthrest next fnext nnext drop drop-while take-last for 47 | 48 | (render doc-dir (rest (cons (last (color/hues 4)) (color/color-seq 3 color/rgb-highlight-color)))) 49 | (render doc-dir (nthrest (color/hues 5) 2)) 50 | (render doc-dir (nthnext (color/hues 5) 2)) 51 | 52 | 53 | ;;Head-items 54 | ;;;take take-while butlast drop-last for 55 | 56 | (render doc-dir (butlast (cons (nth (color/hues 4) 2) (color/color-seq 2 color/rgb-highlight-color)))) 57 | (view (drop-last 2 (concat (color/color-seq 2) (color/color-seq 2 color/rgb-highlight-color)))) 58 | 59 | ;;Change 60 | ;;;flatten group-by partition partition-all partition-by split-at split-with filter 61 | ;;;remove replace shuffle 62 | 63 | (render doc-dir (shuffle (color/hues 7))) 64 | (render doc-dir (replace (color/hues 5 45) [0 3 4])) 65 | (render doc-dir (partition 3 (color/hues 7))) 66 | (render doc-dir (partition-all 3 (color/hues 7))) 67 | (render doc-dir (partition-by even? (color/hues 10))) 68 | (render doc-dir (split-at 2 (color/color-seq 3 color/rgb-highlight-color))) 69 | (render doc-dir (split-with even? (color/color-seq 3 color/rgb-highlight-color))) 70 | (render doc-dir (flatten (partition 2 (color/hues 10)))) 71 | 72 | (render doc-dir (flatten (partition 1 (partition-all 2 (color/hues 8))))) 73 | 74 | ;;Rearrange 75 | ;;;reverse sort sort-by compare 76 | 77 | (render doc-dir (reverse (color/hues 4 30))) 78 | (render doc-dir (sort (shuffle (shuffle (shuffle (color/hues 7 10)))))) 79 | 80 | ;;Process items 81 | ;;;map pmap map-indexed mapcat for replace seque 82 | (conj ) 83 | -------------------------------------------------------------------------------- /src/functions_as_patterns/klipse.cljs: -------------------------------------------------------------------------------- 1 | (ns functions-as-patterns.klipse) 2 | 3 | (def rect-size 70) 4 | (def rect-start 70) 5 | (def indent (/ square-size 2)) 6 | (def stroke-size 2) 7 | 8 | (def canvas-id (atom "canvas-1")) 9 | (def all-hues ["#EE5C96" "#EE5F5C" "#EE9C5C" "#EED85C" "#C7EE5C" "#8AEE5C" 10 | "#5CEE6B" "#5CEEA8" "#5CEEE5" "#5CBAEE" "#5C7EEE" "#775CEE" "#B45CEE" 11 | "#EE5CEB" "#EE5CAE" "#EE5C71" "#EE835C" "#EEC05C" "#DFEE5C" "#A2EE5C" 12 | "#65EE5C" "#5CEE8F" "#5CEECC" "#5CD3EE" "#5C96EE" "#5F5CEE" "#9C5CEE" 13 | "#D95CEE" "#EE5CC7" "#EE5C8A" "#EE6B5C" "#EEA85C" "#EEE55C" "#BAEE5C"]) 14 | 15 | (def blank-color "#663477") 16 | (def highlight-color "#EE5C96") 17 | (def stroke-color "#111111") 18 | (def text-color "#ffffff") 19 | (def darker-highlight-color "#3A396C") 20 | 21 | (defn container-color [depth] "#663477") 22 | 23 | (defn- no-of-leaf-nodes [col] 24 | (if (sequential? col) 25 | (count (flatten col)) 26 | 0)) 27 | 28 | (defn- fill-round-rect! 29 | ([image x y w h colour] 30 | (set! (.-fillStyle image) colour) 31 | (doto image 32 | (.beginPath) 33 | (.rect x y w h) 34 | (.fill) 35 | ;;(.strokeRect x y w h) 36 | ))) 37 | 38 | (defn- find-color [color-lookup v] (get color-lookup v v)) 39 | 40 | (defn- paint-stroked-rectangle! [img color-lookup seq-value posx posy rect-w rect-h] 41 | (let [x (+ posx stroke-size) 42 | y (+ posy stroke-size) 43 | w (- rect-w stroke-size) 44 | h (- rect-h (* 2 stroke-size)) 45 | color (find-color color-lookup seq-value)] 46 | 47 | (fill-round-rect! img 48 | posx posy 49 | (+ w (* 2 stroke-size)) (+ (* 2 stroke-size) h) 50 | stroke-color) 51 | (fill-round-rect! img 52 | x y 53 | w h 54 | color) 55 | (comment 56 | ;; debug 57 | (draw-chars! img (str posx) x y w h text-color)))) 58 | 59 | (defn- leaf? [node] (not (sequential? node))) 60 | (defn- children? [node] (sequential? node)) 61 | 62 | (defn- paint-rectangle! [img color-lookup color rect-size depth x-offset] 63 | (let [y-offset (/ (- rect-start rect-size) 2)] 64 | (if (leaf? color) 65 | (paint-stroked-rectangle! img color-lookup color x-offset y-offset rect-size rect-size) 66 | (let [width (* (no-of-leaf-nodes color) rect-size)] 67 | (paint-stroked-rectangle! img color-lookup (container-color depth) x-offset y-offset width rect-size))))) 68 | 69 | (defn- paint-all! [img color-lookup rect-size x-offset depth] 70 | (fn [parent-indent [idx color]] 71 | (paint-rectangle! img color-lookup color rect-size depth parent-indent) 72 | 73 | (if (children? color) 74 | (let [new-rect-size (/ rect-size 2) 75 | indent (/ (* rect-size (no-of-leaf-nodes color)) 76 | 2 2)] 77 | (+ 78 | indent 79 | (reduce 80 | (paint-all! img color-lookup new-rect-size parent-indent (inc depth)) 81 | (+ indent parent-indent) 82 | (map vector (range) color)))) 83 | (+ parent-indent rect-size) 84 | ))) 85 | 86 | 87 | (defn color-map [args] 88 | (let [all-args (->> args flatten (remove (fn [a] (sequential? a)))) 89 | colors (reduce (fn [acc [idx v]] 90 | (assoc acc v (get acc v (nth all-hues idx)))) 91 | {} 92 | (map vector (range) all-args))] 93 | colors)) 94 | 95 | (defn view [data] 96 | (let [color-lookup (color-map data) 97 | canvas (js/document.getElementById @canvas-id) 98 | ctx (.getContext canvas "2d") 99 | canvas-width (.-width canvas) 100 | canvas-height (.-height canvas) 101 | total-cells (no-of-leaf-nodes data) 102 | new-width (+ (* total-cells rect-size) stroke-size) 103 | new-height rect-size] 104 | (.clearRect ctx 0 0 canvas-width canvas-height) 105 | (set! (.. canvas -width) new-width) 106 | (set! (.. canvas -style -width) new-width) 107 | (set! (.. canvas -height) new-height) 108 | (set! (.. canvas -style -height) new-height) 109 | (reduce (paint-all! ctx color-lookup rect-size 0 0) 110 | 0 111 | (map vector (range) data))) 112 | data) 113 | -------------------------------------------------------------------------------- /resources/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
121 | (view (interpose [1] [[8 8] 2 [4 99] 88 [9 9]]))
122 |
123 |
124 |
125 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/src/functions_as_patterns/color.clj:
--------------------------------------------------------------------------------
1 | (ns functions-as-patterns.color
2 | (require [mikera.image.core :refer :all]
3 | [mikera.image.colours :refer :all]
4 | [com.evocomputing.colors :as colors]))
5 |
6 | (def blank-color (colors/create-color "#663477"))
7 | (def highlight-color (colors/create-color "#EE5C96"))
8 | (def stroke-color (colors/create-color "#111111"))
9 | (def text-color (colors/create-color "#ffffff"))
10 |
11 | (def darker-highlight-color (colors/adjust-hue (colors/create-color "#3A396C") -35))
12 |
13 | (def rgb-blank-color (colors/rgba-int blank-color))
14 | (def rgb-highlight-color (colors/rgba-int highlight-color))
15 | (def rgb-darker-highlight-color (colors/rgba-int darker-highlight-color))
16 | (def rgb-stroke-color (colors/rgba-int stroke-color))
17 | (def rgb-text-color (colors/rgba-int text-color))
18 |
19 | (def rect-start 70)
20 | (def stroke-size 2)
21 |
22 | (defn int->color [i]
23 | (-> highlight-color
24 | (colors/adjust-hue (* i -50))
25 | colors/rgba-int))
26 |
27 | (defn hues
28 | ([steps] (hues 25 steps highlight-color))
29 | ([steps factor] (hues factor steps highlight-color))
30 | ([steps factor base]
31 | (-> (map
32 | (fn [hue-adjust] (colors/rgba-int
33 | (colors/adjust-hue base hue-adjust)))
34 | (range 0 (* steps factor) steps))
35 | vec)))
36 |
37 | (defn color-seq
38 | ([n] (color-seq n rgb-blank-color))
39 | ([n color] (take n (cycle [color]))))
40 |
41 | (defn- container-color [depth]
42 | (-> blank-color
43 | (colors/adjust-hue (* depth -40))
44 | colors/rgba-int))
45 |
46 | (defn- flatten-all [coll]
47 | (lazy-seq
48 | (when-let [s (seq coll)]
49 | (if (coll? (first s))
50 | (concat (flatten (first s)) (flatten-all (rest s)))
51 | (cons (first s) (flatten-all (rest s)))))))
52 |
53 | (defn- no-of-leaf-nodes [col]
54 | (if (sequential? col)
55 | (count (flatten-all col))
56 | 0))
57 |
58 | (defn- fill-round-rect!
59 | ([image x y w h colour]
60 | (let [g (graphics image)
61 | ^Color colour (to-java-color colour)]
62 | (.setColor g colour)
63 | (.fillRect g (int x) (int y) (int w) (int h))
64 | image)))
65 |
66 | (defn- draw-chars! [image text x y w h colour]
67 | (let [g (graphics image)
68 | ^Color colour (to-java-color colour)]
69 | (.setColor g colour)
70 | (.drawChars g (char-array text) 0 (count (char-array text)) (int (+ (/ (- w (* 5 (count (char-array text))) ) 2) x)) (int (+ (/ h 2) y)))
71 | image))
72 |
73 | (defn- find-color [color-lookup v] (get color-lookup v v))
74 |
75 | (defn- paint-stroked-rectangle! [img color-lookup seq-value posx posy rect-w rect-h]
76 | (let [x (+ posx stroke-size)
77 | y (+ posy stroke-size)
78 | w (- rect-w stroke-size)
79 | h (- rect-h (* 2 stroke-size))
80 | color (find-color color-lookup seq-value)]
81 |
82 | (fill-round-rect! img
83 | posx posy
84 | (+ w (* 2 stroke-size)) (+ (* 2 stroke-size) h)
85 | rgb-stroke-color)
86 | (fill-round-rect! img
87 | x y
88 | w h
89 | color)
90 | (comment
91 | ;; debug
92 | (draw-chars! img (str posx) x y w h rgb-text-color))))
93 |
94 | (defn- leaf? [node] (not (sequential? node)))
95 | (defn- children? [node] (sequential? node))
96 |
97 | (defn- paint-rectangle! [img color-lookup color rect-size depth x-offset]
98 | (let [y-offset (/ (- rect-start rect-size) 2)]
99 | (if (leaf? color)
100 | (paint-stroked-rectangle! img color-lookup color x-offset y-offset rect-size rect-size)
101 | (let [width (* (no-of-leaf-nodes color) rect-size)]
102 | (paint-stroked-rectangle! img color-lookup (container-color depth) x-offset y-offset width rect-size)))))
103 |
104 | (defn- paint-all! [img color-lookup rect-size x-offset depth]
105 | (fn [parent-indent [idx color]]
106 | (paint-rectangle! img color-lookup color rect-size depth parent-indent)
107 |
108 | (if (children? color)
109 | (let [new-rect-size (/ rect-size 2)
110 | indent (/ (* rect-size (no-of-leaf-nodes color))
111 | 2 2)]
112 | (+
113 | indent
114 | (reduce
115 | (paint-all! img color-lookup new-rect-size parent-indent (inc depth))
116 | (+ indent parent-indent)
117 | (map vector (range) color))))
118 | (+ parent-indent rect-size)
119 | )))
120 |
121 | (defn- render [data color-lookup dir prefix title]
122 | (let [rect-size rect-start
123 | total-cells (no-of-leaf-nodes data)
124 | bi (new-image (+ (* total-cells rect-size) stroke-size) rect-size)]
125 |
126 | (fill! bi (colors/rgba-int stroke-color))
127 | (reduce (paint-all! bi color-lookup rect-size 0 0)
128 | 0
129 | (map vector (range) data))
130 | (if (clojure.string/blank? dir)
131 | (show bi :zoom 1.0 :title title)
132 | (if (clojure.string/blank? prefix)
133 | (save bi (str dir "/" title ".png"))
134 | (save bi (str dir "/" title "_" prefix ".png"))
135 | ))))
136 |
137 | (defn- fn->str [fn-to-convert]
138 | (-> (str fn-to-convert)
139 | (clojure.string/split #"@")
140 | first
141 | (clojure.string/replace #"__4385" "") ;;Some odd clojure fn noise?
142 | (clojure.string/replace #"__4331" "")
143 | (clojure.string/replace #"__4345" "")
144 | (clojure.string/replace #"__4343" "")
145 | ))
146 |
147 | (defn- color->rgba [c]
148 | (if (= (type c)
149 | :com.evocomputing.colors/color)
150 | (colors/rgba-int c)
151 | c))
152 |
153 | (defn- render-fn
154 | ([fn-to-doc color-map out dir prefix & args]
155 | (let [name (fn->str fn-to-doc)
156 | args (->>
157 | args
158 | (map (fn [a] (if (and (sequential? a) (= 1 (no-of-leaf-nodes a))) [a] a )))
159 | (map (fn [a] (if (sequential? a) a [a])))
160 | (map (fn [args] (map color->rgba args))))
161 | out (map color->rgba out)]
162 | (dotimes [i (count args)]
163 | (try
164 | (render (nth args i) color-map dir prefix (str name "_arg" i))
165 | (catch Exception e (println "Unable to render:" (nth args i)))))
166 | (render out color-map dir prefix (str name "_post")))))
167 |
168 | (defn example->color
169 | "Assumes arguments are colors"
170 | [{fn-to-doc :fn args :args dir :dir prefix :prefix color-map :colors}]
171 | (let [args (vec args)
172 | out (apply fn-to-doc args)
173 | color-map (or color-map {})]
174 | (apply render-fn fn-to-doc color-map out dir prefix args)))
175 |
176 | (defn example->forced-color
177 | "Forces any sequences into color values."
178 | [{fn-to-doc :fn args :args dir :dir prefix :prefix}]
179 | (let [args (vec args)
180 | all-args (flatten (remove (fn [a] (not (sequential? a))) args))
181 | all-hues (hues (count all-args))
182 | colors (reduce (fn [acc [idx v]]
183 | (assoc acc v (get acc v (nth all-hues idx))))
184 | {}
185 | (map vector (range) all-args))]
186 | (example->color {:fn fn-to-doc :args args :dir dir :colors colors :prefix prefix})))
187 |
--------------------------------------------------------------------------------