primitives¶
Primitive (line, rectangle and circle) patterns.
This module provides convenience functions for the generation of basic
pattern shapes. So far including lines, squares/rectangles and circle
rasters.
-- Draw some squares
local square_pattern = primitives.square(5) -- 5x5
local rectangle_pattern = primitives.square(3,5) -- 3x5
-- Draw a line
local line = primitives.line(cell.new(0,0), cell.new(10,10))
-- Draw a circle about (0,0) with radius 5
local circle = primitives.circle(5)
primitives.square¶
Generate a square pattern.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
number |
size in x |
y |
number? |
size in y (default y = x) |
Returns:
forma.pattern— square pattern of size{x, y}
primitives.line¶
Generate a line pattern. According to Bresenham's line algorithm.
Parameters:
| Name | Type | Description |
|---|---|---|
start |
forma.cell |
a cell denoting the start of the line |
finish |
forma.cell |
a cell denoting the end of the line |
Returns:
forma.pattern— a pattern consisting of a line betweenstartandfinish
primitives.quad_bezier¶
Draw a quadratic bezier curve.
Uses an algorithm from rosettacode.org.
This function returns both a pattern consisting of the drawn bezier curve,
and a list of points along the curve. This may be important in case the
curve back-tracks over existing cells, which cannot be represented in a
forma pattern. The full pattern consists of N of these points, joined
by bresenham line segments.
Parameters:
| Name | Type | Description |
|---|---|---|
start |
forma.cell |
a cell denoting the start of the curve |
control |
forma.cell |
a cell denoting the control point of the curve |
finish |
forma.cell |
a cell denoting the end of the curve |
N |
integer? |
number of line-segments to construct the curve with (default: 20) |
Returns:
forma.pattern— a pattern consisting of the bezier curveforma.cell[]— an ordered list of cells consisting of points along the curve
primitives.circle¶
Generate a circle pattern. Bresenham algorithm.
Parameters:
| Name | Type | Description |
|---|---|---|
r |
number |
the radius of the circle to be drawn |
Returns:
forma.pattern— circular pattern of radiusrand origin(0,0)