Liking cljdoc? Tell your friends :D
Clojure only.

clojure2d.core

Main Clojure2d entry point for Canvas, Window and drawing generatively.

Basic concepts:

  • Image - BufferedImage java object used to store ARGB color information.
  • Canvas - Image which contains graphical context. You draw on it. Similar to processing Graphics object.
  • Window - Window which can display canvas, process events, keeps app/script concept. Similar to Processing sketch with display.
  • Events - Mouse and keyboard events

Protocols:

  • [[ImageProto]] - basic Image operations (Image, Canvas, Window and Pixels (see clojure2d.pixels) implement this protocol.
  • Various events protocols. Events and Window implement these:
    • [[MouseXYProto]] - mouse position related to Window.
    • [[MouseButtonProto]] - status of mouse buttons.
    • [[KeyEventProto]] - keyboard status
    • [[ModifiersProto]] - status of special keys (Ctrl, Meta, Alt, etc.)
  • Additionally Window implements [[PressedProto]] in case you want to check in draw loop if your mouse or key is pressed.

Image

Image is BufferedImage java object. Image can be read from file using load-image function or saved to file with save. ImageProto provides get-image function to access to Image object directly (if you need) There is no function which creates Image directly (use Canvas instead).

SVG

To load SVG use load-svg which creates internal Batik object. Object can be rendered to Image with transcode-svg.

Canvas

Canvas is an object which is used to draw on it. To create new one call canvas function. Provide width and height and optionally quality hint.

Quality hints are as follows:

  • :low - no antialiasing, speed optimized rendering
  • :mid - antialiasing, speed optimized rendering
  • :high - antialiasing, quality optimized rendering (default)
  • :highest - as :high plus PURE_STROKE hint, which can give strange results in some cases.
  • :retina - retina display with :high quality

Hints can be provided as a set in case if you want to combine :retina with different quality than :high

To draw on Canvas you have to create graphical context. Wrap your code into one of two functions:

  • with-canvas - binding macro (with-canvas [local-canvas canvas-object] ...)
  • with-canvas-> - threading macro (with-canvas-> canvas ...).

Each function in this macro has to accept Canvas as first parameter and return Canvas.

Canvas bound to Window and accessed via callback drawing function (a'ka Processing draw()) has graphical context created automatically.

Retina / High density displays

When quality hint for canvas is set to :retina (to allow proper window / canvas scaling) internal ImageBuffer is doubled in size and drawing is done with scale set to 2.0 by default. When image is retrieved (via get-image, save or during window display), resulting image is an internal ImageBuffer scaled down.

Events

Java2d keyboard and mouse event handlers can be defined as custom multimethods separately for each window. There are following options:

  • Handlers for particular key with dispatch as a vector of window name and key character (eg. ["name" \c])
  • Handler for given key event with dispatch as a vector of window name and key event (eg. ["name" :key-pressed])
  • Handler for mouse event with dispatch as a vector of window name and mouse event (eg. ["name" :mouse-dragged])

Every event handler accepts as parameters:

  • Event object (java KeyEvent or MouseEvent) - access to the fields through defined protocols
  • Global state - state attached to window

Event handler should return new global state.

Window

Window object is responsible for displaying canvas content and processing events. You can also initialize states here.

To create window and display it call show-window. Function accepts several parameters which are described below.

Window itself simulates workflow which is available in Processing/Quil frameworks.

Internals

When window is created following things are done:

  1. Check parameters and create missing values for missed ones.
  2. If :setup function is provided, call it and use returned value as :draw-state
  3. Create JFrame, java.awt.Canvas, pack them, attach event handlers and display
  4. Set global state
  5. Run separated thread which refreshes display with given :fps, if :draw-fn is available it's called before refreshment.

Additional informations:

  • Display refreshment is done by displaying canvas on JFrame. You can set separate quality hints (same as for canvas) for this process with :hint parameter.
  • When you privide drawing function, it's called every refreshment. By default graphical context is created every call - which costs time but is safe in case you want to directly access pixels. The second variant which can be used is to create graphical context once at the moment of window creation. This variant can be forced by setting :refresher parameter to :fast
  • In case you don't want to refresh window content automatically, set :refresher to :onrepaint. This will lower CPU consumption.
  • You can replace canvas attached to window with replace-canvas function.
  • Window itself acts as event object (implements all event protocols)
  • Canvas and window can have different sizes. Display refreshing functions will scale up/down in such case.
  • Events and refreshment are not synchronized. Synchonization can be done explicitely by wrapping functions with locking macro.
  • You can create as many windows as you want.
  • You can check if window is visible or not with window-active? function.
  • If you provide both :draw-state and :setup. Value returned by :setup has a precedence unless is nil or false.

Parameters

Following parameters are used:

  • :canvas - canvas which is displayed on window. Default is 200x200px
  • :window-name - name of the window as a string. Used for event multimathods dispatch.
  • :w - width of the window. Default width of the canvas
  • :h - height of the window. Default height of the canvas
  • :fps - frames per second, defaults to 60
  • :draw-fn - drawing function, called before every display refreshment. Function should accept following four parameters:
    • canvas within graphical context (you don't need to use with-canvas or with-canvas-> wrappers.
    • window object
    • current frame number as a long value
    • current state
  • :setup - setup function which should accept two parameters and return initial draw state.
    • canvas withing graphical context
    • window object
  • :state - initial global state
  • :draw-state - initial local (drawing) state. If setup is provided, value returned by it will be used instead.
  • :hint - display quality hint. Use it when window and canvas have different sizes
  • :refresher - when create graphical context for draw: :fast for once or :safe for each call (default).

States

There are two states managed by library: global state connected to window and draw state connected to callback drawing function.

Global state

Each window has its own state kept in atom. The main idea is to have data which flow between event calls. Every event function accepts state and should return state data. Initial state can be set with show-window :state parameter To access current state from outside the flow call get-state. You can also mutate the state with set-state!.

Local state for drawing function

When drawing callback is used you can keep state between calls. What is returned by callback is passed as a parameter in next call. Drawing function is not synchronized with events that's why local state is introduced. You can still access and change global state.

You can init state from show-window with :draw-state or :setup parameters.

How to draw

There are plenty of functions which you can use to draw on canvas. They can be grouped to:

All operate on canvas and return canvas as a result. Obviously canvas is mutated.

Session

Session is a datetime with its hash kept globally in vector. To access current session names call session-name.

Following functions rely on session:

  • next-filename - generate unique filename based on session
  • log - save any information to the file under name based on session. See log-name.

Session is created automatically when needed. Session management functions are:

Utilities

Additional utility functions

  • date and time functions
  • to-hex formatter
Main Clojure2d entry point for Canvas, Window and drawing generatively.

Basic concepts:

* Image - `BufferedImage` java object used to store ARGB color information.
* Canvas - Image which contains graphical context. You draw on it. Similar to processing Graphics object.
* Window - Window which can display canvas, process events, keeps app/script concept. Similar to Processing sketch with display.
* Events - Mouse and keyboard events

Protocols:

* [[ImageProto]] - basic Image operations (Image, Canvas, Window and Pixels (see [[clojure2d.pixels]]) implement this protocol.
* Various events protocols. Events and Window implement these:
    * [[MouseXYProto]] - mouse position related to Window.
    * [[MouseButtonProto]] - status of mouse buttons.
    * [[KeyEventProto]] - keyboard status
    * [[ModifiersProto]] - status of special keys (Ctrl, Meta, Alt, etc.)
* Additionally Window implements [[PressedProto]] in case you want to check in draw loop if your mouse or key is pressed.

## Image

Image is `BufferedImage` java object. Image can be read from file using [[load-image]] function or saved to file with [[save]]. ImageProto provides [[get-image]] function to access to Image object directly (if you need)
There is no function which creates Image directly (use Canvas instead).

### SVG

To load SVG use `load-svg` which creates internal Batik object. Object can be rendered to Image with `transcode-svg`.

## Canvas

Canvas is an object which is used to draw on it. To create new one call [[canvas]] function. Provide width and height and optionally quality hint.

Quality hints are as follows:

* `:low` - no antialiasing, speed optimized rendering
* `:mid` - antialiasing, speed optimized rendering
* `:high` - antialiasing, quality optimized rendering (default)
* `:highest` - as `:high` plus `PURE_STROKE` hint, which can give strange results in some cases.
* `:retina` - retina display with `:high` quality

Hints can be provided as a set in case if you want to combine `:retina` with different quality than `:high`

To draw on Canvas you have to create graphical context. Wrap your code into one of two functions:

* [[with-canvas]] - binding macro `(with-canvas [local-canvas canvas-object] ...)`
* [[with-canvas->]] - threading macro `(with-canvas-> canvas ...)`.

Each function in this macro has to accept Canvas as first parameter and return Canvas.

Canvas bound to Window and accessed via callback drawing function (a'ka Processing `draw()`) has graphical context created automatically.

### Retina / High density displays

When quality hint for canvas is set to `:retina` (to allow proper window / canvas scaling) internal ImageBuffer is doubled in size and drawing is done with `scale` set to 2.0 by default.
When image is retrieved (via `get-image`, `save` or during window display), resulting image is an internal ImageBuffer scaled down.

## Events

Java2d keyboard and mouse event handlers can be defined as custom multimethods separately for each window.
There are following options:

* Handlers for particular key with dispatch as a vector of window name and key character (eg. `["name" \c]`)
    * [[key-pressed]] - when key is pressed
    * [[key-released]] - when key is released
    * [[key-typed]] - when key is typed
* Handler for given key event with dispatch as a vector of window name and key event (eg. `["name" :key-pressed]`)
* Handler for mouse event with dispatch as a vector of window name and mouse event (eg. `["name" :mouse-dragged]`)

Every event handler accepts as parameters:

* Event object (java KeyEvent or MouseEvent) - access to the fields through defined protocols
* Global state - state attached to window

Event handler should return new global state.

## Window

Window object is responsible for displaying canvas content and processing events. You can also initialize states here.

To create window and display it call [[show-window]]. Function accepts several parameters which are described below.

Window itself simulates workflow which is available in Processing/Quil frameworks.

### Internals

When window is created following things are done:

1. Check parameters and create missing values for missed ones.
2. If `:setup` function is provided, call it and use returned value as `:draw-state`
3. Create JFrame, java.awt.Canvas, pack them, attach event handlers and display
4. Set global state
5. Run separated thread which refreshes display with given `:fps`, if `:draw-fn` is available it's called before refreshment.

Additional informations:

* Display refreshment is done by displaying canvas on JFrame. You can set separate quality hints (same as for canvas) for this process with `:hint` parameter.
* When you privide drawing function, it's called every refreshment. By default graphical context is created every call - which costs time but is safe in case you want to directly access pixels. The second variant which can be used is to create graphical context once at the moment of window creation. This variant can be forced by setting `:refresher` parameter to `:fast`
* In case you don't want to refresh window content automatically, set `:refresher` to `:onrepaint`. This will lower CPU consumption.
* You can replace canvas attached to window with [[replace-canvas]] function.
* Window itself acts as event object (implements all event protocols)
* Canvas and window can have different sizes. Display refreshing functions will scale up/down in such case.
* Events and refreshment are not synchronized. Synchonization can be done explicitely by wrapping functions with `locking` macro.
* You can create as many windows as you want.
* You can check if window is visible or not with [[window-active?]] function.
* If you provide both `:draw-state` and `:setup`. Value returned by `:setup` has a precedence unless is `nil` or `false`.
 
### Parameters

Following parameters are used:

* `:canvas` - canvas which is displayed on window. Default is 200x200px
* `:window-name` - name of the window as a string. Used for event multimathods dispatch.
* `:w` - width of the window. Default width of the canvas
* `:h` - height of the window. Default height of the canvas
* `:fps` - frames per second, defaults to 60
* `:draw-fn` - drawing function, called before every display refreshment. Function should accept following four parameters:
    * canvas within graphical context (you don't need to use [[with-canvas]] or [[with-canvas->]] wrappers.
    * window object
    * current frame number as a long value
    * current state
* `:setup` - setup function which should accept two parameters and return initial draw state.
    * canvas withing graphical context
    * window object
* `:state` - initial global state
* `:draw-state` - initial local (drawing) state. If `setup` is provided, value returned by it will be used instead.
* `:hint` - display quality hint. Use it when window and canvas have different sizes
* `:refresher` - when create graphical context for draw: `:fast` for once or `:safe` for each call (default).

## States

There are two states managed by library: global state connected to window and draw state connected to callback drawing function.

### Global state

Each window has its own state kept in `atom`. The main idea is to have data which flow between event calls. Every event function accepts state and should return state data.
Initial state can be set with [[show-window]] `:state` parameter 
To access current state from outside the flow call [[get-state]]. You can also mutate the state with [[set-state!]].

### Local state for drawing function

When drawing callback is used you can keep state between calls. What is returned by callback is passed as a parameter in next call. Drawing function is not synchronized with events that's why local state is introduced. You can still access and change global state.

You can init state from [[show-window]] with `:draw-state` or `:setup` parameters.

## How to draw

There are plenty of functions which you can use to draw on canvas. They can be grouped to:

* Primitives like [[point]], [[rect]], etc.
* Tranformations like [[translate]], [[rotate]], etc.
* Text rendering like [[text]], [[set-font-attributes]], etc.
* Image manipulations like [[convolve]]
* Color and style like [[set-color]], [[gradient-mode]], [[set-background]], [[set-stroke]],  etc.

All operate on canvas and return canvas as a result. Obviously canvas is mutated.

## Session

Session is a datetime with its hash kept globally in vector. To access current session names call [[session-name]].

Following functions rely on session:

* [[next-filename]] - generate unique filename based on session
* [[log]] - save any information to the file under name based on session. See [[log-name]].

Session is created automatically when needed. Session management functions are:

* [[make-session]] - create new session
* [[ensure-session]] - create new session when there is no one
* [[close-session]] - close current session
* [[session-name]] - returns current session.

## Utilities

Additional utility functions

* date and time functions
* [[to-hex]] formatter
raw docstring

*jpeg-image-quality*clj

Default quality of saved jpg (values: 0.0 (lowest) - 1.0 (highest)

Default quality of saved jpg (values: 0.0 (lowest) - 1.0 (highest)
sourceraw docstring

*log-to-file*clj

Should log save to file under log-name. Print to terminal if false (default).

Should [[log]] save to file under [[log-name]]. Print to terminal if `false` (default).
sourceraw docstring

alt-down?clj

(alt-down? e)

ALT key state as boolean.

ALT key state as boolean.
sourceraw docstring

alt-gr-down?clj

(alt-gr-down? e)

ALT-GR key state as boolean.

ALT-GR key state as boolean.
sourceraw docstring

arcclj

(arc canvas [x y] w h start extent)
(arc canvas x y w h start extent)
(arc canvas x y w h start extent type)
(arc canvas x y w h start extent type stroke?)

Draw arc with middle at (x,y) position with width w and height h.

Starting angle start and extent are in radians. Direction is clockwise.

Type is one of the:

  • :open - default
  • :pie
  • :chord
Draw arc with middle at `(x,y)` position with width `w` and height `h`.

Starting angle `start` and `extent` are in radians. Direction is clockwise.

Type is one of the:

* `:open` - default
* `:pie`
* `:chord`
sourceraw docstring

arc-shapeclj

(arc-shape [x y] w h start extent)
(arc-shape x y w h start extent)
(arc-shape x y w h start extent type)
(arc-shape a x y w h start extent type)
source

available-coresclj

How much processor cores are in system. Constant is machine dependant.

How much processor cores are in system. Constant is machine dependant.
sourceraw docstring

available-tasksclj

How much intensive tasks can we run. Which is 150% of available cores. Constant is machine dependant.

How much intensive tasks can we run. Which is 150% of available cores. Constant is machine dependant.
sourceraw docstring

awt-xor-modeclj

(awt-xor-mode canvas c)

Set XOR graphics mode with java.awt.Color.

To revert call paint-mode.

Set XOR graphics mode with `java.awt.Color`.

To revert call [[paint-mode]].
sourceraw docstring

bezierclj

(bezier canvas [x1 y1] [x2 y2] [x3 y3] [x4 y4])
(bezier canvas x1 y1 x2 y2 x3 y3 x4 y4)
(bezier canvas x1 y1 x2 y2 x3 y3 x4 y4 stroke?)

Draw bezier curve with 4 sets of coordinates.

Draw bezier curve with 4 sets of coordinates.
sourceraw docstring

bezier-shapeclj

(bezier-shape [x1 y1] [x2 y2] [x3 y3] [x4 y4])
(bezier-shape x1 y1 x2 y2 x3 y3 x4 y4)
source

black-canvasclj

(black-canvas & r)

Create canvas with black, opaque background.

Create [[canvas]] with black, opaque background.
sourceraw docstring

bounding-boxclj

(bounding-box shape)

Returns [x,y,width,height] of shape's bounding box.

Returns `[x,y,width,height]` of shape's bounding box.
sourceraw docstring

canvasclj

(canvas width height)
(canvas width height hints)
(canvas width height hints font)

Create and return Canvas with width, height and optionally quality hints and font (name or Font object).

Default hint is :high. Possible options are: :low, :mid, :high, :highest and :retina. When :retina is selected, rendering hint is set to :high. To select other rendering hint you can provide a set, eg. #{:low :retina}.

When :retina is set, created canvas is doubled and transform matrix is set for scaling 2.0

Default font is system one.

Canvas is an object which keeps everything needed to draw Java2d primitives on it. As a drawing buffer BufferedImage is used. To draw on Canvas directly wrap your functions with with-canvas or with-canvas-> macros to create graphical context.

Canvas is transparent by default. See also black-canvas.

Be aware that drawing on Canvas is single threaded.

Font you set while creating canvas will be default font. You can set another font in the code with set-font and set-font-attributes functions. However these set font temporary.

Create and return Canvas with `width`, `height` and optionally quality hints and font (name or Font object).

Default hint is `:high`.
Possible options are: `:low`, `:mid`, `:high`, `:highest` and `:retina`. When `:retina` is selected, rendering hint is set to `:high`. To select other rendering hint you can provide a set, eg. `#{:low :retina}`.

When `:retina` is set, created canvas is doubled and transform matrix is set for scaling 2.0

Default font is system one.

Canvas is an object which keeps everything needed to draw Java2d primitives on it. As a drawing buffer `BufferedImage` is used. To draw on Canvas directly wrap your functions with [[with-canvas]] or [[with-canvas->]] macros to create graphical context.

Canvas is transparent by default. See also [[black-canvas]].

Be aware that drawing on Canvas is single threaded.

Font you set while creating canvas will be default font. You can set another font in the code with [[set-font]] and [[set-font-attributes]] functions. However these set font temporary.
sourceraw docstring

char-widthclj

(char-width canvas chr)

Returns font width from metrics. Should be called within graphical context.

Returns font width from metrics. Should be called within graphical context.
sourceraw docstring

clipclj

(clip canvas shape)
(clip canvas x y w h)

Clip drawing to specified rectangle or shape.

See also reset-clip.

Clip drawing to specified rectangle or shape.

See also [[reset-clip]].
sourceraw docstring

close-sessionclj

(close-session)

Close session via agent

Close session via agent
sourceraw docstring

close-windowclj

(close-window window)

Close window programmatically

Close window programmatically
sourceraw docstring

contains-point?clj

(contains-point? shape point)
(contains-point? shape x y)

Returns true if given point is inside a shape.

Returns `true` if given point is inside a shape.
sourceraw docstring

contains-rectangle?clj

(contains-rectangle? shape [x y w h])
(contains-rectangle? shape x y w h)

Returns true if given rectangle is inside a shape.

Returns `true` if given rectangle is inside a shape.
sourceraw docstring

control-down?clj

(control-down? e)

CONTROL key state as boolean.

CONTROL key state as boolean.
sourceraw docstring

convolution-matricesclj

Java ConvolveOp kernels. See convolve.

Java ConvolveOp kernels. See [[convolve]].
sourceraw docstring

convolveclj

(convolve i kernel)

Convolve with Java ConvolveOp.

Kernel can be predefined as keywords or sequence of numbers (row-wise).

See convolution-matrices for kernel names.

Convolve with Java ConvolveOp.

Kernel can be predefined as keywords or sequence of numbers (row-wise).

See [[convolution-matrices]] for kernel names.
sourceraw docstring

crectclj

(crect canvas [x y] w h)
(crect canvas x y w h)
(crect canvas x y w h stroke?)

Centered version of rect.

Centered version of [[rect]].
sourceraw docstring

crect-shapeclj

(crect-shape [x y] w h)
(crect-shape x y w h)
(crect-shape r x y w h)
source

curveclj

(curve canvas [x1 y1] [x2 y2] [x3 y3])
(curve canvas x1 y1 x2 y2 x3 y3)
(curve canvas x1 y1 x2 y2 x3 y3 stroke?)

Draw quadratic curve with 3 sets of coordinates.

Draw quadratic curve with 3 sets of coordinates.
sourceraw docstring

curve-shapeclj

(curve-shape [x1 y1] [x2 y2] [x3 y3])
(curve-shape x1 y1 x2 y2 x3 y3)
source

datetimeclj

(datetime)
(datetime type-of-array)

Date time values in the array. Optional parameter :vector or :hashmap (default) to indicate what to return.

Date time values in the array. Optional parameter :vector or :hashmap (default) to indicate what to return.
sourceraw docstring

dayclj

(day)

Current day

Current day
sourceraw docstring

double-array-2dclj

(double-array-2d sizex sizey)

Create 2d int array getter and setter methods. Array is mutable!

Create 2d int array getter and setter methods. Array is mutable!
sourceraw docstring

ellipseclj

(ellipse canvas [x y] w h)
(ellipse canvas x y w h)
(ellipse canvas x y w h stroke?)

Draw ellipse with middle at (x,y) position with width w and height h.

Draw ellipse with middle at `(x,y)` position with width `w` and height `h`.
sourceraw docstring

ellipse-shapeclj

(ellipse-shape [x y] w h)
(ellipse-shape x y w h)
(ellipse-shape e x y w h)
source

ensure-sessionclj

(ensure-session)

Ensure that session is active (create one if not)

Ensure that session is active (create one if not)
sourceraw docstring

file-extensionclj

(file-extension filename)

Extract extension from filename.

  • Input: image filename
  • Returns extension (without dot)
Extract extension from filename.

* Input: image filename
* Returns extension (without dot)
sourceraw docstring

filled-with-strokecljmacro

(filled-with-stroke canvas color-filled color-stroke primitive-fn & attrs)

Draw primitive filled and with stroke.

Provide two colors, one for fill (color-filled), second for stroke (color-stroke). primitive-fn is a primitive function and attrs are function parameters. Do not provide.

One note: current color is replaced with color-stroke.

Draw primitive filled and with stroke.

Provide two colors, one for fill (`color-filled`), second for stroke (`color-stroke`). `primitive-fn` is a primitive function and `attrs` are function parameters. Do not provide.

One note: current color is replaced with `color-stroke`.
sourceraw docstring

flat-hexclj

(flat-hex canvas [x y] size)
(flat-hex canvas x y size)
(flat-hex canvas x y size stroke?)

Draw flat topped hex.

Draw flat topped hex.
sourceraw docstring

flat-hex-shapeclj

(flat-hex-shape [x y] size)
(flat-hex-shape x y size)
source

flip-xclj

(flip-x canvas)

Flip canvas over x axis

Flip canvas over x axis
sourceraw docstring

flip-yclj

(flip-y canvas)

Flip canvas over y axis

Flip canvas over y axis
sourceraw docstring

flush-graphicsclj

(flush-graphics canvas)

Dispose current Graphics2D

Do not use directly. Call with-canvas-> or with-canvas macros.

Dispose current `Graphics2D`

Do not use directly. Call [[with-canvas->]] or [[with-canvas]] macros.
sourceraw docstring

font-ascentclj

(font-ascent canvas)

Returns font width from metrics. Should be called within context.

Returns font width from metrics. Should be called within context.
sourceraw docstring

font-heightclj

(font-height canvas)

Returns font width from metrics. Should be called within context.

Returns font width from metrics. Should be called within context.
sourceraw docstring

fonts-listclj

List of all available font names.

List of all available font names.
sourceraw docstring

get-canvasclj

(get-canvas window)

Returns canvas bound to window.

Returns canvas bound to `window`.
sourceraw docstring

get-imageclj

(get-image i)

Return BufferedImage

Return BufferedImage
sourceraw docstring

get-stateclj

(get-state window)

Get state from window

Get state from window
sourceraw docstring

gradient-modeclj

(gradient-mode canvas x1 y1 color1 x2 y2 color2)

Set paint mode to gradient.

To revert call paint-mode

Set paint mode to gradient.

To revert call [[paint-mode]]
sourceraw docstring

grid-cellclj

(grid-cell canvas grid x y)
(grid-cell canvas grid x y stroke?)
(grid-cell canvas grid x y scale stroke?)

Draw grid cell for given grid in screen (x,y) coordinates. For cell coordinates, see grid-qr-cell.

Draw grid cell for given grid in screen (x,y) coordinates. For cell coordinates, see [[grid-qr-cell]].
sourceraw docstring

grid-cell-shapeclj

(grid-cell-shape grid x y)
(grid-cell-shape grid x y scale)
source

grid-qr-cellclj

(grid-qr-cell canvas grid q r)
(grid-qr-cell canvas grid q r stroke?)
(grid-qr-cell canvas grid q r scale stroke?)

Draw grid cell for given grid in cell (q,r) coordinates. For screen coordinates, see grid-cell.

Draw grid cell for given grid in cell (q,r) coordinates. For screen coordinates, see [[grid-cell]].
sourceraw docstring

heightclj

(height i)

height of the image.

height of the image.
sourceraw docstring

hourclj

(hour)

Current hour

Current hour
sourceraw docstring

imageclj

(image canvas img)
(image canvas img x y)
(image canvas img x y w h)

Draw an image.

You can specify position and size of the image. Default it's placed on whole canvas.

Draw an image.

You can specify position and size of the image. Default it's placed on whole canvas.
sourceraw docstring

img-reader-formatsclj

Supported readable image formats. Machine/configuration dependant.

Supported readable image formats. Machine/configuration dependant.
sourceraw docstring

img-writer-formatsclj

Supported writable image formats. Machine/configuration dependant.

Supported writable image formats. Machine/configuration dependant.
sourceraw docstring

int-array-2dclj

(int-array-2d sizex sizey)

Create 2d int array getter and setter methods. Array is mutable!

Create 2d int array getter and setter methods. Array is mutable!
sourceraw docstring

intersects-rectangle?clj

(intersects-rectangle? shape [x y w h])
(intersects-rectangle? shape x y w h)

Returns true if given rectangle is inside a shape.

Returns `true` if given rectangle is inside a shape.
sourceraw docstring

inv-transformclj

(inv-transform canvas [x y])
(inv-transform canvas x y)

Inverse transform of given point or coordinates with current transformation. See transform.

Inverse transform of given point or coordinates with current transformation. See [[transform]].
sourceraw docstring

key-charclj

(key-char e)

Key as char.

Key as char.
sourceraw docstring

key-codeclj

(key-code e)

Keycode mapped to keyword. See java.awt.event.KeyEvent documentation. Eg. VK_LEFT is mapped to :left.

Keycode mapped to keyword. See `java.awt.event.KeyEvent` documentation. Eg. `VK_LEFT` is mapped to `:left`.
sourceraw docstring

key-eventcljmultimethod

Called on key event

  • Dispatch: vector of window name and key event. See key-event-map.
  • Params: key event and current state.

Should return state.

(defmethod key-event ["My window name" :key-pressed] [event state]
  ;; do something when 'up' is typed
  (when (= :up (key-code event)) (do-something))
  state)
Called on key event

* Dispatch: vector of window name and key event. See [[key-event-map]].
* Params: key event and current state.

Should return state.

```
(defmethod key-event ["My window name" :key-pressed] [event state]
  ;; do something when 'up' is typed
  (when (= :up (key-code event)) (do-something))
  state)
```
sourceraw docstring

key-event-mapclj

Map of supported key events

Map of supported key events
sourceraw docstring

key-pressedcljmultimethod

Called when key is pressed.

  • Dispatch: vector of window name and key char
  • Params: key event and current state.

Should return state.

(defmethod key-pressed ["My window name" \c] [event state]
  ;; do something when 'c' is pressed
  (assoc state :some (calculate-something state)))
Called when key is pressed.

* Dispatch: vector of window name and key char
* Params: key event and current state.

Should return state.

```
(defmethod key-pressed ["My window name" \c] [event state]
  ;; do something when 'c' is pressed
  (assoc state :some (calculate-something state)))
```
sourceraw docstring

key-pressed?clj

(key-pressed? w)

Any key pressed? (boolean)

Any key pressed? (boolean)
sourceraw docstring

key-rawclj

(key-raw e)

Raw value for pressed key (as integer).

Raw value for pressed key (as integer).
sourceraw docstring

key-releasedcljmultimethod

Called when key is released.

  • Dispatch: vector of window name and key char
  • Params: key event and current state.

Should return state.

(defmethod key-released ["My window name" \c] [event state]
  ;; do something after 'c' is released
  (assoc state :some (calculate-something state)))
Called when key is released.

* Dispatch: vector of window name and key char
* Params: key event and current state.

Should return state.

```
(defmethod key-released ["My window name" \c] [event state]
  ;; do something after 'c' is released
  (assoc state :some (calculate-something state)))
```
sourceraw docstring

key-typedcljmultimethod

Called when key is typed (pressed and released).

  • Dispatch: vector of window name and key char
  • Params: key event and current state.

Should return state.

(defmethod key-typed ["My window name" \c] [event state]
  ;; do something when 'c' is typed
  (assoc state :some (calculate-something state)))
Called when key is typed (pressed and released).

* Dispatch: vector of window name and key char
* Params: key event and current state.

Should return state.

```
(defmethod key-typed ["My window name" \c] [event state]
  ;; do something when 'c' is typed
  (assoc state :some (calculate-something state)))
```
sourceraw docstring

lineclj

(line canvas vect1 vect2)
(line canvas x1 y1 x2 y2)

Draw line from point (x1,y1) to (x2,y2)

Draw line from point `(x1,y1)` to `(x2,y2)`
sourceraw docstring

load-bytesclj

(load-bytes file-or-url)

Load file or http and return byte array.

Load file or http and return byte array.
sourceraw docstring

load-fontclj

(load-font font-file-or-url)

Load font from file or url. Only TrueType and OpenTrueType fonts are supported.

Load font from file or url. Only TrueType and OpenTrueType fonts are supported.
sourceraw docstring

load-imageclj

(load-image filename-or-url)

Load Image from file.

  • Input: Image filename with absolute or relative path (relative to your project folder) or url.
  • Returns BufferedImage object or nil when Image can't be loaded.

For supported formats check img-reader-formats.

Load Image from file.

* Input: Image filename with absolute or relative path (relative to your project folder) or url.
* Returns BufferedImage object or nil when Image can't be loaded.

For supported formats check [[img-reader-formats]].
sourceraw docstring

load-svgclj

(load-svg filename-or-url)

Load image into Batik Document. See transcode-svg.

Load image into Batik Document. See [[transcode-svg]].
sourceraw docstring

load-url-imageclj

(load-url-image url)

Load image from given URL, see load-image.

Load image from given URL, see [[load-image]].
sourceraw docstring

logclj

(log message)

Log message to file or console

Log message to file or console
sourceraw docstring

log-nameclj

(log-name)

Returns log file name with path.

Returns log file name with path.
sourceraw docstring

long-array-2dclj

(long-array-2d sizex sizey)

Create 2d int array getter and setter methods. Array is mutable!

Create 2d int array getter and setter methods. Array is mutable!
sourceraw docstring

make-counterclj

(make-counter)
(make-counter v)

Create counter function, each call returns next number.

Create counter function, each call returns next number.
sourceraw docstring

make-graphicsclj

(make-graphics canvas)

Create new Graphics2D object and set rendering hints.

Do not use directly. Call with-canvas-> or with-canvas macros.

Create new `Graphics2D` object and set rendering hints.

Do not use directly. Call [[with-canvas->]] or [[with-canvas]] macros.
sourceraw docstring

make-sessionclj

(make-session)

Create session via agent

Create session via agent
sourceraw docstring

meta-down?clj

(meta-down? e)

META key state as boolean.

META key state as boolean.
sourceraw docstring

millisclj

(millis)

Milliseconds from epoch

Milliseconds from epoch
sourceraw docstring

minuteclj

(minute)

Current minute

Current minute
sourceraw docstring

monthclj

(month)

Current month

Current month
sourceraw docstring

mouse-buttonclj

(mouse-button m)

Get mouse pressed button status: :left :right :center or :none

Get mouse pressed button status: :left :right :center or :none
sourceraw docstring

mouse-eventcljmultimethod

Called on mouse event

  • Dispatch: vector of window name and mouse event. See mouse-event-map.
  • Params: key event and current state.

Should return state.

(defmethod mouse-event ["My window name" :mouse-pressed] [event state]
  ;; do something when button is pressed
  (do-something)
  state)
Called on mouse event

* Dispatch: vector of window name and mouse event. See [[mouse-event-map]].
* Params: key event and current state.

Should return state.

```
(defmethod mouse-event ["My window name" :mouse-pressed] [event state]
  ;; do something when button is pressed
  (do-something)
  state)
```
sourceraw docstring

mouse-event-mapclj

Map of supported mouse events

Map of supported mouse events
sourceraw docstring

mouse-in-window?clj

(mouse-in-window? window)

Check if mouse is inside window.

Check if mouse is inside window.
sourceraw docstring

mouse-posclj

(mouse-pos m)

Mouse position as [[Vec2]] type. [0,0] - top left, [-1,-1] outside window.

Mouse position as [[Vec2]] type. [0,0] - top left, [-1,-1] outside window.
sourceraw docstring

mouse-pressed?clj

(mouse-pressed? w)

Any mouse button pressed? (boolean)

Any mouse button pressed? (boolean)
sourceraw docstring

mouse-xclj

(mouse-x m)

Mouse horizontal position within window. 0 - left side. -1 outside window.

Mouse horizontal position within window. 0 - left side. -1 outside window.
sourceraw docstring

mouse-yclj

(mouse-y m)

Mouse vertical position within window. 0 - left side. -1 outside window.

Mouse vertical position within window. 0 - left side. -1 outside window.
sourceraw docstring

nanosclj

(nanos)

JVM running time in nanoseconds

JVM running time in nanoseconds
sourceraw docstring

next-filenameclj

(next-filename prefix)
(next-filename prefix suffix)

Create next unique filename based on session

Create next unique filename based on session
sourceraw docstring

orient-canvascljmultimethod

Place origin into one of four window corners and reorient axes.

  • - as suffix - means default orientation (y-axis reversed)
  • + as suffix - means usual (mathematical) orientation (y-axis not reversed).
Place origin into one of four window corners and reorient axes.

* `-` as suffix - means default orientation (y-axis reversed)
* `+` as suffix - means usual (mathematical) orientation (y-axis not reversed).
sourceraw docstring

orientations-listclj

List of orientations

List of orientations
sourceraw docstring

paint-modeclj

(paint-mode canvas)

Set normal paint mode.

This is default mode.

See gradient-mode or xor-mode for other types.

Set normal paint mode.

This is default mode.

See [[gradient-mode]] or [[xor-mode]] for other types.
sourceraw docstring

pathclj

(path canvas vs)
(path canvas vs close?)
(path canvas vs close? stroke?)

Draw path from lines.

Input: list of points as vectors, close? - close path or not (default: false), stroke? - draw lines or filled shape (default true - lines).

See also path-bezier.

Draw path from lines.

Input: list of points as vectors, close? - close path or not (default: false), stroke? - draw lines or filled shape (default true - lines).

See also [[path-bezier]].
sourceraw docstring

path-bezierclj

(path-bezier canvas vs)
(path-bezier canvas vs close?)
(path-bezier canvas vs close? stroke?)

Draw path from quad curves.

Input: list of points as vectors, close? - close path or not (default: false), stroke? - draw lines or filled shape (default true - lines).

See also path.

Draw path from quad curves.

Input: list of points as vectors, close? - close path or not (default: false), stroke? - draw lines or filled shape (default true - lines).

See also [[path]].
sourceraw docstring

path-bezier-shapeclj

(path-bezier-shape vs)
(path-bezier-shape vs close?)
source

path-def->shapeclj

(path-def->shape path-def)

Create a shape from path definition, see shape->path-def.

Path entry is a tripplet [command arguments [winding-rule]]

  • [:move [x y]] - move to a position
  • [:line [x y]] - line to a position
  • [:quad [x1 y1 x2 y2] - curved line to a position
  • [:cubic [x1 y1 x2 y2 x3 y3]] - bezier line to a position
  • [:close] - close path
  • [:shape [shape-object connect?]] - append given shape

Winding rule can be one of :even-odd and :non-zero (default) and is optional.

Create a shape from path definition, see [[shape->path-def]].

Path entry is a tripplet [command arguments [winding-rule]]  

* `[:move [x y]]` - move to a position
* `[:line [x y]]` - line to a position
* `[:quad [x1 y1 x2 y2]` - curved line to a position
* `[:cubic [x1 y1 x2 y2 x3 y3]]` - bezier line to a position
* `[:close]` - close path
* `[:shape [shape-object connect?]]` - append given shape

Winding rule can be one of `:even-odd` and `:non-zero` (default) and is optional. 
sourceraw docstring

path-shapeclj

(path-shape vs)
(path-shape vs close?)

Create shape object out of path.

Create shape object out of path.
sourceraw docstring

pattern-modeclj

(pattern-mode canvas image)
(pattern-mode canvas image w h)
(pattern-mode canvas image anchor-x anchor-y w h)

Set paint mode to pattern.

Default anchor is set to (0,0). Default width and height are the same as texture dimensions.

To revert call paint-mode

Set paint mode to pattern.

Default anchor is set to `(0,0)`. Default width and height are the same as texture dimensions.

To revert call [[paint-mode]]
sourceraw docstring

pointclj

(point canvas [x y])
(point canvas x y)

Draw point at x,y or at vector position.

It's implemented as a very short line. Consider using (rect x y 1 1) for speed when x and y are integers.

Draw point at `x`,`y` or at vector position.

It's implemented as a very short line. Consider using `(rect x y 1 1)` for speed when `x` and `y` are integers.
sourceraw docstring

pointy-hexclj

(pointy-hex canvas [x y] size)
(pointy-hex canvas x y size)
(pointy-hex canvas x y size stroke?)

Draw pointy topped hex.

Draw pointy topped hex.
sourceraw docstring

pointy-hex-shapeclj

(pointy-hex-shape [x y] size)
(pointy-hex-shape x y size)
source

pop-matrixclj

(pop-matrix canvas)

Restore saved transformation state.

See also push-matrix, reset-matrix.

Restore saved transformation state.

See also [[push-matrix]], [[reset-matrix]].
sourceraw docstring

prectclj

(prect canvas [x1 y1] [x2 y2])
(prect canvas x1 y1 x2 y2)
(prect canvas x1 y1 x2 y2 stroke?)

Draw rectangle with top-left corner at (x1,y1) and bottom-right corner at (x2,y2). Optionally you can set stroke? (default: false) to true if you don't want to fill rectangle and draw outline only.

See also: rect.

Draw rectangle with top-left corner at `(x1,y1)` and bottom-right corner at `(x2,y2)`. Optionally you can set `stroke?` (default: `false`) to `true` if you don't want to fill rectangle and draw outline only.

See also: [[rect]].
sourceraw docstring

prect-shapeclj

(prect-shape [x y] w h)
(prect-shape x y w h)
(prect-shape r x1 y1 x2 y2)
source

push-matrixclj

(push-matrix canvas)

Remember current transformation state.

See also pop-matrix, reset-matrix.

Remember current transformation state.

See also [[pop-matrix]], [[reset-matrix]].
sourceraw docstring

quadclj

(quad canvas [x1 y1] [x2 y2] [x3 y3] [x4 y4])
(quad canvas x1 y1 x2 y2 x3 y3 x4 y4)
(quad canvas x1 y1 x2 y2 x3 y3 x4 y4 stroke?)

Draw quad with corners at 4 positions.

Draw quad with corners at 4 positions.
sourceraw docstring

quad-shapeclj

(quad-shape [x1 y1] [x2 y2] [x3 y3] [x4 y4])
(quad-shape x1 y1 x2 y2 x3 y3 x4 y4)
source

rarcclj

(rarc canvas [x y] r start extent)
(rarc canvas x y r start extent)
(rarc canvas x y r start extent type)
(rarc canvas x y r start extent type stroke?)

Draw arc with middle at (x,y) with radius r.

Starting angle start and extent are in radians. Direction is clockwise.

Type is one of the:

  • :open
  • :pie
  • :chord
Draw arc with middle at `(x,y)` with radius `r`.

Starting angle `start` and `extent` are in radians. Direction is clockwise.

Type is one of the:

* `:open`
* `:pie`
* `:chord`
sourceraw docstring

rarc-shapeclj

(rarc-shape [x y] r start extent)
(rarc-shape x y r start extent)
(rarc-shape x y r start extent type)
(rarc-shape a x y r start extent type)
source

rectclj

(rect canvas [x y] w h)
(rect canvas x y w h)
(rect canvas x y w h stroke?)

Draw rectangle with top-left corner at (x,y) position with width w and height h. Optionally you can set stroke? (default: false) to true if you don't want to fill rectangle and draw outline only.

See also: crect and prect.

Draw rectangle with top-left corner at `(x,y)` position with width `w` and height `h`. Optionally you can set `stroke?` (default: `false`) to `true` if you don't want to fill rectangle and draw outline only.

See also: [[crect]] and [[prect]].
sourceraw docstring

rect-shapeclj

(rect-shape [x y] w h)
(rect-shape x y w h)
(rect-shape r x y w h)
source

rendering-hintsclj

Rendering hints define quality of drawing or window rendering.

The differences are in interpolation, antialiasing, speed vs quality rendering etc. See the source code for the list of each value.

The :highest is :high with VALUE_STROKE_PURE added. Be aware that this option can give very soft lines.

Default hint for Canvas is :high. You can set also hint for Window which means that when display is refreshed this hint is applied (java defaults are used otherwise).

Rendering hints define quality of drawing or window rendering.

The differences are in interpolation, antialiasing, speed vs quality rendering etc. See the source code for the list of each value.

The `:highest` is `:high` with `VALUE_STROKE_PURE` added. Be aware that this option can give very soft lines.

Default hint for Canvas is `:high`. You can set also hint for Window which means that when display is refreshed this hint is applied (java defaults are used otherwise).
sourceraw docstring

repaintclj

(repaint window)

Repaints window, call only in :onrepaint mode

Repaints window, call only in `:onrepaint` mode
sourceraw docstring

replace-canvasclj

(replace-canvas window canvas)

Replace canvas in window.

  • Input: window and new canvas
  • Returns canvas
Replace canvas in window.

* Input: window and new canvas
* Returns canvas
sourceraw docstring

reset-clipclj

(reset-clip canvas)

Resets current clipping.

See also clip.

Resets current clipping.

See also [[clip]].
sourceraw docstring

reset-matrixclj

(reset-matrix canvas)

Reset transformations.

Reset transformations.
sourceraw docstring

resizeclj

(resize i w h)

Resize image.

Resize image.
sourceraw docstring

rotateclj

(rotate canvas angle)

Rotate canvas

Rotate canvas
sourceraw docstring

saveclj

(save i n)

Save image i to a file n.

Save image `i` to a file `n`.
sourceraw docstring

save-file-typecljmultimethod

Save Image to the file.

Preprocess if necessary (depends on file type). For supported formats check img-writer-formats.

Dispatch is based on extension as keyword, ie. ".jpg" -> :jpg.

Save Image to the file.

Preprocess if necessary (depends on file type). For supported formats check [[img-writer-formats]].

Dispatch is based on extension as keyword, ie. ".jpg" -> `:jpg`.
sourceraw docstring

save-imageclj

(save-image b filename)

Save image to the file.

  • Input: image (BufferedImage object) and filename
  • Side effect: saved image

Image is saved using save-file-type multimethod.

Save image to the file.

* Input: image (`BufferedImage` object) and filename
* Side effect: saved image

Image is saved using [[save-file-type]] multimethod.
sourceraw docstring

scaleclj

(scale canvas s)
(scale canvas scalex scaley)

Scale canvas

Scale canvas
sourceraw docstring

screen-heightclj

(screen-height)

Returns height of the screen.

Returns height of the screen.
sourceraw docstring

screen-widthclj

(screen-width)

Returns width of the screen.

Returns width of the screen.
sourceraw docstring

secclj

(sec)

Current second

Current second
sourceraw docstring

session-nameclj

(session-name)

Get session name

Get session name
sourceraw docstring

set-awt-backgroundclj

(set-awt-background canvas c)

Set background color. Expects valid java.awt.Color object.

Set background color. Expects valid `java.awt.Color` object.
sourceraw docstring

set-awt-colorclj

(set-awt-color canvas c)

Set color with valid java Color object. Use it when you're sure you pass java.awt.Color object.

Set color with valid java `Color` object. Use it when you're sure you pass `java.awt.Color` object.
sourceraw docstring

set-backgroundclj

(set-background canvas c)
(set-background canvas c a)
(set-background canvas r g b)
(set-background canvas r g b a)

Sets background with given color.

Background can be set with alpha.

See set-color.

Sets background with given color.

Background can be set with alpha.

See [[set-color]].
sourceraw docstring

set-colorclj

(set-color canvas c)
(set-color canvas c a)
(set-color canvas r g b)
(set-color canvas r g b a)

Sets current color. Color can be:

  • [[vec3]], [[vec4]] with rgb values.
  • java.awt.Color object
  • keyword with name from 140 HTML color names
  • Integer
  • r, g, b and optional alpha

See clojure2d.color namespace for more color functions.

Sets current color. Color can be:

* [[vec3]], [[vec4]] with rgb values.
* java.awt.Color object
* keyword with name from 140 HTML color names
* Integer
* r, g, b and optional alpha

See [[clojure2d.color]] namespace for more color functions.
sourceraw docstring

set-compositeclj

(set-composite canvas)
(set-composite canvas composite)

Set composite method for blending during draw.

See [[composite]] to create one defined by clojure2d.color blending modes.

You can also use ones defined in java.awt.AlphaComposite class.

Call witout parameters to revert to default: java.awt.AlphaComposite/SrcOver.

Set composite method for blending during draw.

See [[composite]] to create one defined by [[clojure2d.color]] blending modes.

You can also use ones defined in `java.awt.AlphaComposite` class.

Call witout parameters to revert to default: `java.awt.AlphaComposite/SrcOver`.
sourceraw docstring

set-fontclj

(set-font canvas font-or-fontname)

Set font by name or actual font.

Set font by name or actual font.
sourceraw docstring

set-font-attributesclj

(set-font-attributes canvas size)
(set-font-attributes canvas size style)

Set current font size and attributes.

Attributes are: :bold, :italic, :bold-italic.

Set current font size and attributes.

Attributes are: `:bold`, `:italic`, `:bold-italic`.
sourceraw docstring

set-state!clj

(set-state! w state)

Changle global state for Window.

Changle global state for Window.
sourceraw docstring

set-strokeclj

(set-stroke canvas)
(set-stroke canvas size)
(set-stroke canvas size cap)
(set-stroke canvas size cap join)
(set-stroke canvas size cap join miter-limit)

Set stroke (line) attributes like cap, join, size and miter-limit.

Default :round and :bevel are used. Default size and miter-limit are 1.0.

See stroke-joins and stroke-caps for names.

See set-stroke-custom.

Set stroke (line) attributes like `cap`, `join`,  size and `miter-limit`.

Default `:round` and `:bevel` are used. Default size and miter-limit are `1.0`.

See [[stroke-joins]] and [[stroke-caps]] for names.

See [[set-stroke-custom]].
sourceraw docstring

set-stroke-customclj

(set-stroke-custom
  canvas
  {:keys [size cap join miter-limit dash dash-phase]
   :or
     {size 1.0 cap :butt join :round miter-limit 1.0 dash nil dash-phase 0.0}})

Create custom stroke.

Provide map with following entries, see more in JavaDoc:

  • :size - size of the stroke (default: 1.0)
  • :cap - stroke-caps (default: :butt)
  • :join - stroke-joins (default: :round)
  • :miter-limit - line joins trim factor (default: 1.0)
  • :dash - array with dash pattern, (default: nil)
  • :dash-phase - offset to start pattern (default: 0.0)

See also set-stroke.

Create custom stroke.

Provide map with following entries, see more in [JavaDoc](https://docs.oracle.com/javase/7/docs/api/java/awt/BasicStroke.html):

* :size - size of the stroke (default: 1.0)
* :cap - [[stroke-caps]] (default: :butt)
* :join - [[stroke-joins]] (default: :round)
* :miter-limit - line joins trim factor (default: 1.0)
* :dash - array with dash pattern, (default: nil)
* :dash-phase - offset to start pattern (default: 0.0)

See also [[set-stroke]].
sourceraw docstring

shapeclj

(shape canvas sh)
(shape canvas sh stroke?)

Draw Java2D shape object

Draw Java2D shape object
sourceraw docstring

shape->path-defclj

(shape->path-def shape)

Create path definition from a shape

Returns sequence of triplets of [command coords winding-rule]:

  • [:move [x y]] - move to a position
  • [:line [x y]] - line to a position
  • [:quad [x1 y1 x2 y2] - curved line to a position
  • [:cubic [x1 y1 x2 y2 x3 y3]] - bezier line to a position
  • [:close] - close path

Winding rule is one of :even-odd and :non-zero (default)

See path-def->shape

Create path definition from a shape

Returns sequence of triplets of [command coords winding-rule]:

* `[:move [x y]]` - move to a position
* `[:line [x y]]` - line to a position
* `[:quad [x1 y1 x2 y2]` - curved line to a position
* `[:cubic [x1 y1 x2 y2 x3 y3]]` - bezier line to a position
* `[:close]` - close path

Winding rule is one of `:even-odd` and `:non-zero` (default)  

See [[path-def->shape]]
sourceraw docstring

shearclj

(shear canvas s)
(shear canvas sx sy)

Shear canvas

Shear canvas
sourceraw docstring

shift-down?clj

(shift-down? e)

SHIFT key state as boolean.

SHIFT key state as boolean.
sourceraw docstring

show-windowclj

(show-window)
(show-window {:keys [canvas window-name w h fps draw-fn state draw-state setup
                     hint refresher always-on-top? background position]
              :or {canvas (canvas 200 200)
                   window-name (str "Clojure2D - "
                                    (to-hex (rand-int (Integer/MAX_VALUE)) 8))
                   fps 60
                   background :white
                   refresher :safe}})
(show-window canvas window-name)
(show-window canvas window-name draw-fn)
(show-window canvas window-name fps draw-fn)
(show-window canvas window-name w h fps)
(show-window canvas window-name w h fps draw-fn)

Show window for given canvas

  • Returns Window type value

As parameters you can provide a map with folowing keys:

  • :canvas - canvas attached to window (default is canvas 200x200 px)
  • :window-name - window name, used also for events dispatch and global state
  • :w - width of the window (default as canvas width)
  • :h - height of the window (default as canvas heiht)
  • :fps - refresh rate
  • :draw-fn - drawing callback (fn [canvas window frame loop-state] ... new-loop-state)
  • :state - initial global state data
  • :draw-state - initial drawing state
  • :setup - inital callback function, returns drawing state (fn [canvas window] ... initial-loop-state)
  • :hint - rendering hint for display: :low, :mid, :high or :highest
  • :refresher - :safe (default), :fast, :onrepaint
  • :background - background color for window panel, default white.
  • :position - window position as a pair of [x y], nil (default) for center.

:refresher controls what to do with repainting a window. :safe and :fast repaint a window autmatically, calling draw-fn (if provided) and repaint is done :fps times per second. :onrepaint leaves repainting to the AWT or user by calling repaint, draw-fn is ignored.

Show window for given canvas

* Returns `Window` type value

As parameters you can provide a map with folowing keys:

* `:canvas` - canvas attached to window (default is canvas 200x200 px)
* `:window-name` - window name, used also for events dispatch and global state
* `:w` - width of the window (default as canvas width)
* `:h` - height of the window (default as canvas heiht)
* `:fps` - refresh rate
* `:draw-fn` - drawing callback (fn [canvas window frame loop-state] ... new-loop-state)
* `:state` - initial global state data
* `:draw-state` - initial drawing state
* `:setup` - inital callback function, returns drawing state (fn [canvas window] ... initial-loop-state)
* `:hint` - rendering hint for display: `:low`, `:mid`, `:high` or `:highest`
* `:refresher` - `:safe` (default), `:fast`, `:onrepaint`
* `:background` - background color for window panel, default white.
* `:position` - window position as a pair of [x y], `nil` (default) for center.

`:refresher` controls what to do with repainting a window. `:safe` and `:fast` repaint a window autmatically, calling `draw-fn` (if provided) and repaint is done `:fps` times per second. `:onrepaint` leaves repainting to the AWT or user by calling `repaint`, `draw-fn` is ignored.
sourceraw docstring

stroke-capsclj

Stroke cap types

Stroke cap types
sourceraw docstring

stroke-joinsclj

Stroke join types

Stroke join types
sourceraw docstring

subimageclj

(subimage i x y w h)

Return rectangular subimage

Return rectangular subimage
sourceraw docstring

textclj

(text canvas s x y)
(text canvas s x y align)

Draw text for given position and alignment.

Possible alignments are: :right, :center, :left.

Draw text for given position and alignment.

Possible alignments are: `:right`, `:center`, `:left`.
sourceraw docstring

text-bounding-boxclj

(text-bounding-box canvas txt)

Returns bounding box [x,y,w,h] for given text. [x,y] position is relative to base line.

Returns bounding box [x,y,w,h] for given text. `[x,y]` position is relative to base line.
sourceraw docstring

text-shapeclj

(text-shape canvas txt)
(text-shape canvas txt x y)

Returns shape for given text. Should be called withing context.

Returns shape for given text. Should be called withing context.
sourceraw docstring

text-widthclj

(text-width canvas txt)

Returns width of the provided string. Should be called within context.

Returns width of the provided string. Should be called within context.
sourceraw docstring

to-hexclj

(to-hex n)
(to-hex n pad)

Return hex value of given number, padded with leading zeroes if given length

Return hex value of given number, padded with leading zeroes if given length
sourceraw docstring

to-imageclj

(to-image i)

Return BufferedImage, alias for get-image

Return BufferedImage, alias for `get-image`
sourceraw docstring

transcode-svgclj

(transcode-svg input w h)

Convert transcoder input into BufferedImage. See load-svg.

Convert transcoder input into BufferedImage. See [[load-svg]].
sourceraw docstring

transformclj

(transform canvas [x y])
(transform canvas x y)

Transform given point or coordinates with current transformation. See inv-transform.

Transform given point or coordinates with current transformation. See [[inv-transform]].
sourceraw docstring

translateclj

(translate canvas [x y])
(translate canvas tx ty)

Translate origin

Translate origin
sourceraw docstring

triangleclj

(triangle canvas [x1 y1] [x2 y2] [x3 y3])
(triangle canvas x1 y1 x2 y2 x3 y3)
(triangle canvas x1 y1 x2 y2 x3 y3 stroke?)

Draw triangle with corners at 3 positions.

Draw triangle with corners at 3 positions.
sourceraw docstring

triangle-fanclj

(triangle-fan canvas vs)
(triangle-fan canvas vs stroke?)

Draw triangle fan. Implementation of Processing FAN shape.

First point is common vertex of all triangles.

Input: list of vertices as vectors.

See also: triangle-strip.

Draw triangle fan. Implementation of `Processing` `FAN` shape.

First point is common vertex of all triangles.

Input: list of vertices as vectors.

See also: [[triangle-strip]].
sourceraw docstring

triangle-shapeclj

(triangle-shape [x1 y1] [x2 y2] [x3 y3])
(triangle-shape x1 y1 x2 y2 x3 y3)
source

triangle-stripclj

(triangle-strip canvas vs)
(triangle-strip canvas vs stroke?)

Draw triangle strip. Implementation of Processing STRIP shape.

Input: list of vertices as vectors.

See also: triangle-fan.

Draw triangle strip. Implementation of `Processing` `STRIP` shape.

Input: list of vertices as vectors.

See also: [[triangle-fan]].
sourceraw docstring

virtual-keyclj

Use as a dispatch in key events for keys like up/down/etc.

Use as a dispatch in key events for keys like up/down/etc.
sourceraw docstring

widthclj

(width i)

Width of the image.

Width of the image.
sourceraw docstring

window-active?clj

(window-active? window)

Helper function, check if window is active.

Helper function, check if window is active.
sourceraw docstring

with-canvascljmacro

(with-canvas [c canvas] & body)

Macro which takes care to create and destroy Graphics2D object for drawings on canvas. Macro returns result of last call.

See also with-canvas->.

Macro which takes care to create and destroy `Graphics2D` object for drawings on canvas. Macro returns result of last call.

See also [[with-canvas->]].
sourceraw docstring

with-canvas->cljmacro

(with-canvas-> canvas & body)

Threading macro which takes care to create and destroy Graphics2D object for drawings on canvas. Macro returns result of last call.

Each function have to accept canvas as second parameter and have to return canvas.

See also with-canvas.

Threading macro which takes care to create and destroy `Graphics2D` object for drawings on canvas. Macro returns result of last call.

Each function have to accept canvas as second parameter and have to return canvas.

See also [[with-canvas]].
sourceraw docstring

with-oriented-canvascljmacro

(with-oriented-canvas orientation [c canv] & body)

Same as with-canvas but with initial orientation.

Same as [[with-canvas]] but with initial orientation.
sourceraw docstring

with-oriented-canvas->cljmacro

(with-oriented-canvas-> orientation canv & body)

Same as with-canvas-> but with initial orientation.

Same as [[with-canvas->]] but with initial orientation.
sourceraw docstring

xor-modeclj

(xor-mode canvas c)
(xor-mode canvas c a)
(xor-mode canvas r g b)
(xor-mode canvas r g b a)

Set XOR painting mode with given color.

Set XOR painting mode with given color.
sourceraw docstring

yearclj

(year)

Current year

Current year
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close