Liking cljdoc? Tell your friends :D

quip.util

Miscellaneous utility functions.

Vector math functions for position/rotation/velocity calculations.

Geometric collision detection predicates.

Misc utilities.

Miscellaneous utility functions.

Vector math functions for position/rotation/velocity calculations.

Geometric collision detection predicates.

Misc utilities.
raw docstring

backgroundclj


blackclj


blueclj


bold-fontclj


bold-italic-fontclj


centerclj

(center)

Create an [x y] position at the centre of the current game width and height.

Create an `[x y]` position at the centre of the current game width
and height.
raw docstring

centreclj


coarse-polys-collide?clj

(coarse-polys-collide? poly-a poly-b)

Predicate to determine if two polygons possibly collide.

Checks if the minimum rectangles containing the polygons overlap. If they do we should use fine-polys-collide? to check properly.

Predicate to determine if two polygons possibly collide.

Checks if the minimum rectangles containing the polygons overlap. If
they do we should use `fine-polys-collide?` to check properly.
raw docstring

coarse-pos-in-poly?clj

(coarse-pos-in-poly? [x y] poly)

Predicate to determine if a point is possibly inside a polygon.

Checks if the point is contanied by the minimum rectangle containing the polygon. If the point is inside this rectangle we should use fine-pos-in-poly? to check properly.

Predicate to determine if a point is possibly inside a polygon.

Checks if the point is contanied by the minimum rectangle containing
the polygon. If the point is inside this rectangle we should use
`fine-pos-in-poly?` to check properly.
raw docstring

darkenclj

(darken [_r _g _b a :as color])

Darken a colour by 30, preserving alpha component if present.

Darken a colour by 30, preserving alpha component if present.
raw docstring

default-fontclj


default-text-sizeclj


direction-vectorclj

(direction-vector r)

Calculate the unit direction vector based on the rotation angle.

Calculate the unit direction vector based on the rotation angle.
raw docstring

equal-pos?clj

(equal-pos? pos-a pos-b)

Predicate to check if two positions are equal.

Predicate to check if two positions are equal.
raw docstring

fillclj


fine-polys-collide?clj

(fine-polys-collide? poly-a poly-b)

Predicate to determine if two polygons overlap.

We first check if there are any points shared by the polygons, then we check if any of the lines intersect.

If no lines intersect it is still possible that one polygon is fully containing the other. In this case one polygon will contain all the points of the other. So we can just check if the first point of poly-a is contained in poly-b or vice versa.

Predicate to determine if two polygons overlap.

We first check if there are any points shared by the polygons, then
we check if any of the lines intersect.

If no lines intersect it is still possible that one polygon is fully
containing the other. In this case one polygon will contain all the
points of the other. So we can just check if the first point of
poly-a is contained in poly-b or vice versa.
raw docstring

fine-pos-in-poly?clj

(fine-pos-in-poly? pos poly)

Uses ray casting to check if a polygon encloses a pos.

We construct a line starting at our point and count how many of the polygon lines it intersects, an odd number of intersections means the point is inside the polygon.

Our line should be infinite, but in practice any large number will suffice.

Uses ray casting to check if a polygon encloses a pos.

We construct a line starting at our point and count how many of the
polygon lines it intersects, an odd number of intersections means
the point is inside the polygon.

Our line should be infinite, but in practice any large number will
suffice.
raw docstring

grayclj


greenclj


greyclj


hex->rgbclj

(hex->rgb hex-string)

invertclj

(invert v)

Multiply each component of the vector by -1.

Represents a rotation of 180 degrees.

Multiply each component of the vector by -1.

Represents a rotation of 180 degrees.
raw docstring

italic-bold-fontclj


italic-fontclj


large-text-sizeclj


lightenclj

(lighten [_r _g _b a :as color])

Lighten a colour by 30, preserving alpha component if present.

Lighten a colour by 30, preserving alpha component if present.
raw docstring

lines-intersect?clj

(lines-intersect? [[x1 y1 :as p1] [x2 y2 :as p2] :as l1]
                  [[x3 y3 :as p3] [x4 y4 :as p4] :as l2])

Predicate to determine if two lines intersect.

We have decided that zero-length lines do not intersect as the complexity in determining their intersection is not worth the performance hit.

line a: (x1, y1) -> (x2, y2) line b: (x3, y3) -> (x4, y4)

lines intersect iff: 0.0 <= numerator-t/denominator-t <= 1.0 and 0.0 <= numerator-u/denominator-u <= 1.0

We can just assert that the fraction is bottom-heavy.

Predicate to determine if two lines intersect.

We have decided that zero-length lines do not intersect as the
complexity in determining their intersection is not worth the
performance hit.

line a: (x1, y1) -> (x2, y2)
line b: (x3, y3) -> (x4, y4)

lines intersect iff:
     0.0 <= numerator-t/denominator-t <= 1.0
and  0.0 <= numerator-u/denominator-u <= 1.0

We can just assert that the fraction is bottom-heavy.
raw docstring

magnitudeclj

(magnitude v)

Calculate the length of a vector.

Calculate the length of a vector.
raw docstring

make-posclj

(make-pos [x-factor y-factor])

Create an [x y] vector based on the supplied factors and the current game width and height.

Create an `[x y]` vector based on the supplied factors and the
current game width and height.
raw docstring

ms->framesclj

(ms->frames ms)
(ms->frames ms frame-rate)

Determines the expected number of frames to be processed in ms milliseconds. Useful for defining tweens or delays based on time instead of frame count directly.

Optionally takes a specific framerate (in case you want to use the :average-fps in the game state for a more stable result).

Minimum returned value is 1.

Determines the expected number of frames to be processed in `ms`
milliseconds. Useful for defining tweens or delays based on time
instead of frame count directly.

Optionally takes a specific framerate (in case you want to use the
`:average-fps` in the game state for a more stable result).

Minimum returned value is 1.
raw docstring

normalizeclj

(normalize v)

Calculate the unit vector of a given vector.

We calculate the reciprocal of the magnitude of the vector and multiply the components by this factor to avoid multiple division operations.

Calculate the unit vector of a given vector.

We calculate the reciprocal of the magnitude of the vector and
multiply the components by this factor to avoid multiple division
operations.
raw docstring

orthogonalsclj

(orthogonals [x y])

Calculate the two orthogonal vectors to a given 2D vector.

Y axis is inverted so this returns [90-degrees-right-vector 90-degrees-left-vector]

Calculate the two orthogonal vectors to a given 2D vector.

Y axis is inverted so this returns [90-degrees-right-vector
                                    90-degrees-left-vector]
raw docstring

poly-linesclj

(poly-lines poly)

Construct the lines that make up a polygon from its points.

Construct the lines that make up a polygon from its points.
raw docstring

poly-w-hclj

(poly-w-h poly)

polys-collide?clj

(polys-collide? poly-a poly-b)

Predicate to check if two polygons overlap.

The fine-polys-collide? predicate is expensive so we only do it if the cheaper coarse-polys-collide? says this is a possible collision.

Predicate to check if two polygons overlap.

The `fine-polys-collide?` predicate is expensive so we only do it if
the cheaper `coarse-polys-collide?` says this is a possible
collision.
raw docstring

pos->rayclj

(pos->ray [x y])

Creates an arbitrarily long line starting at the specified pos.

When doing poly->point collision detection a point lying on a horizontal edge of a poly would cause a division by zero if we used a horizontal ray.

This would be handled, but would not count as a collision so we increment y to make it much less likely that the intersecting lines are parallel.

Creates an arbitrarily long line starting at the specified pos.

When doing poly->point collision detection a point lying on a
horizontal edge of a poly would cause a division by zero if we used
a horizontal ray.

This would be handled, but would not count as a collision so we
increment y to make it much less likely that the intersecting lines
are parallel.
raw docstring

pos-in-poly?clj

(pos-in-poly? pos poly)

Predicate to check if a pos is inside a polygon.

The fine-pos-in-poly? predicate is expensive so we only do it if the cheaper coarse-pos-in-poly? says this is a possible collision.

Predicate to check if a pos is inside a polygon.

The `fine-pos-in-poly?` predicate is expensive so we only do it if
the cheaper `coarse-pos-in-poly?` says this is a possible
collision.
raw docstring

pos-in-rect?clj

(pos-in-rect? [ax ay] [bx1 by1 bx2 by2])

Predicate to check if a position is inside a rectangle.

Predicate to check if a position is inside a rectangle.
raw docstring

rects-overlap?clj

(rects-overlap? [ax1 ay1 ax2 ay2] [bx1 by1 bx2 by2])

Predicate to determine if two rectangles overlap.

Predicate to determine if two rectangles overlap.
raw docstring

redclj


rotate-vectorclj

(rotate-vector [x y :as v] r)

Rotate a vector about the origin by r degrees.

Checks first for r representing an integer number of rotations, in with case the vector will be unchanged.

Rotate a vector about the origin by `r` degrees.

Checks first for `r` representing an integer number of rotations, in
with case the vector will be unchanged.
raw docstring

rotation-angleclj

(rotation-angle [x y])

Calculate the rotation angle of a vector.

Calculate the rotation angle of a vector.
raw docstring

small-text-sizeclj


squared-magnitudeclj

(squared-magnitude [x y z])

Sum the squares of the components of a vector.

The if check on z is a lot faster than doing an apply or reduce across the vector.

Sum the squares of the components of a vector.

The `if` check on `z` is a lot faster than doing an `apply` or
`reduce` across the vector.
raw docstring

strokeclj


title-text-sizeclj


unit-vectorclj

(unit-vector v)

Calculate the unit vector of a given vector.

Calculate the unit vector of a given vector.
raw docstring

v<clj

(v< a b)

Determine if the magnitude of a vector a is less than the magnitude of vector b.

We can just compare the component squares to avoid the costly sqrt operations.

Determine if the magnitude of a vector `a` is less than the magnitude
of vector `b`.

We can just compare the component squares to avoid the costly `sqrt`
operations.
raw docstring

v<=clj

(v<= a b)

Determine if the magnitude of a vector a is less than or equal to the magnitude of vector b.

We can just compare the component squares to avoid the costly sqrt operations.

Determine if the magnitude of a vector `a` is less than or equal to
the magnitude of vector `b`.

We can just compare the component squares to avoid the costly `sqrt`
operations.
raw docstring

whiteclj


wrap-trans-rotclj

(wrap-trans-rot [x y] r f)

Perform a translation, a rotation, invoke the supplied function (probably drawing a sprite, then reset the transform matrix to the identity.

Perform a translation, a rotation, invoke the supplied
function (probably drawing a sprite, then reset the transform matrix
to the identity.
raw docstring

zero-vector?clj

(zero-vector? v)

Predicate to check if a vector has length 0.

Predicate to check if a vector has length 0.
raw docstring

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

× close