The HSB color scheme is useful when you want to provide a variety of colors.
(defn ^BufferedImage make-image
[]
(let [rval (BufferedImage. 600 600 BufferedImage/TYPE_INT_ARGB)
g (.createGraphics rval)]
(.setRenderingHint g RenderingHints/KEY_ANTIALIASING RenderingHints/VALUE_ANTIALIAS_ON)
(let [n 3600
full-circle 360
step (/ full-circle n)
angles '[0 60 120 180 240 300]]
(doseq [i (range 0 n)]
(let [current-angle (* i step)
current-radian (Math/toRadians current-angle)
radius 250
x (+ 300 (* radius (Math/cos current-radian)))
y (+ 300 (* radius (Math/sin current-radian)))]
(.setColor g (Color/getHSBColor (* i (/ n)) 1.0 1.0))
(.drawLine g (+ x 7.5) (+ y 7.5) 300 300))))
(.setColor g Color/BLACK)
(.setStroke g (new BasicStroke 2))
(.drawOval g 56.5 56.5 500 500)
rval))
This BufferedImage appears as depicted below.

This is an interesting picture. If you want to make an image with a wide variety of colours you are going to want to use a gradient or your own custom methods like this that do their own color calculations.
No comments:
Post a Comment