Module forma.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.

Usage:

    -- 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)
    

Geometry primitives

square (x, y) Generate a square pattern.
line (start, finish) Generate a line pattern.
quad_bezier (start, control, finish, N) Draw a quadratic bezier curve.
circle (r) Generate a circle pattern.


Geometry primitives

square (x, y)
Generate a square pattern.

Parameters:

  • x size in x
  • y size in y (default y = x)

Returns:

    square forma.pattern of size {x,y}
line (start, finish)
Generate a line pattern. According to Bresenham's line algorithm.

Parameters:

  • start a forma.cell denoting the start of the line
  • finish a forma.cell denoting the end of the line

Returns:

    a pattern consisting of a line between start and finish
quad_bezier (start, control, finish, N)
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:

  • start a forma.cell denoting the start of the curve
  • control a forma.cell denoting the control point of the curve
  • finish a forma.cell denoting the end of the curve
  • N (optional) number of line-segments to construct the curve with

Returns:

  1. a pattern consisting of a bezier curve between start and finish, controlled by control
  2. an ordered list of cells consisting of points along the curve.
circle (r)
Generate a circle pattern. Bresenham algorithm.

Parameters:

  • r the radius of the circle to be drawn

Returns:

    circular forma.pattern of radius r and origin (0,0)
generated by LDoc 1.4.6 Last updated 2019-01-07 21:10:29