alpha

blend-color

blue

brightness

color

color-mode

current-fill

current-stroke

green

hue

lerp-color

red

saturation

alpha

Arguments
[color]
Docstring
Extracts the alpha value from a color.
Works only inside sketch functions?
Yes
Original Processing method
alpha()
Example
(q/background 255)
(let [; create semitransparent red
      semi-red (q/color 255 0 0 120)
      ; extract alpha value from it
      alph (q/alpha semi-red)
      ; create semitransparent blue using the alpha
      semi-blue (q/color 0 0 255 alph)]
  (q/fill semi-red)
  (q/rect 0 0 100 100)
  (q/fill semi-blue)
  (q/rect 70 70 100 100))
try example

blend-color

Arguments
[c1 c2 mode]
Docstring
Blends two color values together based on the blending mode given specified
with the mode keyword.

Available blend modes are:

:blend      - linear interpolation of colours: C = A*factor + B
:add        - additive blending with white clip:
                                          C = min(A*factor + B, 255)
:subtract   - subtractive blending with black clip:
                                          C = max(B - A*factor, 0)
:darkest    - only the darkest colour succeeds:
                                          C = min(A*factor, B)
:lightest   - only the lightest colour succeeds:
                                          C = max(A*factor, B)
:difference - subtract colors from underlying image.
:exclusion  - similar to :difference, but less extreme.
:multiply   - Multiply the colors, result will always be darker.
:screen     - Opposite multiply, uses inverse values of the colors.
:overlay    - A mix of :multiply and :screen. Multiplies dark values
              and screens light values.
:hard-light - :screen when greater than 50% gray, :multiply when
              lower.
:soft-light - Mix of :darkest and :lightest. Works like :overlay,
              but not as harsh.
:dodge      - Lightens light tones and increases contrast, ignores
              darks.
              Called "Color Dodge" in Illustrator and Photoshop.
:burn       - Darker areas are applied, increasing contrast, ignores
              lights. Called "Color Burn" in Illustrator and
              Photoshop.
Works only inside sketch functions?
No
Original Processing method
blendColor()
Example
(q/background 255)
(let [; very transparent red
      c1 (q/color 255 100 20 50)
      ; not very transparent blue
      c2 (q/color 40 200 255 200)
      modes [:blend :add :subtract :darkest :lightest :difference :exclusion
             :multiply :screen :overlay :hard-light :soft-light :dodge :burn]
      splitted (partition-all 3 modes)]
  ; draw 2 rectangles with colors c1 and c2
  (q/fill c1)
  (q/rect 0 0 70 70)
  (q/fill c2)
  (q/rect 100 0 70 70)
  ; draw all possible blended colors
  (dotimes [row (count splitted)]
    (dotimes [col (count (nth splitted row))]
      (let [mode (nth (nth splitted row) col)]
        (q/fill (q/blend-color c1 c2 mode)))
      (q/rect (* col 100) (* (inc row) 100) 70 70))))
try example

blue

Arguments
[color]
Docstring
Extracts the blue value from a color, scaled to match current color-mode.
Returns a float.
Works only inside sketch functions?
Yes
Original Processing method
blue()
Example
(q/background 255)
(let [col (q/color 123 50 220)]
  (q/fill col)
  (q/rect 0 0 100 100)
  (q/fill 0 0 (q/blue col))
  (q/rect 70 70 100 100))
try example

brightness

Arguments
[color]
Docstring
Extracts the brightness value from a color. Returns a float.
Works only inside sketch functions?
Yes
Original Processing method
brightness()
Example
(q/background 255)
(q/color-mode :hsb)
(let [col (q/color 100 230 100)]
  (q/fill col)
  (q/rect 0 0 100 100)
  (q/fill 255 255 (q/brightness col))
  (q/rect 70 70 100 100))
try example

color

Arguments
[gray][r g b][r g b a][gray alpha]
Docstring
Creates an integer representation of a color The parameters are
interpreted as RGB or HSB values depending on the current
color-mode. The default mode is RGB values from 0 to 255 and
therefore, the function call (color 255 204 0) will return a bright
yellow. Args are cast to floats.

r - red or hue value
g - green or saturation value
b - blue or brightness value
a - alpha value
Works only inside sketch functions?
Yes
Original Processing method
color()
Example
(q/background 255)
; black
(q/fill (q/color 0))
(q/rect 0 0 100 100)
; semitransparent gray
(q/fill (q/color 128 128))
(q/rect 70 70 100 100)
; purple
(q/fill (q/color 255 0 255))
(q/rect 140 140 100 100)
; semitransparent cyan
(q/fill (q/color 0 255 255 120))
(q/rect 210 210 100 100)
try example

color-mode

Arguments
[mode max][mode][mode max-x max-y max-z max-a][mode max-x max-y max-z]
Docstring
Changes the way Processing interprets color data. Available modes
are :rgb and :hsb.By default, the parameters for fill, stroke,
background, and color are defined by values between 0 and 255 using
the :rgb color model. The color-mode fn is used to change the
numerical range used for specifying colors and to switch color
systems. For example, calling
(color-mode :rgb 1.0) will specify that values are specified between
0 and 1. The limits for defining colors are altered by setting the
parameters range1, range2, range3, and range 4.
Works only inside sketch functions?
Yes
Original Processing method
colorMode()
Example
(q/color-mode :rgb 255)
(q/background 255)
; use HSB and draw red
(q/color-mode :hsb)
(q/fill 255 255 255)
(q/rect 0 0 100 100)
; use HSB with different max and draw dark green
(q/color-mode :hsb 5 10 20)
(q/fill 2 10 5)
(q/rect 70 70 100 100)
; use RGB with 42 max value and draw 75% transparent blue
(q/color-mode :rgb 40)
(q/fill 0 0 40 30)
(q/rect 140 140 100 100)
; use RGB with different max values and draw semitransparent cyan
(q/color-mode :rgb 5 10 20 30)
(q/fill 0 10 20 15)
(q/rect 210 210 100 100)
try example
(q/color-mode :rgb 255)
(q/background 255)
(q/color-mode :hsb)
(q/fill 255 255 255)
(q/rect 0 0 100 100)
try example

current-fill

Arguments
[]
Docstring
Return the current fill color.
Works only inside sketch functions?
Yes
Original Processing method
PGraphics.fillColor
Example
clojure specific
  • (q/background 255)
    ; set to red
    (q/fill 255 0 0)
    (q/rect 0 0 100 100)
    (let [; remember current color
          cur-fill (q/current-fill)]
      ; change to blue
      (q/fill 0 0 255)
      (q/rect 70 70 100 100)
      ; change back to the original color
      (q/fill cur-fill)
      (q/rect 140 140 100 100))

current-stroke

Arguments
[]
Docstring
Return the current stroke color.
Works only inside sketch functions?
Yes
Original Processing method
PGraphics.strokeColor
Example
clojure specific
  • (q/background 255)
    ; set to red
    (q/stroke 255 0 0)
    (q/rect 0 0 100 100)
    (let [; remember current color
          cur-stroke (q/current-stroke)]
      ; change to blue
      (q/stroke 0 0 255)
      (q/rect 70 70 100 100)
      ; change back to the original color
      (q/stroke cur-stroke)
      (q/rect 140 140 100 100))

green

Arguments
[col]
Docstring
Extracts the green value from a color, scaled to match current
color-mode. This value is always returned as a float so be careful
not to assign it to an int value.
Works only inside sketch functions?
Yes
Original Processing method
green()
Example
(q/background 255)
(let [col (q/color 123 50 220)]
  (q/fill col)
  (q/rect 0 0 100 100)
  (q/fill 0 (q/green col) 0)
  (q/rect 70 70 100 100))
try example

hue

Arguments
[col]
Docstring
Extracts the hue value from a color.
Works only inside sketch functions?
Yes
Original Processing method
hue()
Example
(q/background 255)
(q/color-mode :hsb)
(let [col (q/color 100 230 100)]
  (q/fill col)
  (q/rect 0 0 100 100)
  (q/fill (q/hue col) 255 255)
  (q/rect 70 70 100 100))
try example

lerp-color

Arguments
[c1 c2 amt]
Docstring
Calculates a color or colors between two color at a specific
increment. The amt parameter is the amount to interpolate between
the two values where 0.0 equal to the first point, 0.1 is very near
the first point, 0.5 is half-way in between, etc.
Works only inside sketch functions?
Yes
Original Processing method
lerpColor()
Example
(q/background 255)
(let [c1 (q/color 255 0 0)
      c2 (q/color 0 0 255)]
  ; draw colors that transition from c1 to c2
  (dotimes [i 6]
    (q/fill (q/lerp-color c1 c2 (/ i 5)))
    (q/rect (* i 70) (* i 70) 100 100)))
try example

red

Arguments
[c]
Docstring
Extracts the red value from a color, scaled to match current color-mode.
Works only inside sketch functions?
Yes
Original Processing method
red()
Example
(q/background 255)
(let [col (q/color 123 50 220)]
  (q/fill col)
  (q/rect 0 0 100 100)
  (q/fill (q/red col) 0 0)
  (q/rect 70 70 100 100))
try example

saturation

Arguments
[c]
Docstring
Extracts the saturation value from a color.
Works only inside sketch functions?
Yes
Original Processing method
saturation()
Example
(q/background 255)
(q/color-mode :hsb)
(let [col (q/color 100 230 100)]
  (q/fill col)
  (q/rect 0 0 100 100)
  (q/fill 255 (q/saturation col) 255)
  (q/rect 70 70 100 100))
try example