current-frame-rate

current-graphics

cursor

cursor-imageclj

defsketch

display-density

focused

frame-count

frame-rate

height

loaded?

looping?

no-cursor

pixel-density

resize-sketch

screen-heightclj

screen-widthclj

sketch

target-frame-rate

width

current-frame-rate

Arguments
[]
Docstring

Returns the current framerate

Works only inside sketch functions?
Yes
Original Processing method
frameRate
Original p5js method
frameRate()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/current-frame-rate) = " (q/current-frame-rate)) 10 20)
(q/text (str "(q/target-frame-rate) = " (q/target-frame-rate)) 10 40)
try example

current-graphics

Arguments
[]
Docstring

Graphics currently used for drawing. By default it is sketch graphics, but if called inside with-graphics macro - graphics passed to the macro is returned. This method should be used if you need to call some methods that are not implemented by quil.

Example:

(.beginDraw (current-graphics))
Works only inside sketch functions?
Yes
Original Processing method
None.
Original p5js method
None.
Example
(q/background 255)
(q/fill 0 0 255)
(.rect (q/current-graphics) 0 0 100 100)
(let [gr (q/create-graphics 100 100)]
  (q/with-graphics gr
    (.fill (q/current-graphics) 255 255 0)
    (.ellipse (q/current-graphics) 50 50 100 100))
  (q/image gr 70 70))
try example

cursor

Arguments
[][cursor-mode]
Docstring

Sets the cursor to a predefined symbol or makes it visible if already hidden (after no-cursor was called).

Available modes: :arrow, :cross, :hand, :move, :text, :wait

See cursor-image for specifying a generic image as the cursor symbol (clj only).

Works only inside sketch functions?
Yes
Original Processing method
cursor()
Original p5js method
cursor()
Example
(q/background 255)
(q/rect-mode :corners)
(q/text-align :center :center)
; iterate through all types of cursors
(let [types [:arrow :cross :hand :move :text :wait :no-cursor :default]
      box-width (/ (q/width) 4.1)
      box-height (/ (q/height) 2.1)]
  (dotimes [ind (count types)]
    (let [type (nth types ind)
          ; calculate corners of current box
          x (* box-width (rem ind 4))
          y (* box-height (quot ind 4))
          n-x (+ x box-width)
          n-y (+ y box-height)]
      ; draw a box for current type with its name in center
      (q/stroke 127)
      (q/no-fill)
      (q/rect x y n-x n-y)
      (q/no-stroke)
      (q/fill 0)
      (q/text (str type) (/ (+ x n-x) 2) (/ (+ y n-y) 2))
      ; if mouse is inside the box - enable this type
      (when (and (<= x (q/mouse-x) n-x) (<= y (q/mouse-y) n-y))
        (condp = type
          :default (q/cursor)
          :no-cursor (q/no-cursor)
          (q/cursor type))))))
try example

cursor-imageclj

Arguments
[img hx hy][img]
Docstring

Set the cursor to a predefined image. The horizontal and vertical active spots of the cursor may be specified with hx and hy. It is recommended to make the size 16x16 or 32x32 pixels.

Works only inside sketch functions?
Yes
Original Processing method
cursor()
Original p5js method
None.
Example
clojure specific
  • ; 
    ; setup
    ; 
    (q/set-state! :image (q/load-image "test/html/cursor.jpg"))
    ; 
    ; draw
    ; 
    (if (zero? (.-width (q/state :image)))
      (q/text "Loading" 10 10)
      (do (q/cursor-image (q/state :image))
          (q/cursor-image (q/state :image) 16 16)
          (q/image (q/state :image) 0 0)))

defsketch

Arguments
[app-name & options]
Docstring

Define and start a sketch and bind it to a var with the symbol app-name. If any of the options to the various callbacks are symbols, it wraps them in a call to var to ensure they aren't inlined and that redefinitions to the original functions are reflected in the visualisation.

  • :size - A vector of width and height for the sketch or :fullscreen. Defaults to [500 300]. If you're using :fullscreen you may want to enable present mode using :features [:present]. :fullscreen size works only in Clojure. In ClojureScript all sketches support fullscreen when you press F11.
  • :renderer - Specifies the renderer type. One of :p2d, :p3d, :java2d, :opengl, :pdf, :svg, :fx2d). Defaults to :java2d in Clojure and :p2d in ClojureScript. :dxf renderer can't be used as sketch renderer. Use begin-raw method instead. In Clojurescript only :p2d and :p3d renderers are supported. More info on Clojure renderers: https://processing.org/reference/environment/#Renderers
  • :output-file - Specifies an output file path. Only used in :pdf and :svg modes. Not supported in Clojurescript. When writing to a file, call exit at the end of the draw call to end the sketch and not write repeatedly to the file.
  • :title - A string which will be displayed at the top of the sketch window. Not supported in Clojurescript.
  • :features - A vector of keywords customizing sketch behaviour. Supported features:
    • :keep-on-top - Sketch window will always be above other windows. Note: some platforms might not support always-on-top windows. Not supported in clojurescript.
    • :exit-on-close - Shutdown JVM when sketch is closed. Not supported in Clojurescript.
    • :resizable - Makes sketch resizable. Not supported in Clojurescript.
    • :no-safe-fns - Do not catch and print exceptions thrown inside functions provided to sketch (like draw, mouse-pressed?, key-pressed? and others). By default all exceptions thrown inside these functions are caught. This prevents the sketch from breaking when a bad function is provided and allows you to fix it and reload it on the fly. You can disable this behaviour by enabling the :no-safe-fns feature. Not supported in Clojurescript.
    • :present - Switch to present mode (fullscreen without borders, OS panels). You may want to use this feature together with :size :fullscreen. Not supported in ClojureScript. In ClojureScript fullscreen is enabled by pressing F11 and it's enabled on all sketches automatically.
    • :no-start - Disables autostart if sketch was created using the defsketch macro. To start sketch you have to call function created defsketch. Supported only in ClojureScript. Usage example: :features [:keep-on-top :present]
  • :bgcolor - Sets background color for unused space in present mode. Color is specified in hex format for example :bgcolor "#00FFFF" (cyan background) Not supported in ClojureScript.
  • :display - Sets what display should be used by this sketch. Displays are numbered starting from 0. Example: :display 1. Not supported in ClojureScript.
  • :setup - A function to be called once when setting the sketch up.
  • :draw - A function to be repeatedly called at most n times per second where n is the target frame-rate set for the visualisation.
  • :host - String id of canvas element or DOM element itself. Specifies host for the sketch. Must be specified in sketch, may be omitted in defsketch. If omitted in defsketch, :host is set to the name of the sketch. If element with specified id is not found on the page and page is empty, a new canvas element will be created. Used in ClojureScript.
  • :focus-gained - Called when the sketch gains focus. Not supported in ClojureScript.
  • :focus-lost - Called when the sketch loses focus. Not supported in ClojureScript.
  • :mouse-entered - Called when the mouse enters the sketch window.
  • :mouse-exited - Called when the mouse leaves the sketch window
  • :mouse-pressed - Called every time a mouse button is pressed.
  • :mouse-released - Called every time a mouse button is released.
  • :mouse-clicked - Called once after a mouse button has been pressed and then released.
  • :mouse-moved - Called every time the mouse moves and a button is not pressed.
  • :mouse-dragged - Called every time the mouse moves and a button is pressed.
  • :mouse-wheel - Called every time mouse wheel is rotated. Takes 1 argument - wheel rotation, an int. Negative values if the mouse wheel was rotated up/away from the user, and positive values if the mouse wheel was rotated down/towards the user.
  • :key-pressed - Called every time any key is pressed.
  • :key-released - Called every time any key is released.
  • :key-typed - Called once every time non-modifier keys are pressed.
  • :on-close - Called once, when sketch is closed. Not supported in ClojureScript.
  • :middleware - Vector of middleware to be applied to the sketch. Middleware will be applied in the same order as in comp function: [f g] will be applied as (f (g options)).
  • :settings - Cousin of :setup. A function to be called once when setting sketch up. Should be used only for smooth and no-smooth. Due to Processing limitations these functions cannot be used neither in :setup nor in :draw.
Works only inside sketch functions?
No
Original Processing method
None.
Original p5js method
None.
Example

There are no examples for this function. You can request examples which will help us to prioritize this funciton.

display-density

Arguments
[display][]
Docstring

This function returns the number 2 if the screen is a high-density screen (called a Retina display on OS X or high-dpi on Windows and Linux) and a 1 if not. This information is useful for a program to adapt to run at double the pixel density on a screen that supports it. Can be used in conjunction with pixel-density.

Works only inside sketch functions?
Yes
Original Processing method
displayDensity()
Original p5js method
displayDensity()
Example
(q/background 255)
(q/fill 0)
(q/text (str "display density: " (q/display-density)) 10 20)
try example

focused

Arguments
[]
Docstring

Returns true if the applet has focus, false otherwise.

Works only inside sketch functions?
Yes
Original Processing method
focused
Original p5js method
focused
Example
(q/background 255)
(q/fill 0)
(q/text (str "Focused: " (q/focused)) 10 20)
try example

frame-count

Arguments
[]
Docstring

The system variable frameCount contains the number of frames displayed since the program started. Inside setup() the value is 0 and after the first iteration of draw it is 1, etc.

Works only inside sketch functions?
Yes
Original Processing method
frameCount
Original p5js method
frameCount
Example
(q/background 255)
(q/fill 0)
(q/text (str "Frame count: " (q/frame-count)) 10 20)
try example

frame-rate

Arguments
[new-rate]
Docstring

Specifies a new target framerate (number of frames to be displayed every second). If the processor is not fast enough to maintain the specified rate, it will not be achieved. For example, the function call (frame-rate 30) will attempt to refresh 30 times a second. It is recommended to set the frame rate within setup. The default rate is 60 frames per second.

Works only inside sketch functions?
Yes
Original Processing method
frameRate()
Original p5js method
frameRate()
Example
(q/background 255)
(q/fill 0)
(q/text (str "Frame rate: " (q/target-frame-rate)) 10 20)
(let [frame (q/frame-count)]
  ; draw moving box
  (q/rect (rem frame (q/width)) 50 50 50)
  ; every 10 frames change frame rate
  ; frame rate cycles through [1, 6, 11, 16, 21]
  (when (zero? (rem frame 10))
    (q/frame-rate (inc (* 5 (rem (quot frame 10) 5))))))
try example

height

Arguments
[]
Docstring

Height of the display window. The value of height is zero until size is called.

Works only inside sketch functions?
Yes
Original Processing method
height
Original p5js method
height
Example
(q/background 255)
(q/fill 0)
(q/text (str "width: " (q/width) ", height: " (q/height)) 10 20)
try example

loaded?

Arguments
[object]
Docstring

Returns true if object is loaded.

Works only inside sketch functions?
No
Original Processing method
None.
Original p5js method
None.
Example
clojure specific
  • ; 
    ; setup
    ; 
    (let [path (clojure.java.io/resource "SimpleShader.glsl")
          shd (q/load-shader (.getPath path))]
      (q/set-state! :shader shd))
    ; 
    ; draw
    ; 
    (let [gr (q/create-graphics 250 250)
          shd (q/state :shader)]
      (when (q/loaded? shd)
        (q/with-graphics gr
          (q/background 255)
          (q/fill 255 0 0)
          (q/triangle 50 30 220 120 20 180))
        (q/image gr 0 0)
        (q/image gr 250 0)
        (q/shader shd)
        (q/image gr 0 250)
        (q/reset-shader)
        (q/image gr 250 250)))
clojurescript specific
  • ; 
    ; setup
    ; 
    (let [shd (q/load-shader "shader.frag" "shader.vert")]
      (q/set-state! :shader shd))
    ; 
    ; draw
    ; 
    (let [shd (q/state :shader)]
      (when (q/loaded? shd)
        (q/shader shd)
        (q/set-uniform shd "p" (array -0.74364388703 0.13182590421))
        (q/set-uniform shd
                       "r"
                       (* 1.5 (q/exp (* -6.5 (+ 1 (q/sin (/ (q/millis) 2000)))))))
        (q/quad -1 -1 1 -1 1 1 -1 1)))
    try example

looping?

Arguments
[]
Docstring

Returns whether the sketch is looping.

Works only inside sketch functions?
Yes
Original Processing method
None.
Original p5js method
None.
Example
(q/background 255)
(q/fill 0)
; pause sketch on every 10th frame
(when (zero? (rem (q/frame-count) 10))
  (q/no-loop)
  (q/text "paused, click to unpause" 10 20))
(q/text (str "(q/looping?) = " (q/looping?)) 10 40)
(q/text (str "frame: " (q/frame-count)) 10 60)
try example

no-cursor

Arguments
[]
Docstring

Hides the cursor from view. Will not work when running in full screen (Present) mode.

Works only inside sketch functions?
Yes
Original Processing method
noCursor()
Original p5js method
noCursor()
Example
(q/background 255)
(q/rect-mode :corners)
(q/text-align :center :center)
; iterate through all types of cursors
(let [types [:arrow :cross :hand :move :text :wait :no-cursor :default]
      box-width (/ (q/width) 4.1)
      box-height (/ (q/height) 2.1)]
  (dotimes [ind (count types)]
    (let [type (nth types ind)
          ; calculate corners of current box
          x (* box-width (rem ind 4))
          y (* box-height (quot ind 4))
          n-x (+ x box-width)
          n-y (+ y box-height)]
      ; draw a box for current type with its name in center
      (q/stroke 127)
      (q/no-fill)
      (q/rect x y n-x n-y)
      (q/no-stroke)
      (q/fill 0)
      (q/text (str type) (/ (+ x n-x) 2) (/ (+ y n-y) 2))
      ; if mouse is inside the box - enable this type
      (when (and (<= x (q/mouse-x) n-x) (<= y (q/mouse-y) n-y))
        (condp = type
          :default (q/cursor)
          :no-cursor (q/no-cursor)
          (q/cursor type))))))
try example

pixel-density

Arguments
[density]
Docstring

It makes it possible for Processing to render using all of the pixels on high resolutions screens like Apple Retina displays and Windows High-DPI displays. Possible values 1 or 2. Must be called only from :settings handler. To get density of the current screen you can use the display-density function.

Works only inside sketch functions?
Yes
Original Processing method
pixelDensity()
Original p5js method
pixelDensity()
Example
(q/background 255)
(q/fill 0)
(q/ellipse 102 102 200 200)
(q/triangle 200 200 400 300 300 400)
try example

resize-sketch

Arguments
[width height]
Docstring

Resizes sketch. Note about ClojureScript version: if the div element is resized externally (for example from js on a page then you still need to call this method in order to tell Quil that size has changed. Currently there is no good way to automatically detect that size of the <div> element changed.

Works only inside sketch functions?
No
Original Processing method
None.
Original p5js method
None.
Example
(q/frame-rate 1)
; each frame increase size of sketch
(q/resize-sketch (inc (q/width)) (inc (q/height)))
(q/background 255)
(q/fill 0)
(q/text (str "width: " (q/width) ", height: " (q/height)) 10 20)
try example

screen-heightclj

Arguments
[]
Docstring

Returns the height of the main screen in pixels.

Works only inside sketch functions?
No
Original Processing method
None.
Original p5js method
None.
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    (let [w (q/screen-width) h (q/screen-height)] (q/text (str w "x" h) 10 20))

screen-widthclj

Arguments
[]
Docstring

Returns the width of the main screen in pixels.

Works only inside sketch functions?
No
Original Processing method
None.
Original p5js method
None.
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    (let [w (q/screen-width) h (q/screen-height)] (q/text (str w "x" h) 10 20))

sketch

Arguments
[& opts]
Docstring

Create and start a new visualisation applet. Can be used to create new sketches programmatically. See documentation for defsketch for list of available options.

Works only inside sketch functions?
No
Original Processing method
None.
Original p5js method
None.
Example

There are no examples for this function. You can request examples which will help us to prioritize this funciton.

target-frame-rate

Arguments
[]
Docstring

Returns the target framerate specified with the function frame-rate

Works only inside sketch functions?
Yes
Original Processing method
None.
Original p5js method
None.
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/current-frame-rate) = " (q/current-frame-rate)) 10 20)
(q/text (str "(q/target-frame-rate) = " (q/target-frame-rate)) 10 40)
try example

width

Arguments
[]
Docstring

Width of the display window. The value of width is zero until size is called.

Works only inside sketch functions?
Yes
Original Processing method
width
Original p5js method
width
Example
(q/background 255)
(q/fill 0)
(q/text (str "width: " (q/width) ", height: " (q/height)) 10 20)
try example