style

(module)

A module for setting the current drawing style used with various graphics functions in Codea, such as line()

General

style.push()
style.push(style)
style.pop()
style.reset()

Functions for manipulating the style stack, use these when you want to temporarily change the style and restore it to it’s previous state

Use style.reset() to restore the default style

style.get()
style.set(style)

Gets/sets the current style as a graphicsStyle object allowing styles to be saved and restored arbitrarily

style.fill(<color>)
style.fill() r, g, b, a

Sets/gets the fill color for use in vector drawing operations

style.stroke(<color>)
style.stroke() r, g, b, a

Sets/gets the stroke color for use in vector drawing operations

style.tint(<color>)
style.tint() r, g, b, a

Sets/gets the tint color for use to tint calls to sprite() and mesh.draw()

style.strokeWidth(width)
style.stroke() number

Sets/gets the stroke width for use in vector drawing operations

style.lineCap(mode)
style.lineCap() enum

Sets/gets the current line cap mode, used by line, polyline and shape

  • ROUND

  • SQUARE

  • PROJECT

style.lineJoin(mode)
style.lineJoin() enum

Sets/gets the current line join mode, used by polyline, polygon and shape used when joining multiple line segments

  • ROUND

  • MITER

  • BEVEL

style.shapeMode(mode)
style.shapeMode() enum

Sets/gets the current shape mode, used by rect, ellipse and sprite

  • CENTER - Draw shapes from the center and size using width/height

  • CORNERS - Draw shapes by specifying the two opposite corners

  • CORNER - Draw shapes by specifying the bottom left corner and then width/height

  • RADIUS - Draw shapes by specifying center and radius

Constants - Shape Mode

CORNER: const
CORNERS: const
CENTER: const
RADIUS: const
style.sortOrder(order)

Blending Style

Functions

style.blend(mode)

Sets the current blend mode to one of the available presets. Blending composites pixels onto the current drawing context based on source and destination color and alpha values

The default mode is NORMAL which applies standard alpha blended transparency with the following equation:

\[RGBA = RGBA_{s} * A_{s} + RGBA_{d} * (1-A_{s})\]

DISABLED can be used to disable alpha blending entirely

style.blend(src, dst)

Sets a custom blend mode for both rgb and alpha components using src (source) and dst destination blending factors

style.blend(src, dst, srcAlpha, dstAlpha)

Sets a custom blend mode with separate blending factors for both rgb and alpha components

style.blend() src, dst, srcAlpha, dstAlpha

Returns the current blend factors for both rgb and alpha components (regardless of how the blend modes were set)

style.blendFunc(func)
style.blendFunc(func, alphaFunc)

Sets the current blend function (the default is EQUATION_ADD) which determines how source and destination parts of the blending equation are combined

  • EQUATION_ADD - Add (default)

    \(R = R_s*k_s+R_d*k_d\)

  • EQUATION_SUB - Subtract

    \(R = R_s*k_s-R_d*k_d\)

  • EQUATION_REVSUB - Reverse subtract

    \(R = R_d*k_d-R_s*k_s\)

  • EQUATION_MIN - Minimum (blend factors are ignored)

    \(R = min(R_s, R_d)\)

  • EQUATION_MAX - Maximum (blend factors are ignored)

    \(R = max(R_s, R_d)\)

style.blendFunc() func, alphaFunc

Returns the current blend function for both rgb and alpha components (regardless of how the functions were set)

Constants - Blend Modes

NORMAL: const

The default blend mode (alpha blended transparency)

../_images/example_blendMode_NORMAL.png
ADDITIVE: const

Additive blend mode

../_images/example_blendMode_ADDITIVE.png
MULTIPLY: const

Multiply blend mode

../_images/example_blendMode_MULTIPLY.png
SCREEN: const

Screen blend mode

../_images/example_blendMode_SCREEN.png
LIGHTEN: const

Lighten blend mode

../_images/example_blendMode_LIGHTEN.png
LINEAR_BURN: const

Linear burn blend mode

../_images/example_blendMode_LINEAR_BURN.png
PREMULTIPLIED: const

Premultiplied blend mode

../_images/example_blendMode_PREMULTIPLIED.png
DISABLED: const

Disables blending

../_images/example_blendMode_DISABLED.png

Constants - Blend Functions

EQUATION_ADD: const

Combines source and destination pixels using addition

EQUATION_SUB: const

Combines source and destination pixels using subtraction

EQUATION_REVSUB: const

Combines source and destination pixels using subtraction in reverse order

EQUATION_MIN: const

Combines source and destination pixels by taking the minimum of each component (ignores blend factors)

EQUATION_MAX: const

Combines source and destination pixels by taking the maximum of each component (ignores blend factors)

Constants - Blend Factors

ZERO: const

Blend factor of \((0, 0, 0, 0)\)

ONE: const

Blend factor or \((1, 1, 1, 1)\)

SRC_COLOR: const

Blend factor of \((R_s, G_s, B_s, A_s)\)

ONE_MINUS_SRC_COLOR: const

Blend factor of \((1-R_s, 1-G_s, 1-B_s, 1-A_s)\)

SRC_ALPHA: const

Blend factor of \((A_s, A_s, A_s, A_s)\)

ONE_MINUS_SRC_ALPHA: const

Blend factor of \((1-A_s, 1-A_s, 1-A_s, 1-A_s)\)

DST_ALPHA: const

Blend factor of \((A_d, A_d, A_d, A_d)\)

ONE_MINUS_DST_ALPHA: const

Blend factor of \((1-A_d, 1-A_d, 1-A_d, 1-A_d)\)

DST_COLOR: const

Blend factor of \((R_d, G_d, B_d, A_d)\)

SRC_ALPHA_SATURATE: const

Blend factor of \((f, f, f, 1)\) where \(f = min(A_s, 1 - A_d)\)

Text Style

style.fontSize(size)
style.textAlign(align)

Constants - Text

LEFT: const
CENTER: const
RIGHT: const
TOP: const
MIDDLE: const
BOTTOM: const
BASELINE: const

Constants - Style

ROUND: const
SQUARE: const
PROJECT: const
MITER: const
BEVEL: const

Constants - Render Queues

BACKGROUND: const
OPAQUE: const
TRANSPARENT: const
OVERLAY: const

Constants - Color Mask

Used by shaders to control which color components are written to color buffers (i.e. images and the main context)

COLOR_MASK_NONE: const
COLOR_MASK_RED: const
COLOR_MASK_GREEN: const
COLOR_MASK_BLUE: const
COLOR_MASK_ALPHA: const
COLOR_MASK_RGB: const
COLOR_MASK_RGBA: const

Constants - Culling

Used by shaders / meshes to control which triangles are culled (based on winding order)

CULL_FACE_NONE: const
CULL_FACE_FRONT: const
CULL_FACE_BACK: const

Constants - Depth

Used by shaders to control depth rejection for opaque and translucent fragments

DEPTH_WRITE_ENABLED: const
DEPTH_WRITE_DISABLED: const
DEPTH_FUNC_NEVER: const
DEPTH_FUNC_LESS: const
DEPTH_FUNC_EQUAL: const
DEPTH_FUNC_LESS_EQUAL: const
DEPTH_FUNC_GREATER: const
DEPTH_FUNC_NOT_EQUAL: const
DEPTH_FUNC_GREATER_EQUAL: const