Last active
January 7, 2016 03:43
-
-
Save logaan/6ddec0ec7e0e53618c76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hex-transition.core | |
(:require [clojure.string :refer [join]] | |
[clojure.pprint :refer [pprint]])) | |
(defn hex->int-parts [hex-string] | |
(for [[a b] (partition 2 hex-string)] | |
(Integer/parseInt (str a b) 16))) | |
(defn hex->int-parts [hex-string] | |
(for[[a b](partition 2 hex-string)](Integer/parseInt(str a b)16))) | |
(defn hex->int-parts [hex-string] | |
(map (fn[[a b]](Integer/parseInt(str a b)16))(partition 2 hex-string))) | |
(defn hex->int-parts [hex-string] | |
(map #(Integer/parseInt(apply str %)16)(partition 2 hex-string))) | |
(assert (= (hex->int-parts "FFFFFF") [255 255 255])) | |
(defn hex-range [from to steps] | |
(let [step-size (/ (- to from) steps)] | |
(map #(format "%02X" %) | |
(range from (+ to step-size) step-size)))) | |
(defn hex-range [from to steps] | |
((fn[a](map #(format"%02X"(int %))(range from(+ to a)a)))(/(- to from)steps))) | |
(defn hex-range [f t s] | |
((fn[a](map #(format"%02X"(int %))(range f(+ t a)a)))(/(- t f)s))) | |
(def hex-range | |
(fn[f t s]((fn[a](map #(format"%02X"(int %))(range f(+ t a)a)))(/(- t f)s)))) | |
(assert (= (hex-range 255 0 3) ["FF" "AA" "55" "00"])) | |
(defn transpose [m] | |
(apply mapv vector m)) | |
(defn transition [from to steps] | |
(let [from-int (hex->int-parts from) | |
to-int (hex->int-parts to)] | |
(->> (for [[from to] (map list from-int to-int)] | |
(hex-range from to (dec steps))) | |
transpose | |
(map join)))) | |
(defn transition [from to steps] | |
(let [from-int(hex->int-parts from)to-int(hex->int-parts to)](->>(for[[from to](map list from-int to-int)](hex-range from to(dec steps)))transpose(map join)))) | |
(defn transition [from to steps] | |
(->>(for[[from to](map list (hex->int-parts from)(hex->int-parts to))](hex-range from to(dec steps)))transpose(map join))) | |
(defn transition [f t s] | |
(#(map join(apply map list(for[[f t](map list(% f)(% t))]((fn[a](map(fn[a](format"%02X"(int a)))(range f(+ t a)a)))(/(- t f)(dec s))))))(fn[a](map #(Integer/parseInt(apply str %)16)(partition 2 a))))) | |
(defn transition [f t s] | |
(#(map join(apply map list(for[[f t](map list(% f)(% t))]((fn[a](map(fn[a](format"%02X"(int a)))(range f(+ t a)a)))(/(- t f)(dec s))))))(fn[a](map #(Integer/parseInt(apply str %)16)(partition 2 a))))) | |
(defn t[f t s](#(map join(apply map list(for[[f t](map list(% f)(% t))]((fn[a](map(fn[a](format"%02X"(int a)))(range f(+ t a)a)))(/(- t f)(dec s))))))(fn[a](map #(Integer/parseInt(apply str %)16)(partition 2 a))))) | |
(assert (= (t "FFFFFF" "000000" 16) | |
["FFFFFF" "EEEEEE" "DDDDDD" "CCCCCC" "BBBBBB" "AAAAAA" "999999" | |
"888888" "777777" "666666" "555555" "444444" "333333" "222222" | |
"111111" "000000"])) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(defn hex-range [from to steps] | |
(let [from (Integer/parseInt from 16) | |
to (Integer/parseInt to 16) | |
step-size (/ (- to from) (dec steps))] | |
(map #(format "%02X" (int %)) | |
(range from (+ to step-size) step-size)))) | |
(defn hex-range [f t s] | |
(let [f (Integer/parseInt f 16) | |
t (Integer/parseInt t 16) | |
d (/ (- t f) (dec s))] | |
(map #(format "%06X" %) | |
(range f (+ t d) d)))) | |
(defn hex-range [f t s] | |
(let [i #(Integer/parseInt %1 %2) | |
f (i f 16) | |
t (i t 16) | |
d (/ (- t f) (dec s))] | |
(map #(format "%06X" %) | |
(range f (+ t d) d)))) | |
(defn hex-range[f t s](let[i #(Integer/parseInt %1 %2)f(i f 16)t(i t 16)d(/(- t f)(dec s))](map #(format"%06X"(int %))(range f(+ t d)d)))) | |
(assert (= (hex-range "FFFFFF" "000000" 16) | |
["FFFFFF" "EEEEEE" "DDDDDD" "CCCCCC" "BBBBBB" "AAAAAA" "999999" | |
"888888" "777777" "666666" "555555" "444444" "333333" "222222" | |
"111111" "000000"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment