Skip to content

FxPixelLayer ​

This module contains functions for PixelLayer nodes.

INFO

Source grids and pixels define the data on which the functions of this module operate.

A source node is any PixelLayer node identified by the given NodeID.

A source grid is the pixel grid of a source node.

The source pixels are all pixels of the source grid, unless the NodeID wildcard /a is used and the active node is a PixelLayer whose grid has selected pixels. In this case, only the selected pixels are the source pixels.

Load ​

lua
FxPixelLayer = require "FxPixelLayer";

Functions ​

FunctionDescription
AdjustHeight (NodeID, Offset)Adds an offset to the height of pixels.
AssignHeight (NodeID, Value)Sets the height of pixels.
BrightnessContrast (NodeID, Brightness, Contrast)Roughly adjusts brightness and contrast.
Clear (NodeID)Deletes all pixels.
ColorOverlay (NodeID, Color, Opacity)Blends the color of pixels with another color.
Crop (NodeID, X, Y, Width, Height)Crops a pixel grid.
Desaturate (NodeID)Roughly desaturates pixel.
Detach (NodeID)Moves selected pixels to a new layer.
Fill (NodeID, Pixel)Sets all solid pixels.
FillColor (NodeID, Color)Sets the color of pixels.
FillMaterial (NodeID, Material)Sets the material of pixels.
Flip (NodeID, Horizontally)Flips a pixel grid.
HueSaturation (NodeID, Hue, Saturation, Lightness)Roughly adjusts hue, saturation and lightness.
InvertColors (NodeID)Roughly inverts colors.
Merge (NodeID1, NodeID2)Merges two pixel layers.
Mirror (NodeID, Direction)Mirrors a pixel grid.
OptimizeSize (NodeID)Crops empty areas.
ReduceColors (NodeID, ColorCount)Reduces the number of distinct colors used in the pixel grid.
ReplaceColor (NodeID, Color, ReplacementColor)Replaces colors of pixels.
ReplaceMaterial (NodeID, Material, ReplacementMaterial)Replaces materials of pixels.
Resize (NodeID, X, Y, AnchorX, AnchorY)Resizes a pixel grid.
Rotate (NodeID, Angle)Rotates a pixel grid arbitrarily.
Rotate90 (NodeID, Steps)Rotates a pixel grid in 90° steps.
Scale (NodeID, X, Y)Scales a pixel grid.
ScaleToFit (NodeID, X, Y, AnchorX, AnchorY)Resizes a pixel grid and scales its content to fit the new size.
Shear (NodeID, ShearFactorX, ShearFactorY)Skews a pixel grid.
WrapAround (NodeID, X, Y)Offsets pixels. Pixels pushed out are moved to the opposite side.

AdjustHeight (NodeID, Offset) ​

This function adds the specified offset to the height of all source pixels.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.AdjustHeight("layer1", 2);

AssignHeight (NodeID, Value) ​

This function sets the height of all source pixels to the specified value.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.AssignHeight("layer1", 20);

BrightnessContrast (NodeID, Brightness, Contrast) ​

This function roughly adjusts the brightness and contrast of the source grid. For each source pixel the adjusted color is calculated, then the index color that best matches the calculated color is determined and assigned to the pixel.

Parameters ​

  • NodeID: The NodeID to identify the source nodes
  • Brightness: The brightness shift, clamped to [-1.0, 1.0]
  • Contrast: The contrast shift, clamped to [-1.0, 1.0]

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
-- shift brightness by 0.5
FxPixelLayer.BrightnessContrast("layer1", 0.5, 0);

Clear (NodeID) ​

This function deletes all source pixels.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Clear("layer1");

ColorOverlay (NodeID, Color, Opacity) ​

This function roughly blends the source grid with a color and opacity. For each source pixel, the adjusted color is calculated, then the index color that best matches the calculated color is determined and assigned to the pixel.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID

Since ​

Version 1.0

Example ​

lua
color = FxColor.CreateFromHex("ff00ff");
FxPixelLayer.ColorOverlay("layer1", color, 0.5);

Crop (NodeID, X, Y, Width, Height) ​

This function cuts off areas of the source grid outside of the specified area.

Parameters ​

  • NodeID: The NodeID to identify the source nodes
  • X: The X coordinate of the area position
  • Y: The Y coordinate of the area position
  • Width: The area width
  • Height: The area height

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Crop("layer1", 5, 5, 10, 10);

Desaturate (NodeID) ​

This function roughly reduces the saturation of the source grid to 0.0. For each source pixel the adjusted color is calculated, then the index color that best matches the calculated color is determined and assigned to the pixel.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Desaturate("layer1");

Detach (NodeID) ​

This function moves all selected pixels from the source grid to a new PixelLayer node.

Parameters ​

  • NodeID: The NodeID of the PixelLayer node

Returns ​

The NodeID of the new PixelLayer

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Detach("layer1");

Fill (NodeID, Pixel) ​

This function replaces all solid source pixels with the specified pixel.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID

Since ​

Version 1.0

Example ​

lua
pixel = FxPixel.Create(0, 0);
FxPixelLayer.Fill("layer1", pixel);

FillColor (NodeID, Color) ​

This function assigns the given color to all source pixels.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_ITEM_INDEX_INVALID

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.FillColor("layer1", 10);

FillMaterial (NodeID, Material) ​

This function applies the given material to all source pixels.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_ITEM_INDEX_INVALID

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.FillMaterial("layer1", 1);

Flip (NodeID, Horizontally) ​

This function flips the source grid.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
-- flip vertically
FxPixelLayer.Flip("layer1", false);

HueSaturation (NodeID, Hue, Saturation, Lightness) ​

This function roughly adjusts the hue, saturation, and lightness of the source grid. For each source pixel, the adjusted color is calculated, then the index color that best matches the calculated color is determined and assigned to the pixel.

Parameters ​

  • NodeID: The NodeID to identify the source nodes
  • Hue: The hue shift, clamped to [-1.0, 1.0]
  • Saturation: The saturation shift, clamped to [-1.0, 1.0]
  • Lightness: The lightness shift, clamped to [-1.0, 1.0]

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.HueSaturation("layer1", -0.2, -0.5, 0);

InvertColors (NodeID) ​

This function roughly inverts the colors of the source grid. For each source pixel the adjusted color is calculated, then the index color that best matches the calculated color is determined and assigned to the pixel.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.InvertColors("layer1");

Merge (NodeID1, NodeID2) ​

This function merges the two grids of the given nodes and deletes the second node.

Parameters ​

  • NodeID1: The NodeID of the first PixelLayer node
  • NodeID2: The NodeID of the second PixelLayer node

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Merge("layer1", "layer2");

Mirror (NodeID, Direction) ​

This function mirrors one half of the source grid to the other depending on the given direction.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Mirror("layer1", 1);

OptimizeSize (NodeID) ​

This function cuts the surrounding empty areas from the source grid.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.OptimizeSize("layer1");

ReduceColors (NodeID, ColorCount) ​

This function reduces the number of colors used in the specified source pixels.

Parameters ​

Errors ​

Possible errors include: FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID.

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.ReduceColors("layer1", 10);

ReplaceMaterial (NodeID, Material, ReplacementMaterial) ​

This function assigns the specified new material to all source pixels that have Material assigned.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_ITEM_INDEX_INVALID

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.ReplaceMaterial("layer1", 0, 1);

ReplaceColor (NodeID, Color, ReplacementColor) ​

This function assigns the specified new color to all source pixels that have Color assigned.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_ITEM_INDEX_INVALID

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.ReplaceColor("layer1", 0, 1);

Resize (NodeID, X, Y, AnchorX, AnchorY) ​

This function resizes the source grid from given anchors and optionally resamples its contents.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Resize("layer1", 20, 30, 0, 0);

Rotate (NodeID, Angle) ​

This function rotates the source grid arbitrarily.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Rotate("layer1", 45);

Rotate90 (NodeID, Steps) ​

This function rotates the source grid by the specified number of 90° steps.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Rotate90("layer1", 1);

Scale (NodeID, X, Y) ​

This function scales the source grid.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Scale("layer1", 0.25, 0.25);

ScaleToFit (NodeID, X, Y, AnchorX, AnchorY) ​

This function resizes the source grid from given anchors and scales its content to fit the new size.

Parameters ​

  • NodeID: The NodeID to identify the source nodes
  • X: The new voxel grid width
  • Y: The new voxel grid height
  • AnchorX: The X-axis Anchor
  • AnchorY: The Y-axis Anchor

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.ScaleToFit("layer1", 20, 30, 0, 0);

Shear (NodeID, ShearFactorX, ShearFactorY) ​

This function skews the source grid by the specified factors.

Parameters ​

  • NodeID: The NodeID to identify the source nodes
  • ShearFactorX: The Shear factor for the X-axis
  • ShearFactorY: The Shear factor for the Y-axis

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.Shear("layer1", 1.0, 2.0);

WrapAround (NodeID, X, Y) ​

This function offsets the grid position of source pixels. The pixels that are pushed out are moved to the opposite side.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxPixelLayer.WrapAround("layer1", 0, 10);