Skip to content

Commit

Permalink
color -> patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwilk committed Jan 25, 2017
1 parent e4cb2ca commit 51091b9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 59 deletions.
6 changes: 3 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(defproject functions-as-color "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
(defproject functions-as-patterns "0.1.0-SNAPSHOT"
:description "Exploring understanding functions through patterns"
:url "http://github.com/josephwilk/functions-as-patterns"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns functions-as-color.core
(ns functions-as-patterns.core
(require [mikera.image.core :refer :all]
[mikera.image.colours :refer :all]
[com.evocomputing.colors :as colors]))
Expand Down Expand Up @@ -30,19 +30,25 @@
(lazy-seq
(when-let [s (seq coll)]
(if (coll? (first s))
(concat (flatten (first s)) (flatten (rest s)))
(cons (first s) (flatten (rest s)))))))
(concat (flatten (first s)) (flatten-all (rest s)))
(cons (first s) (flatten-all (rest s)))))))

(defn no-of-leaf-nodes [seq]
(count (flatten-all seq)))

(defn hues
([steps] (hues 25 steps highlight-color))
([steps factor] (hues factor steps highlight-color))
([steps factor base]
(map
(fn [hue-adjust] (colors/rgba-int
(colors/adjust-hue base hue-adjust)))
(range 0 (* steps factor) steps))))
(-> (map
(fn [hue-adjust] (colors/rgba-int
(colors/adjust-hue base hue-adjust)))
(range 0 (* steps factor) steps))
vec)))

(defn color-seq
([n] (color-seq n rgb-blank-color))
([n color] (take n (cycle [color]))))

(defn paint-stroked-rectangle! [img color posx posy rect-w rect-h stroke-size]
(let [x (+ posx stroke-size)
Expand Down Expand Up @@ -139,52 +145,3 @@
(let [v (vec args)]
`(example->color
{:fn ~fn-to-view :args ~v})))

(view
(interpose rgb-highlight-color (take 8 (cycle [rgb-blank-color]))))

(view
(interleave (hues 30 2 highlight-color) (take 8 (cycle [blank-color]))))

(view
(nthrest (hues 10) 4))

(view
(shuffle (hues 10)))

(view
(replace (vec (hues 10)) [0 3 4 5]))

(view
(partition 2 (partition 3 (hues 25 10 highlight-color))))



;;Get shorter
;;;distinct filter remove take-nth for

(view (distinct (sort (concat (hues 5) (hues 5)))))
(view (filter (fn [x] (= 0 (mod x 3))) (hues 10)))
(view (remove (fn [x] (= 0 (mod x 3))) (hues 10)))
(view (take-nth 3 (hues 10)))
(view (take 10 (for [x (range 10) y (range 100) :while (< y x)] [(int->color x)
(int->color y)])))

;;Get longer
;;;cons conj concat lazy-cat mapcat cycle interleave interpose

;;Tail-items
;;;rest nthrest next fnext nnext drop drop-while take-last for

;;Head-items
;;;take take-while butlast drop-last for

;;'Change'
;;;conj concat distinct flatten group-by partition partition-all partition-by split-at split-with filter
;;;remove replace shuffle

;;Rearrange
;;;reverse sort sort-by compare

;;Process items
;;;map pmap map-indexed mapcat for replace seque
51 changes: 51 additions & 0 deletions src/functions_as_patterns/seq.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(ns functions-as-patterns.seq
(:require [functions-as-patterns.core :refer :all]))

;;Get shorter
;;;distinct filter remove take-nth for

(view (distinct (sort (concat (hues 5) (hues 5)))))

;;The pattern is more the fn than the filter/remove
(view (filter (fn [x] (= 0 (mod x 3))) (hues 10)))
(view (remove (fn [x] (= 0 (mod x 3))) (hues 10)))

(view (take-nth 3 (hues 10)))
(view (take 5 (for [x (range 5) y (range 5) :while (< y x)] [(int->color x)
(int->color y)])))

;;Get longer
;;;cons conj concat lazy-cat mapcat cycle interleave interpose

(view (cons rgb-highlight-color (color-seq 3)))
(view (conj (color-seq 3) rgb-highlight-color))
(view (concat (color-seq 3) (color-seq 3 rgb-highlight-color)))
;;fails (view (conj (hues 5) (hues 5)))
;;fails (view (lazy-cat (color-seq 3) (color-seq 3 rgb-highlight-color)))

(view (mapcat (fn [x] x) [(color-seq 3) (color-seq 3 rgb-highlight-color)]))
(view (interpose rgb-highlight-color (color-seq 8)))
(view (interleave (hues 30 2 highlight-color) (color-seq 8)))

;;Tail-items
;;;rest nthrest next fnext nnext drop drop-while take-last for

(view (rest (hues 4)))
(view (nthrest (hues 10) 4))

;;Head-items
;;;take take-while butlast drop-last for

;;Change
;;;conj concat distinct flatten group-by partition partition-all partition-by split-at split-with filter
;;;remove replace shuffle

(view (shuffle (interpose rgb-highlight-color (color-seq 5))))
(view (replace (hues 10) [0 3 4 5]))
(view (partition 2 (hues 10)))

;;Rearrange
;;;reverse sort sort-by compare

;;Process items
;;;map pmap map-indexed mapcat for replace seque

0 comments on commit 51091b9

Please sign in to comment.