alpha

blend-colorclj

blue

brightness

color

color-mode

current-fill

current-stroke

green

hue

lerp-color

lightnesscljs

red

saturation

alpha

Arguments
[color]
Docstring

Extracts the alpha value from a color.

Works only inside sketch functions?
Yes
Original Processing method
alpha()
Original p5js 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 1 1 100 100)
  (q/fill semi-blue)
  (q/rect 70 70 100 100))
try example

blend-colorclj

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()
Original p5js method
None.
Example
clojure specific
  • (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))))

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()
Original p5js method
blue()
Example
(q/background 255)
(let [purple (q/color 123 50 220)]
  (q/fill purple)
  (q/rect 1 1 100 100)
  ; use only blue component of purple
  (q/fill 0 0 (q/blue purple))
  (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()
Original p5js method
brightness()
Example
(q/background 255)
(q/color-mode :hsb)
(let [dark-green (q/color 100 230 100)]
  (q/fill dark-green)
  (q/rect 1 1 100 100)
  ; use the same brightness but different color
  (q/fill 255 255 (q/brightness dark-green))
  (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()
Original p5js method
color()
Example
(q/background 255)
; black
(q/fill (q/color 0))
(q/rect 1 1 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 (and :hsl in Clojurescript). 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 function 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()
Original p5js method
colorMode()
Example
clojure specific
  • (q/color-mode :rgb 255)
    (q/background 255)
    ; use HSB and draw red
    (q/color-mode :hsb)
    (q/fill 255 255 255)
    (q/rect 1 1 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)
clojurescript specific
  • (q/color-mode :rgb 255)
    (q/background 255)
    ; use HSB and draw red
    (q/color-mode :hsb)
    (q/fill 255 255 255)
    (q/rect 1 1 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 :hsl)
    ; use red color
    (q/fill 255 255 127)
    (q/rect 1 1 100 100)
    try example

current-fill

Arguments
[]
Docstring

Return the current fill color.

Works only inside sketch functions?
Yes
Original Processing method
PGraphics.fillColor
Original p5js method
None.
Example
(q/background 255)
; set to red
(q/fill 255 0 0)
(q/rect 1 1 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))
try example

current-stroke

Arguments
[]
Docstring

Return the current stroke color.

Works only inside sketch functions?
Yes
Original Processing method
PGraphics.strokeColor
Original p5js method
None.
Example
(q/background 255)
; set to red
(q/stroke 255 0 0)
(q/rect 1 1 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))
try example

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()
Original p5js method
green()
Example
(q/background 255)
(let [purple (q/color 123 50 220)]
  (q/fill purple)
  (q/rect 1 1 100 100)
  ; use only green component of purple
  (q/fill 0 (q/green purple) 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()
Original p5js method
hue()
Example
(q/background 255)
(q/color-mode :hsb)
(let [dark-green (q/color 100 230 100)]
  (q/fill dark-green)
  (q/rect 1 1 100 100)
  ; use the hue (green) but make it bright
  (q/fill (q/hue dark-green) 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()
Original p5js method
lerpColor()
Example
(q/background 255)
(let [red (q/color 255 0 0)
      blue (q/color 0 0 255)]
  ; draw colors that transition from red to blue
  (dotimes [i 6]
    (q/fill (q/lerp-color red blue (/ i 5)))
    (q/rect (inc (* i 70)) (inc (* i 70)) 100 100)))
try example

lightnesscljs

Arguments
[c]
Docstring

Extracts the HSL lightness value from a color or pixel array.

Works only inside sketch functions?
Yes
Original Processing method
None.
Original p5js method
lightness()
Example
clojurescript specific
  • (q/background 255)
    (q/color-mode :hsl)
    (let [; blue with low lightness (70 of 255)
          blue (q/color 156 255 70)
          ; extract lightness
          l (q/lightness blue)
          ; create red with same lightness
          red (q/color 0 255 l)]
      (q/fill blue)
      (q/rect 1 1 100 100)
      (q/fill red)
      (q/rect 70 70 100 100))
    try example

red

Arguments
[c]
Docstring

Extracts the red value from a color, scaled to match the current color-mode.

Works only inside sketch functions?
Yes
Original Processing method
red()
Original p5js method
red()
Example
(q/background 255)
(let [purple (q/color 123 50 220)]
  (q/fill purple)
  (q/rect 1 1 100 100)
  ; use only red component of purple
  (q/fill (q/red purple) 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()
Original p5js method
saturation()
Example
(q/background 255)
(q/color-mode :hsb)
(let [dark-green (q/color 100 230 100)]
  (q/fill dark-green)
  (q/rect 1 1 100 100)
  ; use the same saturation but different color
  (q/fill 255 (q/saturation dark-green) 255)
  (q/rect 70 70 100 100))
try example