image

image-mode

load-image

mask-imageclj

no-tint

request-image

tint

image

Arguments
[img x y][img x y c d]
Docstring
Displays images to the screen. Processing currently works with GIF,
JPEG, and Targa images. The color of an image may be modified with
the tint function and if a GIF has transparency, it will maintain
its transparency. The img parameter specifies the image to display
and the x and y parameters define the location of the image from its
upper-left corner. The image is displayed at its original size
unless the width and height parameters specify a different size. The
image-mode fn changes the way the parameters work. A call to
(image-mode :corners) will change the width and height parameters to
define the x and y values of the opposite corner of the image.

Starting with release 0124, when using the default (JAVA2D)
renderer, smooth will also improve image quality of resized
images.
Works only inside sketch functions?
Yes
Original Processing method
image()
Example
(q/background 255)
; create graphics with circle
(let [gr (q/create-graphics 70 70)]
  (q/with-graphics gr
    (q/ellipse 35 35 70 70))
  ; draw graphics twice
  (q/image gr 0 0)
  (q/image gr 100 0 100 70))
try example

image-mode

Arguments
[mode]
Docstring
Modifies the location from which images draw. The default mode is :corner.
 Available modes are:

:corner  - specifies the location to be the upper left corner and
           uses the fourth and fifth parameters of image to set the
           image's width and height.

:corners - uses the second and third parameters of image to set the
           location of one corner of the image and uses the fourth
           and fifth parameters to set the opposite corner.

:center  - draw images centered at the given x and y position.
Works only inside sketch functions?
Yes
Original Processing method
imageMode()
Example
(q/background 255)
(let [gr (q/create-graphics 100 100)]
  (q/with-graphics gr
    (q/fill 0 0 255)
    (q/stroke 0 0 255)
    (q/rect 0 0 100 100))
  (q/stroke-weight 10)
  ; use :corner mode
  (q/image-mode :corner)
  (q/image gr 50 50)
  (q/point 50 50)
  ; use :center mode
  (q/image-mode :center)
  (q/image gr 250 100)
  (q/point 250 100)
  ; use :corners mode
  (q/image-mode :corners)
  (q/image gr 350 50 400 150)
  (q/point 350 50)
  (q/point 400 150))
try example

load-image

Arguments
[filename]
Docstring
Loads an image into a variable of type PImage. Four types of
images ( .gif, .jpg, .tga, .png) images may be loaded. To load
correctly, images must be located in the data directory of the
current sketch. In most cases, load all images in setup to preload
them at the start of the program. Loading images inside draw will
reduce the speed of a program.

The filename parameter can also be a URL to a file found online.

If an image is not loaded successfully, the null value is returned
and an error message will be printed to the console. The error
message does not halt the program, however the null value may cause
a NullPointerException if your code does not check whether the value
returned from load-image is nil.

Depending on the type of error, a PImage object may still be
returned, but the width and height of the image will be set to
-1. This happens if bad image data is returned or cannot be decoded
properly. Sometimes this happens with image URLs that produce a 403
error or that redirect to a password prompt, because load-image
will attempt to interpret the HTML as image data.
Works only inside sketch functions?
Yes
Original Processing method
loadImage()
Example
; 
; setup
; 
(let [; create url to load image 100x100
      url (str "https://dummyimage.com/100x100/2c3e50/ffffff.png")]
  (q/set-state! :image (q/load-image url)))
; 
; draw
; 
(let [im (q/state :image)]
  ; image is loaded once its width is non-zero
  (when-not (zero? (.-width im)) (q/image im 0 0)))
try example

mask-imageclj

Arguments
[img mask][mask]
Docstring
Masks part of an image from displaying by loading another image and
using it as an alpha channel.  This mask image should only contain
grayscale data, but only the blue color channel is used. The mask
image needs to be the same size as the image to which it is
applied.

If single argument function is used - masked image is sketch itself
or graphics if used inside with-graphics macro. If you're passing
graphics to this function - it works only with :p3d and :opengl renderers.

This method is useful for creating dynamically generated alpha
masks.
Works only inside sketch functions?
No
Original Processing method
PImage.mask()
Example
clojure specific
  • (q/background 255)
    ; define 2 graphics and mask to apply to them
    (let [gr (q/create-graphics 100 100 :p3d)
          gr2 (q/create-graphics 100 100 :p3d)
          mask (q/create-graphics 100 100 :p3d)]
      ; first graphic is blue square with red crossing
      (q/with-graphics gr
        (q/background 0 0 255)
        (q/stroke-weight 3)
        (q/stroke 255 0 0)
        (q/line 0 0 100 100)
        (q/line 0 100 100 0))
      ; second graphic is green cross
      (q/with-graphics gr2
        (q/background 255)
        (q/stroke 0 255 0)
        (q/stroke-weight 5)
        (q/line 0 50 100 50)
        (q/line 50 0 50 100))
      ; mask is grey circles
      (q/with-graphics mask
        (q/background 0)
        (q/stroke-weight 5)
        (q/no-fill)
        (q/stroke 255)
        (q/ellipse 50 50 10 10)
        (q/stroke 200)
        (q/ellipse 50 50 30 30)
        (q/stroke 150)
        (q/ellipse 50 50 50 50)
        (q/stroke 100)
        (q/ellipse 50 50 70 70)
        (q/stroke 50)
        (q/ellipse 50 50 90 90))
      ; draw first graphic, mask and graphic with mask applied
      (q/image gr 20 20)
      (q/image mask 140 20)
      (q/mask-image gr mask)
      (q/image gr 260 20)
      ; draw second graphic, mask and graphic with mask applied
      (q/image gr2 20 140)
      (q/image mask 140 140)
      (q/with-graphics gr2
        (q/mask-image mask))
      (q/image gr2 260 140))

no-tint

Arguments
[]
Docstring
Removes the current fill value for displaying images and reverts to
displaying images with their original hues.
Works only inside sketch functions?
Yes
Original Processing method
noTint()
Example
(q/background 255)
; create graphics with white circle
(let [gr (q/create-graphics 100 100)]
  (q/with-graphics gr
    (q/background 0 0)
    (q/fill 255)
    (q/ellipse 50 50 70 70))
  ; apply cyan tint
  (q/image gr 0 0)
  (q/tint 127 255 255)
  (q/image gr 100 0)
  ; remove tint
  (q/no-tint)
  (q/image gr 200 0))
try example

request-image

Arguments
[filename]
Docstring
This function load images on a separate thread so that your sketch
does not freeze while images load during setup. While the image is
loading, its width and height will be 0. If an error occurs while
loading the image, its width and height will be set to -1. You'll
know when the image has loaded properly because its width and height
will be greater than 0. Asynchronous image loading (particularly
when downloading from a server) can dramatically improve
performance.
Works only inside sketch functions?
Yes
Original Processing method
requestImage()
Example
; 
; setup
; 
(q/set-state! :image
              (q/request-image
                "https://dummyimage.com/100x100/2c3e50/ffffff.png"))
; 
; draw
; 
(if (zero? (.-width (q/state :image)))
  (q/text "Loading" 10 10)
  (q/image (q/state :image) 0 0))
try example

tint

Arguments
[gray][r g b][r g b a][gray alpha]
Docstring
Sets the fill value for displaying images. Images can be tinted to
specified colors or made transparent by setting the alpha.

To make an image transparent, but not change it's color, use white
as the tint color and specify an alpha value. For instance,
tint(255, 128) will make an image 50% transparent (unless
colorMode() has been used).

The value for the parameter gray must be less than or equal to the
current maximum value as specified by colorMode(). The default
maximum value is 255.

Also used to control the coloring of textures in 3D.
Works only inside sketch functions?
Yes
Original Processing method
tint()
Example
(q/background 127)
(let [gr (q/create-graphics 100 100)]
  ; draw 4 circles of different color on the graphics
  (q/with-graphics gr
    (q/background 0 0)
    (q/fill 255)
    (q/ellipse 25 25 40 40)
    (q/fill 255 0 0)
    (q/ellipse 75 25 40 40)
    (q/fill 0 255 0)
    (q/ellipse 25 75 40 40)
    (q/fill 0 0 255)
    (q/ellipse 75 75 40 40))
  ; apply different types of tint
  (q/no-tint)
  (q/image gr 0 0)
  (q/tint 127)
  (q/image gr 120 0)
  (q/tint 255 127)
  (q/image gr 240 0)
  (q/tint 200 127 180)
  (q/image gr 0 120)
  (q/tint 200 127 180 127)
  (q/image gr 120 120))
try example