From ae5060020356c721c3c41fd318b940a1a1d815dc Mon Sep 17 00:00:00 2001 From: Remington Covert Date: Tue, 5 May 2015 17:42:45 -0700 Subject: [PATCH] better scaling! --- desktop/src-common/advent/utils.clj | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index 8ece79c6..ebd1e4a6 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -75,14 +75,27 @@ range (+ (* percent-complete (- maximum-size minimum-size)) minimum-size)] range))))) +(defn get-scale-value [image x y] + (let [base-y (Math/floor (- 240 y)) + other-y (Math/ceil (- 240 y)) + base-amount (- y (Math/floor y)) + other-amount (- 1.0 base-amount) + base-v (-> image + (pixmap! :get-pixel x base-y) + color + (.r)) + other-v (-> image + (pixmap! :get-pixel x other-y) + color + (.r))] + (+ (* base-v base-amount) + (* other-v other-amount)))) + (defn scaler-fn-from-image [image minimum-size maximum-size] (let [image (pixmap image) maximum-size (or maximum-size 1.0)] (fn [[x y]] - (let [percent-complete (-> image - (pixmap! :get-pixel x (- 240 y)) - color - (.r))] + (let [percent-complete (get-scale-value image x y)] (if (< y 0) maximum-size (+ (* percent-complete (- maximum-size minimum-size)) minimum-size))))))