Skip to content

Instantly share code, notes, and snippets.

@chrisschreiner
Created July 11, 2010 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisschreiner/471459 to your computer and use it in GitHub Desktop.
Save chrisschreiner/471459 to your computer and use it in GitHub Desktop.
(defn inside-byte [v]
(cond
(< v 0) 0
(> v 255) 255
:else v))
(defn darker- [color fraction]
(let [fr (- 1.0 fraction)
red (inside-byte (-> (.getRed color) (* fr) Math/round))
green (inside-byte (-> (.getGreen color) (* fr) Math/round))
blue (inside-byte (-> (.getBlue color) (* fr) Math/round))
alpha (.getAlpha color)]
(Color. red green blue alpha)))
@chrisschreiner
Copy link
Author

No matching ctor found for class java.awt.Color
[Thrown class java.lang.IllegalArgumentException]

@chrisschreiner
Copy link
Author

When I type-hint the return, it works

(defn inside-byte [v](cond
%28< v 0%29 0
%28> v 255%29 255
:else %28int v%29))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment