Permalink
Browse files

Initial version

  • Loading branch information...
1 parent 8060297 commit 10a12b5fee8038f55df5312ac42011ba07ab26d5 David Serrano Arce committed Jan 14, 2016
Showing with 333 additions and 1 deletion.
  1. +3 −0 CHANGELOG.md
  2. +10 −1 README.md
  3. BIN chocobo-coloring-0.1.jar
  4. +27 −0 chocobo.iml
  5. +8 −0 project.clj
  6. +96 −0 src/chocobo/coloring.clj
  7. +42 −0 src/chocobo/core.clj
  8. +82 −0 src/chocobo/feeding.clj
  9. +29 −0 src/chocobo/math.clj
  10. +36 −0 src/chocobo/rgb.clj
View
@@ -0,0 +1,3 @@
+## 0.1.0 - 2016-01-13
+### Added
+- First version
View
@@ -1,2 +1,11 @@
# ChocoboColoring
-A simple Clojure algorithm to calculate how to modifiy the color of a Chocobo in FFXIV
+
+A Clojure library designed to ... well, that part is up to you.
+
+## Usage
+
+Execute the main function (or the compiled jar) with two arguments, being the first the name of the current color of your chocobo, and the second the target color. A correct input will provide the berries you need to feed the chocobo (totals and order), otherwise it will print the available colors.
+
+## License
+
+LGPL v3.0
Binary file not shown.
View
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module cursive.leiningen.project.LeiningenProjectsManager.displayName="chocobo:0.1" cursive.leiningen.project.LeiningenProjectsManager.isLeinModule="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/classes" />
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/dev-resources" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="Leiningen: cider/cider-nrepl:0.8.1" level="project" />
+ <orderEntry type="library" name="Leiningen: cljs-tooling:0.1.3" level="project" />
+ <orderEntry type="library" name="Leiningen: clojure-complete:0.2.3" level="project" />
+ <orderEntry type="library" name="Leiningen: compliment:0.2.0" level="project" />
+ <orderEntry type="library" name="Leiningen: org.clojure/clojure:1.7.0" level="project" />
+ <orderEntry type="library" name="Leiningen: org.clojure/java.classpath:0.2.0" level="project" />
+ <orderEntry type="library" name="Leiningen: org.clojure/tools.namespace:0.2.5" level="project" />
+ <orderEntry type="library" name="Leiningen: org.clojure/tools.nrepl:0.2.10" level="project" />
+ <orderEntry type="library" name="Leiningen: org.clojure/tools.trace:0.7.8" level="project" />
+ <orderEntry type="library" name="Leiningen: org.tcrawley/dynapath:0.2.3" level="project" />
+ </component>
+</module>
View
@@ -0,0 +1,8 @@
+; HarZe 2016
+(defproject chocobo "0.1"
+ :description "It provides the berries you need to modify a Chocobo color in FFXIV"
+ :url "http://github.com/HarZe/ChocoboColoring"
+ :license {:name "LGPL"
+ :url "https://www.gnu.org/licenses/lgpl-3.0.txt"}
+ :dependencies [[org.clojure/clojure "1.7.0"]]
+ :main chocobo.core)
@@ -0,0 +1,96 @@
+; HarZe 2016 - Colors used by FFXIV
+(ns chocobo.coloring)
+
+(def color-data [{:rgb [219 180 87] :name "Desert Yellow"},
+ {:rgb [228 223 208] :name "Snow White"},
+ {:rgb [172 168 162] :name "Ash Gray"},
+ {:rgb [137 135 132] :name "Goobbue Grey"},
+ {:rgb [101 101 101] :name "Slate Grey"},
+ {:rgb [72 71 66] :name "Charcoal Grey"},
+ {:rgb [43 41 35] :name "Soot Black"},
+ {:rgb [230 159 150] :name "Rose Pink"},
+ {:rgb [131 105 105] :name "Lilac Purple"},
+ {:rgb [91 23 41] :name "Rolanberry Red"},
+ {:rgb [120 26 26] :name "Dalamud Red"},
+ {:rgb [98 34 7] :name "Rust Red"},
+ {:rgb [69 21 17] :name "Wine Red"},
+ {:rgb [204 108 94] :name "Coral Pink"},
+ {:rgb [145 59 48] :name "Blood Red"},
+ {:rgb [228 170 138] :name "Salmon Pink"},
+ {:rgb [183 92 45] :name "Sunset Orange"},
+ {:rgb [125 57 6] :name "Mesa Red"},
+ {:rgb [106 75 55] :name "Bark Brown"},
+ {:rgb [110 61 36] :name "Chocolate Brown"},
+ {:rgb [79 45 31] :name "Russet Brown"},
+ {:rgb [48 33 27] :name "Kobold Brown"},
+ {:rgb [201 145 86] :name "Cork Brown"},
+ {:rgb [153 110 63] :name "Qiqirn Brown"},
+ {:rgb [123 92 45] :name "Opo-Opo Brown"},
+ {:rgb [162 135 92] :name "Aldgoat Brown"},
+ {:rgb [197 116 36] :name "Pumpkin Orange"},
+ {:rgb [142 88 27] :name "Acorn Brown"},
+ {:rgb [100 66 22] :name "Orchard Brown"},
+ {:rgb [61 41 13] :name "Chestnut Brown"},
+ {:rgb [185 164 137] :name "Gobbiebag Brown"},
+ {:rgb [146 129 108] :name "Shale Brown"},
+ {:rgb [97 82 69] :name "Mole Brown"},
+ {:rgb [63 51 41] :name "Loam Brown"},
+ {:rgb [235 211 160] :name "Bone White"},
+ {:rgb [183 163 112] :name "Ul Brown"},
+ {:rgb [250 198 43] :name "Honey Yellow"},
+ {:rgb [228 158 52] :name "Millioncorn Yellow"},
+ {:rgb [188 136 4] :name "Coeurl Yellow"},
+ {:rgb [242 215 112] :name "Cream Yellow"},
+ {:rgb [165 132 48] :name "Halatali Yellow"},
+ {:rgb [64 51 17] :name "Raisin Brown"},
+ {:rgb [88 82 48] :name "Mud Green"},
+ {:rgb [187 187 138] :name "Sylph Green"},
+ {:rgb [171 176 84] :name "Lime Green"},
+ {:rgb [112 115 38] :name "Moss Green"},
+ {:rgb [139 156 99] :name "Meadow Green"},
+ {:rgb [75 82 50] :name "Olive Green"},
+ {:rgb [50 54 33] :name "Marsh Green"},
+ {:rgb [149 174 92] :name "Apple Green"},
+ {:rgb [101 130 65] :name "Cactuar Green"},
+ {:rgb [40 75 38] :name "Hunter Green"},
+ {:rgb [64 99 57] :name "Ochu Green"},
+ {:rgb [95 117 88] :name "Adamantoise Green"},
+ {:rgb [59 77 60] :name "Nophica Green"},
+ {:rgb [30 42 33] :name "Deepwood Green"},
+ {:rgb [150 189 185] :name "Celeste Green"},
+ {:rgb [67 114 144] :name "Turquoise Green"},
+ {:rgb [31 70 70] :name "Morbol Green"},
+ {:rgb [178 196 206] :name "Ice Blue"},
+ {:rgb [131 176 210] :name "Sky Blue"},
+ {:rgb [100 129 160 ] :name "Seafog Blue"},
+ {:rgb [59 104 134] :name "Peacock Blue"},
+ {:rgb [28 61 84] :name "Rhotano Blue"},
+ {:rgb [142 155 172] :name "Corpse Blue"},
+ {:rgb [79 87 102] :name "Ceruleam Blue"},
+ {:rgb [47 56 81] :name "Woad Blue"},
+ {:rgb [26 31 39] :name "Ink Blue"},
+ {:rgb [91 127 192] :name "Raptor Blue"},
+ {:rgb [47 88 137] :name "Othard Blue"},
+ {:rgb [35 65 114] :name "Storm Blue"},
+ {:rgb [17 41 68] :name "Void Blue"},
+ {:rgb [39 48 103] :name "Royal Blue"},
+ {:rgb [24 25 55] :name "Midnight Blue"},
+ {:rgb [55 55 71] :name "Shadow Blue"},
+ {:rgb [49 45 87] :name "Abyssal Blue"},
+ {:rgb [135 127 174] :name "Lavender Purple"},
+ {:rgb [81 69 96] :name "Gloom Purple"},
+ {:rgb [50 44 59] :name "Currant Purple"},
+ {:rgb [183 158 188] :name "Iris Purple"},
+ {:rgb [59 42 61] :name "Grape Purple"},
+ {:rgb [254 206 245] :name "Lotus Pink"},
+ {:rgb [220 155 202] :name "Colibri Pink"},
+ {:rgb [121 82 108] :name "Plum Purple"},
+ {:rgb [102 48 78] :name "Regal Purple"}])
+
+(defn find-by-name
+ "Returns the color data associated to the given name"
+ [name]
+ (first
+ (filter
+ #(= name (:name %))
+ color-data)))
View
@@ -0,0 +1,42 @@
+; HarZe 2016 - Feeding/coloring chocobo utility
+(ns chocobo.core
+ (:require [chocobo.feeding :as feeding]
+ [chocobo.coloring :as coloring])
+ (:gen-class))
+
+(defn format-list
+ "Returns a string from a seq"
+ [coll]
+ (reduce
+ str
+ (map
+ #(str % "\n")
+ coll)))
+
+(defn -main
+ "Main funciton"
+ [& args]
+ (let [current (first args)
+ target (second args)
+ current-data (coloring/find-by-name current)
+ target-data (coloring/find-by-name target)]
+ (do
+ (println (str "*** ChocoboColoring 0.1 - http://github.com/HarZe/ChocoboColoring"))
+ (println " ")
+ (if
+ (and
+ (= 2 (count args))
+ (= current (:name current-data))
+ (= target (:name target-data)))
+ (do
+ (println (str "---> From " (:name current-data) " to " (:name target-data) " you'll need:"))
+ (let [chain (feeding/feed-chain (:rgb current-data) (:rgb target-data))]
+ (println (format-list (filter #(not (nil? %)) (feeding/feed-chain-totals chain))))
+ (println "---> Feed your chocobo in this order:")
+ (println (format-list (feeding/feed-chain-names chain))))
+ (println "---> That's all, thanks for using ChocoboColoring"))
+ (do
+ (println "---> Available colors:")
+ (println (format-list (map #(:name %) coloring/color-data)))
+ (println "ERROR: wrong usage, please type two names listed above")
+ (println "Usage example: java -jar chocobo-coloring-0.1.jar \"Desert Yellow\" \"Ash Gray\""))))))
@@ -0,0 +1,82 @@
+; HarZe 2016 - "Feeding chocobo problem" logic
+
+(ns chocobo.feeding
+ (:require [chocobo.math :as math]
+ [chocobo.rgb :as rgb]))
+
+(def berry-data [{:rgb [5 -5 -5] :name "Xelphatol Apple"},
+ {:rgb [-5 5 -5] :name "Mamook Pear"},
+ {:rgb [-5 -5 5] :name "O'Ghomoro Berries"},
+ {:rgb [-5 5 5] :name "Doman Plum"},
+ {:rgb [5 -5 5] :name "Valfruit"},
+ {:rgb [5 5 -5] :name "Cieldalaes Pineapple"}])
+
+(defn find-by-color
+ "Returns the berry data based on rgb color"
+ [color]
+ (first
+ (filter
+ #(rgb/equal color (:rgb %))
+ berry-data)))
+
+(defn find-name
+ "Transforms rgb color data to a berry name"
+ [color]
+ (:name (find-by-color color)))
+
+(def closeness 6)
+
+(defn close-enough
+ "Returns true if the given rgb values have almost equal components"
+ [x y]
+ (every?
+ (partial > closeness)
+ (math/abs
+ (rgb/diff x y))))
+
+(defn feed
+ "Returns a collection with each color obtained by using the berries on the given rgb color"
+ [color]
+ (map
+ (partial rgb/add color)
+ (map :rgb berry-data)))
+
+(defn best-choice
+ "Returns the next berry that should be feed to the Chocobo in order to achieve the target color from a the current one"
+ [current target]
+ (rgb/diff target
+ (rgb/add current
+ (math/smallest-entropy
+ (map
+ (partial rgb/diff target)
+ (filter
+ rgb/valid
+ (feed current)))))))
+
+(defn feed-chain
+ "Return the sorted list of berries (rgb values) needed to feed a Chocobo from the current color to the target"
+ ([current target]
+ (feed-chain current target []))
+ ([current target berries]
+ (if (close-enough current target)
+ berries
+ (let [next (best-choice current target)]
+ (recur
+ (rgb/add current next)
+ target
+ (conj berries next))))))
+
+(defn feed-chain-totals
+ "Return the total of berries required for a chain"
+ [chain]
+ (map
+ #(let [total (rgb/counter % chain)
+ name (find-name %)]
+ (if (> total 0)
+ (str name " x" total)))
+ (map #(:rgb %) berry-data)))
+
+(defn feed-chain-names
+ "Parses a list of rgb values to berry names"
+ [chain]
+ (map find-name chain))
View
@@ -0,0 +1,29 @@
+; HarZe 2016 - Auxiliar math functions
+(ns chocobo.math)
+
+(defn absolute
+ "Absolute value of a number"
+ [n]
+ (if (< n 0)
+ (- n)
+ n))
+
+(defn abs
+ "Seq of absolute values of its members"
+ [coll]
+ (map absolute coll))
+
+(defn sum
+ "Sum of values of a seq"
+ [coll]
+ (reduce + coll))
+
+(defn entropy
+ "Returns the entropy (sum of absolute values)"
+ [coll]
+ (sum (abs coll)))
+
+(defn smallest-entropy
+ "Returns the collection with smallest entropy"
+ [coll]
+ (first (sort-by entropy coll)))
View
@@ -0,0 +1,36 @@
+; HarZe 2016 - RGB vector functions
+(ns chocobo.rgb)
+
+(defn equal
+ "Returns true if components are equal"
+ [x y]
+ (every?
+ (partial = true)
+ (map = x y)))
+
+(defn add
+ "Sum of the components"
+ [x y]
+ (map + x y))
+
+(defn diff
+ "Difference of the components"
+ [x y]
+ (map - x y))
+
+(defn valid
+ "Returns true if all components are within [0,255] range"
+ [color]
+ (every?
+ (partial = true)
+ (map
+ #(and (>= % 0) (<= % 255))
+ color)))
+
+(defn counter
+ "Returns the number of ocurrences of the given rgb value in a seq"
+ [color coll]
+ (count
+ (filter
+ #(equal color %)
+ coll)))

0 comments on commit 10a12b5

Please sign in to comment.