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()
andmesh.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
andshape
ROUND
SQUARE
PROJECT
- style.lineJoin(mode)¶
- style.lineJoin() enum
Sets/gets the current line join mode, used by
polyline
,polygon
andshape
used when joining multiple line segmentsROUND
MITER
BEVEL
- style.shapeMode(mode)¶
- style.shapeMode() enum
Sets/gets the current shape mode, used by
rect
,ellipse
andsprite
CENTER
- Draw shapes from the center and size using width/heightCORNERS
- Draw shapes by specifying the two opposite cornersCORNER
- Draw shapes by specifying the bottom left corner and then width/heightRADIUS
- Draw shapes by specifying center and radius
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) anddst
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 combinedEQUATION_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)
- ADDITIVE: const¶
Additive blend mode
- MULTIPLY: const¶
Multiply blend mode
- SCREEN: const¶
Screen blend mode
- LIGHTEN: const¶
Lighten blend mode
- LINEAR_BURN: const¶
Linear burn blend mode
- PREMULTIPLIED: const¶
Premultiplied blend mode
- DISABLED: const¶
Disables blending
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)\)
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¶