Liking cljdoc? Tell your friends :D

lambdaisland.witchcraft.cursor

Logo-like API for drawing blocks by using a walking metaphor.

This is a functional API, movements simply build up a list of block positions, call build! at the end to actually make them materialize in the game.

A cursor contains a current location (x/y/z), a directions (:north, :north-east, :east, etc.), and a current building material, e.g :lapis-block (see lambdaisland.witchcraft/materials).

It also contains a drawing flag :draw? and a list of blocks :blocks. When drawing is on, then any step will add a block to the list. build! creates blocks in the world based on this, and resets the list.

Call start to get an initial cursor, this will return a cursor that is one step ahead of the player (so what you draw is in sight), facing away from the player.

(require '[lambdaisland.witchcraft.cursor :as c])

(-> (c/start)
    (c/draw)
    (c/material :red-glazed-terracotta)
    (c/steps 3)
    (c/rotate 2)
    (c/material :blue-glazed-terracotta)
    (c/steps 3)
    (c/rotate 2)
    (c/material :green-glazed-terracotta)
    (c/steps 3)
    (c/rotate 2)
    (c/material :yellow-glazed-terracotta)
    (c/steps 3)
    (c/build)
    )
Logo-like API for drawing blocks by using a walking metaphor.

This is a functional API, movements simply build up a list of block positions,
call [[build!]] at the end to actually make them materialize in the game.

A cursor contains a current location (x/y/z), a
directions (:north, :north-east, :east, etc.), and a current building
material, e.g :lapis-block (see [[lambdaisland.witchcraft/materials]]).

It also contains a drawing flag `:draw?` and a list of blocks `:blocks`. When
drawing is on, then any step will add a block to the list. [[build!]] creates
blocks in the world based on this, and resets the list.

Call [[start]] to get an initial cursor, this will return a cursor that is one
step ahead of the player (so what you draw is in sight), facing away from the
player.

```
(require '[lambdaisland.witchcraft.cursor :as c])

(-> (c/start)
    (c/draw)
    (c/material :red-glazed-terracotta)
    (c/steps 3)
    (c/rotate 2)
    (c/material :blue-glazed-terracotta)
    (c/steps 3)
    (c/rotate 2)
    (c/material :green-glazed-terracotta)
    (c/steps 3)
    (c/rotate 2)
    (c/material :yellow-glazed-terracotta)
    (c/steps 3)
    (c/build)
    )
```
raw docstring

?blockclj

(?block c)

Add a block to the block list based on the current cursor location and material, but only if drawing is enabled. (pronounced "maybe block")

Add a block to the block list based on the current cursor location and
material, but only if drawing is enabled. (pronounced "maybe block")
sourceraw docstring

apply-matrixclj

(apply-matrix {:keys [origin dir] :as c} matrix)

Apply a single matrix to a single x/y/z map based on the origin.

Apply a single matrix to a single x/y/z map based on the origin.
sourceraw docstring

blockclj

(block {:keys [matrices block-fn] :as c :or {block-fn block-fn}})

Add a block to the block list based on the cursor location.

Will set multiple blocks if symmetries are defined, see [[reflect]].

Add a block to the block list based on the cursor location.

Will set multiple blocks if symmetries are defined, see [[reflect]].
sourceraw docstring

block-fnclj

(block-fn c)
source

block-valueclj

(block-value {:keys [x y z material data palette dir face-direction?
                     rotate-block]})

Get the x/y/z and material data for the current cursor, so we can use it to create a block. This also resolves any palette indirection for the material. If the material is a two-element vector (either explicitly or via the palette) then this is taken as [material material-data], and overrides the material-data in the cursor.

Get the x/y/z and material data for the current cursor, so we can use it to
create a block. This also resolves any palette indirection for the material.
If the material is a two-element vector (either explicitly or via the palette)
then this is taken as [material material-data], and overrides the
material-data in the cursor.
sourceraw docstring

buildcljdeprecated

See build!

See [[build!]]
sourceraw docstring

build!clj

(build! {:keys [blocks] :as cursor})

Apply the list of blocks in the cursor to the world.

Apply the list of blocks in the cursor to the world.
sourceraw docstring

default-materialclj

Material used if no material is specified. This one has an arrow on it, which will show the direction the cursor is moving into.

Material used if no material is specified. This one has an arrow on it, which
will show the direction the cursor is moving into.
sourceraw docstring

directionsclj

source

drawclj

(draw c)
(draw c draw?)

Enable/disable drawing. Enables by default, pass false to disable.

Enable/disable drawing. Enables by default, pass false to disable.
sourceraw docstring

excursionclj

(excursion cursor f)

Apply a block-drawing function f, then return to the original position.

Apply a block-drawing function f, then return to the original position.
sourceraw docstring

extrudeclj

(extrude cursor n)
(extrude cursor n dir)

Take the current block list and extrude it in a given direction, by default up.

Take the current block list and extrude it in a given direction, by default up.
sourceraw docstring

faceclj

(face cursor dir)

Face the cursor in a certain direction

Face the cursor in a certain direction
sourceraw docstring

flash!clj

(flash! c)
(flash! c timeout)

Like build, but shortly after undoes the build again

This is meant for REPL use where you can rapidly try out changes before committing to them.

Like build, but shortly after undoes the build again

This is meant for REPL use where you can rapidly try out changes before
committing to them.
sourceraw docstring

materialclj

(material c m)
(material c m md)

Set the current cursor material, and optionally material-data, to be used for consecutive blocks.

Set the current cursor material, and optionally material-data, to be used for
consecutive blocks.
sourceraw docstring

material->keywordclj

source

matricesclj

(matrices c & matrices)

Set matrices

Set matrices
sourceraw docstring

moveclj

(move cursor)
(move {:keys [draw? dir] :as cursor} n)
(move {:keys [draw?] :as cursor} n dir)
(move c n dir & more)

Move the cursor as with steps, but without drawing. Retains the cursor direction.

Move the cursor as with steps, but without drawing. Retains the cursor
direction.
sourceraw docstring

move-toclj

(move-to cursor loc)

Move the cursor to the given location, does not draw.

Move the cursor to the given location, does not draw.
sourceraw docstring

movementsclj

source

originclj

(origin c & a)

Set the origin around which matrix operations are performed

Set the origin around which matrix operations are performed
sourceraw docstring

paletteclj

(palette c m)

Add items to the palette. Takes a single map.

Add items to the palette. Takes a single map.
sourceraw docstring

patternclj

(pattern c pattern)

Draw a number of steps in a line, based on a sequence of materials. Note that in combination with palette this can also take a string, assuming you've added palette entries for the given characters.

Draw a number of steps in a line, based on a sequence of materials. Note that
in combination with palette this can also take a string, assuming you've added
palette entries for the given characters.
sourceraw docstring

relative-movementsclj

source

repsclj

(reps c n f & args)

Perform a function n times on the cursor

Perform a function n times on the cursor
sourceraw docstring

resolve-dirclj

(resolve-dir facing asked)

Helper for dealing with forward/left/right type of directions, instead of east/north/west.

Helper for dealing with forward/left/right type of directions, instead of
east/north/west.
sourceraw docstring

rotateclj

(rotate {:keys [dir xy-dir] :as cursor} n)

Rotate the cursor clockwise by a number of 1/8 turns clockwise.

Rotate the cursor clockwise by a number of 1/8 turns clockwise.
sourceraw docstring

rotate-dirclj

(rotate-dir dir n)

Given a direction keyword like :north or :south and a number, make that many 1/8 turns clockwise.

(rotate :north 4) ;; => :south

Given a direction keyword like :north or :south and a number, make that many
1/8 turns clockwise.

(rotate :north 4) ;; => :south
sourceraw docstring

startclj

(start)
(start loc)
(start loc dir)

Creates a new cursor, starting at the given location, or one step in front of the player's location.

Creates a new cursor, starting at the given location, or one step in front of
the player's location.
sourceraw docstring

stepclj

(step cursor)
(step {:keys [step-fn] :or {step-fn step-fn} :as cursor} dir)
(step cursor dir & dirs)

Take one step forward in the direction given, or the direction the cursor is facing. If drawing is enabled this will also add a block to the block list corresponding with the new location.

Take one step forward in the direction given, or the direction the cursor is
facing. If drawing is enabled this will also add a block to the block list
corresponding with the new location.
sourceraw docstring

step-fnclj

(step-fn c dir)
source

stepsclj

(steps cursor n)
(steps cursor n dir)
(steps cursor n dir & more)

Take n steps forward as with step, or in the direction specified. Can take multiple number/direction pairs to do a full walk. Will change the direction of the cursor to the direction of the final step.

Take n steps forward as with [[step]], or in the direction specified. Can take
multiple number/direction pairs to do a full walk. Will change the direction
of the cursor to the direction of the final step.
sourceraw docstring

symmetry-xzclj

(symmetry-xz c)
source

translateclj

(translate c offset)

Move all blocks in the block set, as well as the cursor, by a given offset.

Move all blocks in the block set, as well as the cursor, by a given offset.
sourceraw docstring

valid-movementsclj

source

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

× close