available-fontsclj

create-fontclj

font-available?clj

load-font

text

text-char

text-font

text-num

available-fontsclj

Arguments
[]
Docstring

A sequence of strings representing the fonts on this system available for use.

Because of limitations in Java, not all fonts can be used and some
might work with one operating system and not others. When sharing a
sketch with other people or posting it on the web, you may need to
include a `.ttf` or `.otf` version of your font in the data directory of
the sketch because other people might not have the font installed on
their computer. Only fonts that can legally be distributed should be
included with a sketch.
Works only inside sketch functions?
No
Original Processing method
PFont.list()
Original p5js method
None.
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    (q/text-size 10)
    (doseq [[col fonts] (->> (q/available-fonts)
                             (partition-all 50)
                             (map-indexed vector))
            [row font] (map-indexed vector fonts)]
      (q/text font (+ 20 (* col 100)) (+ 20 (* row 10))))

create-fontclj

Arguments
[name size smooth charset][name size smooth][name size]
Docstring

Dynamically converts a font to the format used by Processing (a PFont) from either a font name that's installed on the computer, or from a .ttf or .otf file inside the sketches 'data' folder. This function is an advanced feature for precise control.

 Use [[available-fonts]] to obtain the names for the fonts recognized by
 the computer and are compatible with this function.

 The `size` parameter states the font size you want to generate. The
 `smooth` parameter specifies if the font should be antialiased or not,
 and the `charset` parameter is an array of chars that specifies the
 characters to generate.

 This function creates a bitmapped version of a font. It loads a font
 by name, and converts it to a series of images based on the size of
 the font. When possible, the text function will use a native font
 rather than the bitmapped version created behind the scenes with
 create-font. For instance, when using the default renderer
 setting (JAVA2D), the actual native version of the font will be
 employed by the sketch, improving drawing quality and
 performance. With the `:p2d`, `:p3d`, and `:opengl` renderer settings, the
 bitmapped version will be used. While this can drastically improve
 speed and appearance, results are poor when exporting of the sketch
 does not include the `.otf` or `.ttf` file, and the requested font is
 not available on the machine running the sketch.
Works only inside sketch functions?
Yes
Original Processing method
createFont()
Original p5js method
None.
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    ; create font by name and size
    (q/text-font (q/create-font "Courier New" 30))
    (q/text "(print :hello)" 20 50)
    ; create font by name and size and using smooth
    (q/text-font (q/create-font "Georgia" 30 true))
    (q/text "(print :hello)" 20 100)
    ; create font with all parameters
    (q/text-font (q/create-font "Georgia" 30 false (char-array "what is it for?")))
    (q/text "(print :hello)" 20 150)

font-available?clj

Arguments
[font-str]
Docstring

Returns true if font (specified as a string) is available on this system, false otherwise

Works only inside sketch functions?
No
Original Processing method
None.
Original p5js method
None.
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    (q/text (str "'Courier New' available: " (q/font-available? "Courier New"))
            20
            20)
    (q/text (str "'Ubuntu' available: " (q/font-available? "Ubuntu")) 20 40)
    (q/text (str "'My Custom Font' available: "
                 (q/font-available? "My Custom Font"))
            20
            60)

load-font

Arguments
[filename]
Docstring

Loads a font into a variable of type PFont. To load correctly, fonts must be located in the data directory of the current sketch. To create a font to use with Processing use the create-font function.

Like load-image and other methods that load data, the load-font function should not be used inside draw, because it will slow down the sketch considerably, as the font will be re-loaded from the disk (or network) on each frame.

For most renderers, Processing displays fonts using the .vlw font format, which uses images for each letter, rather than defining them through vector data. When hint :enable-native-fonts is used with the JAVA2D renderer, the native version of a font will be used if it is installed on the user's machine.

Using create-font (instead of load-font) enables vector data to be used with the JAVA2D (default) renderer setting. This can be helpful when many font sizes are needed, or when using any renderer based on JAVA2D, such as the PDF library.

Works only inside sketch functions?
Yes
Original Processing method
loadFont()
Original p5js method
loadFont()
Example
clojure specific
  • ; 
    ; setup
    ; 
    (let [; create url to load font
          url (.getPath (clojure.java.io/resource "ComicSansMS-48.vlw"))]
      (q/set-state! :font (q/load-font url)))
    ; 
    ; draw
    ; 
    (q/background 255)
    (q/fill 0)
    (let [font (q/state :font)]
      (q/text-font font)
      (q/text "CoMiC SaNs HeRe" 20 100))
clojurescript specific
  • ; 
    ; setup
    ; 
    (let [; create url to load font
          url "https://www.fontsquirrel.com/fonts/download/roboto"]
      (q/set-state! :font (q/load-font url)))
    ; 
    ; draw
    ; 
    (q/background 255)
    (q/fill 0)
    (let [font (q/state :font)]
      (q/text-font font)
      (q/text "CoMiC SaNs HeRe" 20 100))
    try example

text

Arguments
[s x1 y1 x2 y2][s x y][s x y z]clj
Docstring

Draws text to the screen in the position specified by the x and y parameters (and the optional z parameter in clj). A default font will be used unless a font is set with the text-font function. Change the color of the text with the fill function. The text displays in relation to the text-align function, which gives the option to draw to the left, right, and center of the coordinates.

The x1, y1, x2 and y2 parameters define a rectangular area to display within and may only be used with string data. For text drawn inside a rectangle, the coordinates are interpreted based on the current rect-mode setting.

Works only inside sketch functions?
Yes
Original Processing method
text()
Original p5js method
text()
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    (q/camera 50 50 50 0 0 0 0 0 -1)
    ; draw x/y/z axis
    (q/line 0 0 0 0 0 20)
    (q/line 0 0 0 0 20 0)
    (q/line 0 0 0 20 0 0)
    ; draw text '2D'
    (q/text "2D" 0 15)
    (q/rotate-x (- q/HALF-PI))
    ; draw text '3D'
    (q/text "3D" 0 -5 0)
    ; draw text 'box'
    (q/rotate-y q/HALF-PI)
    (q/rect-mode :corners)
    (q/text "box" -30 0 30 -15)
  • (q/background 255)
    (q/fill 0)
    ; draw text
    (q/text "word" 10 30)
    ; draw text in a 'box'
    (q/text "a long sentence wrapping inside a box" 60 20 120 60)
clojurescript specific
  • (q/background 255)
    (q/fill 0)
    ; draw text
    (q/text "word" 10 30)
    ; draw text in a 'box'
    (q/text "a long sentence wrapping inside a box" 60 20 120 60)
    try example

text-char

Arguments
[c x y z][c x y]
Docstring

Draws a char to the screen in the specified position. See the text function for more details.

Works only inside sketch functions?
Yes
Original Processing method
text()
Original p5js method
text()
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    (q/camera 50 50 50 0 0 0 0 0 -1)
    (q/text-char \Q 0 0)
    (q/text-char \W 0 0 10)

text-font

Arguments
[font][font size]
Docstring

Sets the current font that will be drawn with the text function. Fonts must be loaded with load-font before it can be used. This font will be used in all subsequent calls to the text function. If no size parameter is input, the font will appear at its original size until it is changed with text-size.

Because fonts are usually bitmaped, you should create fonts at the sizes that will be used most commonly. Using text-font without the size parameter will result in the cleanest-looking text.

With the default (JAVA2D) and PDF renderers, it's also possible to enable the use of native fonts via the command (hint :enable-native-fonts). This will produce vector text in JAVA2D sketches and PDF output in cases where the vector data is available: when the font is still installed, or the font is created via the create-font function.

Works only inside sketch functions?
Yes
Original Processing method
textFont()
Original p5js method
textFont()
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    (let [font (q/create-font "Courier New" 20)]
      (q/text-font font 20)
      (q/text "(print :hello)" 20 30)
      (q/text-font font 30)
      (q/text "(print-bigger :hello)" 20 100))
clojurescript specific
  • (q/background 255)
    (q/fill 0)
    (let [font "Courier New"]
      (q/text-font font 20)
      (q/text "(print :hello)" 20 30)
      (q/text-font font 30)
      (q/text "(print-bigger :hello)" 20 100))
    try example

text-num

Arguments
[num x y][num x y z]
Docstring

Draws a number to the screen in the specified position. See the text function for more details.

Works only inside sketch functions?
Yes
Original Processing method
text()
Original p5js method
text()
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    (q/camera 70 70 70 0 0 0 0 0 -1)
    (q/text-num 42 0 0)
    (q/text-num 1/2 0 0 10)