$Graphics
The $Graphics namespace houses graphics utilities for processing images and colors.
Constants
Light direction constants
These constants are common presets to be used as directions for directional lights.
$Graphics.DL_TOP = [ 0.0, 1.0, 1.0 ] // From the top
$Graphics.DL_LEFT = [ -1.0, 0.0, 1.0 ] // From the left
$Graphics.DL_RIGHT = [ 1.0, 0.0, 1.0 ] // From the right
$Graphics.DL_BOTTOM = [ 0.0, -1.0, 1.0 ] // From the bottom
$Graphics.DL_TL = [ -1.0, 1.0, 1.0 ] // From the top-left
$Graphics.DL_TR = [ 1.0, 1.0, 1.0 ] // From the top-right
$Graphics.DL_BL = [ -1.0, -1.0, 1.0 ] // From the bottom-left
$Graphics.DL_BR = [ 1.0, -1.0, 1.0 ] // From the bottom-right
$Graphics.DL_DIRECT = [ 0.0, 0.0, 1.0 ] // Frontlit
Read more:
Functions
dir_light
$Graphics.dir_light(float luminosity, color c, float[] direction) -> light
Creates and returns a directional light with a luminosity luminosity, a base color c, and a direction specified by the vector direction.
A directional light, as opposed to a point light, shines with a non-dimming luminosity/intensity from a particular direction. It does not originate at any particular position.
Note:
light objects are mutable. Arguments luminosity, c, and direction passed to the constructor can be overridden by using the mutator methods of light.
Read more:
gen_lookup
$Graphics.gen_lookup(image source, bool dim) -> image
Takes an image source and generates a corresponding lookup image where every non-transparent pixel in source is assigned a unique opaque RGB color. The flag dim determines whether the lookup will have vertical or horizontal striping.
Read more:
hsv
-
$Graphics.hsv(float h, float s, float v, int a) -> colorReturns a color built from its hue, saturation, value and alpha components. Unlike
rgba(), which takes as arguments integer values ranging from 0 to 255, each of the HSV component arguments (h,sandv) is a float ranging from 0.0 to 1.0.a, however, is still an integer ranging from 0 to 255.Throws:
Any of the following will result in a runtime exception:
- For any
compofh,s,v;comp < 0.0 - For any
compofh,s,v;comp > 1.0 a > 255a < 0
- For any
-
$Graphics.hsv(float h, float s, float v) -> colorEquivalent to
$Graphics.hsv(h, s, v, 255)
lerp_color
$Graphics.lerp_color(color a, color b, float t) -> color
Returns the resultant color of a linear interpolation operation performed on colors a and b.
- If
t <= 0.0, returnsa - If
t >= 1.0, returnsb - Otherwise (
0.0 < t < 1.0), returns color specified bya + (Δ * t)whereΔ = b - a
lighting
$Graphics.lighting(image texture, image normal, light<> lights) -> image
Sequentially applies a list of lights lights to texture by referencing the surface normal data provided by normal, and returns the lit image.
If texture and normal do not have the same dimensions, returns texture.
point_light
$Graphics.point_light(float luminosity, color c, float radius, int x, int y, float z) -> light
Creates and returns a point light with a source luminosity luminosity, a base color c, a radius radius, a source pixel position specified by x and y, and a relative source Z-axis position specified by z.
A z value of 0.0 means the light is level along the Z-axis with an image being illuminated. A positive z value means the light is in front of an illuminated image, while a negative z value means the light is behind an illuminated image.
A point light, as opposed to a directional light, originates at a specified point and shines from its source position with a linearly dimming luminosity up to a distance specified by its radius.
Note:
light objects are mutable. Arguments luminosity, c, radius, x, y, and z passed to the constructor can be overridden by using the mutator methods of light.
uv_mapping
$Graphics.uv_mapping(image texture, image map, image animation) -> image
Parameters:
texture- a color texturemap- a lookup map corresponding to the shape and dimensions oftexturewhere every non-transparent pixel should have a unique coloranimation- a specification for an animation using the colors inmap
Returns:
If texture and map do not have the same dimensions, returns animation.
Otherwise, returns the following image:
- Initializes a blank image with the same dimensions as
animation - For every non-transparent pixel at position
(ax, ay)inanimation…- checks if the color
csampled at that pixel is present inmap - If it is…
- assigns the first (and ideally only) pixel instance of
cas(mx, my) - sets position
(ax, ay)of the output image to the color of the pixel at(mx, my)intexture
- assigns the first (and ideally only) pixel instance of
- If it isn’t…
- sets position
(ax, ay)of the output image toc
- sets position
- checks if the color
Read more:
- UV mapping algorithm implementation

gen_lookup()- generating a naive lookup map for atexture