File draw.lua
Author:
Ciarán Eaton |
Copyright ©2010 Ciarán Eaton
Release: draw.lua, v1.1
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Functions
ArrowAt3v (xy1, length, bearing) | Draw an arrow pointing at a provided point. |
ArrowAt4f (x1, y1, length, bearing) | Draw an arrow pointing at a provided point. |
ArrowFrom3v (xy1, length, bearing) | Draw an arrow pointing from a provided point. |
ArrowFrom4f (x1, y1, length, bearing) | Draw an arrow pointing from a provided point. |
Circle2v (cxy, radius) | Draw a circle Uses a set number of segments. |
Circle3f (cx, cy, radius) | Draw a circle Uses a set number of segments. |
Circle3vi (cxy, radius, segments) | Draw a circle |
Circle4fi (cx, cy, radius, segments) | Draw a circle |
Clear () | Clears the whiteboard. |
Cross2v (cxy, radius) | Draw a cross |
Cross3f (cx, cy, radius) | Draw a cross |
Cross3v (cxy, radius, rotation) | Draw a cross |
Cross4f (cx, cy, radius, rotation) | Draw a cross |
EqTriangle2v (cxy, length) | Draw a equilateral triangle |
EqTriangle3f (cx, cy, length) | Draw a equilateral triangle |
EqTriangle3v (cxy, length, rotation, cx) | Draw a equilateral triangle. |
EqTriangle4f (cx, cy, length, rotation) | Draw a equilateral triangle. |
IsoTriangle3v (cxy, length, angle) | Draw an isosceles triangle. |
IsoTriangle4f (cx, cy, length, angle) | Draw an isosceles triangle. |
IsoTriangle4v (cxy, length, angle, rotation) | Draw an isosceles triangle. |
IsoTriangle5f (cx, cy, length, angle, rotation) | Draw an isosceles triangle. |
LineB3v (xy1, length, bearing) | Draw a line using a point and a bearing. |
LineB4f (x1, y1, length, bearing) | Draw a line using a point and a bearing. |
LineH2v (xy1, length) | Draw a horizontal line from a point. |
LineH3f (x1, y1, length) | Draw a horizontal line from a point. |
LineP2v (xy1, xy2) | Draw a line using two points. |
LineP4f (x1, y1, x2, y2) | Draw a line using two points. |
LineV2v (xy1, length) | Draw a vertical line from a point. |
LineV3f (x1, y1, length) | Draw a vertical line from a point. |
Quad2v (xy1, xy2) | Draw a quadrilateral using two points. |
Quad4f (x1, y1, x2, y2) | Draw a quadrilateral using two points. |
SemiCircle2v (xy1, radius) | Draw a semicircle. |
SemiCircle3f (x1, y1, radius) | Draw a semicircle. |
SemiCircle3v (xy1, radius, rotation) | Draw a semicircle. |
SemiCircle4f (x1, y1, radius, rotation) | Draw a semicircle. |
SemiCircle4vi (xy1, radius, rotation, segments) | Draw a semicircle. |
SemiCircle5fi (x1, y1, radius, rotation, segments) | Draw a semicircle. |
SetArrowHeadAngle (angle) | Set arrow head angle. |
SetArrowHeadRatio (ratio) | Set arrow head ratio. |
SetCircleSegments (segments) | Set circle segments. |
SetSemiCircleSegments (segments) | Set semicircle segments. |
SetYieldFreq (freq) | Set yield frequency. |
Square2v (cxy, length) | Draw a square |
Square3f (cx, cy, length) | Draw a square |
Square3v (cxy, length, rotation) | Draw a square |
Square4f (cx, cy, length, rotation) | Draw a square |
Teapot2v (cxy, size) | Draw a teapot. |
Teapot3f (cx, cy, size) | Draw a teapot. |
Teapot3v (cxy, size, rotation) | Draw a teapot. |
Teapot4f (cx, cy, size, rotation) | Draw a teapot. |
Triangle3v (xy1, xy2, xy3) | Draw a triangle using three points. |
Triangle6f (x1, y1, x2, y2, x3, y3) | Draw a triangle using three points. |
TrigRotate6f (cx, cy, coord, scale, sinv, cosv) | Trigonmetry to rotate point |
TrigTriangle (cx, cy, dx, dy, sinv, cosv) | Compute and draw a rotated triangle. |
Tables
default_options | Default options. |
teapot_data | Teapot data. |
Functions
- ArrowAt3v (xy1, length, bearing)
-
Draw an arrow pointing at a provided point.
Parameters:
-
xy1
: table with the x-y coords for arrow head -
length
: length of arrow from head to tail. -
bearing
: bearing arrow should point.
Usage:
draw.ArrowAt3v({0.0,0.0},10.0,math.pi*0.25)
See also:
-
- ArrowAt4f (x1, y1, length, bearing)
-
Draw an arrow pointing at a provided point.
Parameters:
-
x1
: x-coord of arrow head. -
y1
: y-coord of arrow head. -
length
: length of arrow from head to tail. -
bearing
: bearing arrow should point.
Usage:
draw.ArrowAt4f(0.0,0.0,10.0,math.pi*0.25)
See also:
-
- ArrowFrom3v (xy1, length, bearing)
-
Draw an arrow pointing from a provided point.
Parameters:
-
xy1
: x-y coord for arrow tail -
length
: length of arrow from head to tail. -
bearing
: bearing arrow should point.
Usage:
draw.ArrowFrom3v({15.0,0.0},10.0,math.pi*0.56)
See also:
-
- ArrowFrom4f (x1, y1, length, bearing)
-
Draw an arrow pointing from a provided point.
Parameters:
-
x1
: x-coord of arrow tail. -
y1
: y-coord of arrow tail. -
length
: length of arrow from head to tail. -
bearing
: bearing arrow should point.
Usage:
draw.ArrowFrom4f(15.0,0.0,10.0,math.pi*0.56)
See also:
-
- Circle2v (cxy, radius)
-
Draw a circle Uses a set number of segments.
Parameters:
-
cxy
: x-y coord of centre. -
radius
: length from centre to edge.
Usage:
draw.Circle2v({0.0,10.0},5.0)
See also:
-
- Circle3f (cx, cy, radius)
-
Draw a circle Uses a set number of segments.
Parameters:
-
cx
: x-coord of centre. -
cy
: y-coord of centre. -
radius
: length from centre to edge.
Usage:
draw.Circle3f(0.0,10.0,5.0)
See also:
-
- Circle3vi (cxy, radius, segments)
-
Draw a circle
Parameters:
-
cxy
: x-y coord of centre. -
radius
: length from centre to edge. -
segments
: number of segments to use.
Usage:
draw.Circle3vi({15.0,10.0},5.0,20)
See also:
-
- Circle4fi (cx, cy, radius, segments)
-
Draw a circle
Parameters:
-
cx
: x-coord of centre. -
cy
: y-coord of centre. -
radius
: length from centre to edge. -
segments
: number of segments to use.
Usage:
draw.Circle4fi(15.0,10.0,5.0,20)
See also:
-
- Clear ()
-
Clears the whiteboard.
Usage:
draw.Clear()
- Cross2v (cxy, radius)
-
Draw a cross
Parameters:
-
cxy
: x-y coord of centre. -
radius
: length from centre to edge.
Usage:
draw.Cross2v({0.0,25.0},5.0)
See also:
-
- Cross3f (cx, cy, radius)
-
Draw a cross
Parameters:
-
cx
: x-coord of centre. -
cy
: y-coord of centre. -
radius
: length from centre to edge.
Usage:
draw.Cross3f(0.0,25.0,5.0)
See also:
-
- Cross3v (cxy, radius, rotation)
-
Draw a cross
Parameters:
-
cxy
: x-y coord of centre. -
radius
: length from centre to edge. -
rotation
: amount to rotate in radians.
Usage:
draw.Cross3v({15.0,25.0},5.0,math.pi*0.5)
See also:
-
- Cross4f (cx, cy, radius, rotation)
-
Draw a cross
Parameters:
-
cx
: x-coord of centre. -
cy
: y-coord of centre. -
radius
: length from centre to edge. -
rotation
: amount to rotate in radians.
Usage:
draw.Cross4f(15.0,25.0,5.0,math.pi*0.5)
See also:
-
- EqTriangle2v (cxy, length)
-
Draw a equilateral triangle
Parameters:
-
cxy
: x-y coord of centre point. -
length
: length of an edge.
Usage:
draw.EqTriangle2v({0.0,100.0},10.0)
See also:
-
- EqTriangle3f (cx, cy, length)
-
Draw a equilateral triangle
Parameters:
-
cx
: x-coord of centre point. -
cy
: y-coord of centre point. -
length
: length of an edge.
Usage:
draw.EqTriangle3f(0.0,100.0,10.0)
See also:
-
- EqTriangle3v (cxy, length, rotation, cx)
-
Draw a equilateral triangle.
Parameters:
-
cxy
: -
length
: length of an edge. -
rotation
: amount to rotate in radians. -
cx
: x-y coord of centre point.
Usage:
draw.EqTriangle3v({15.0,100.0},10.0,math.pi*0.25)
See also:
-
- EqTriangle4f (cx, cy, length, rotation)
-
Draw a equilateral triangle.
Parameters:
-
cx
: x-coord of centre point. -
cy
: y-coord of centre point. -
length
: length of an edge. -
rotation
: amount to rotate in radians.
Usage:
draw.EqTriangle4f(15.0,100.0,10.0,math.pi*0.25)
See also:
-
- IsoTriangle3v (cxy, length, angle)
-
Draw an isosceles triangle.
Parameters:
-
cxy
: x-ycoord of centre point. -
length
: length of an edge. -
angle
: size of the top angle in radians.
Usage:
draw.IsoTriangle3v({30.0,100.0},10.0,math.pi*0.2)
See also:
-
- IsoTriangle4f (cx, cy, length, angle)
-
Draw an isosceles triangle.
Parameters:
-
cx
: x-coord of centre point. -
cy
: y-coord of centre point. -
length
: length of an edge. -
angle
: size of the top angle in radians.
Usage:
draw.IsoTriangle4f(30.0,100.0,10.0,math.pi*0.2)
See also:
-
- IsoTriangle4v (cxy, length, angle, rotation)
-
Draw an isosceles triangle.
Parameters:
-
cxy
: x-y coord of centre point. -
length
: length of an edge. -
angle
: size of the top angle in radians. -
rotation
: amount to rotate in radians.
Usage:
draw.IsoTriangle4v({50.0,100.0},10.0,math.pi*0.4,math.pi*0.15)
See also:
-
- IsoTriangle5f (cx, cy, length, angle, rotation)
-
Draw an isosceles triangle.
Parameters:
-
cx
: x-coord of centre point. -
cy
: y-coord of centre point. -
length
: length of an edge. -
angle
: size of the top angle in radians. -
rotation
: amount to rotate in radians.
Usage:
draw.IsoTriangle5f(50.0,100.0,10.0,math.pi*0.4,math.pi*0.15)
See also:
-
- LineB3v (xy1, length, bearing)
-
Draw a line using a point and a bearing.
Parameters:
-
xy1
: x-y coord for point. -
length
: length of line. -
bearing
: bearing of line in radians.
Usage:
draw.LineB3v({0.0,40.0},5.0,math.pi*0.25)
See also:
-
- LineB4f (x1, y1, length, bearing)
-
Draw a line using a point and a bearing.
Parameters:
-
x1
: x-coord of point. -
y1
: y-coord of point. -
length
: length of line. -
bearing
: bearing of line in radians.
Usage:
draw.LineB4f(0.0,40.0,5.0,math.pi*0.25)
See also:
-
- LineH2v (xy1, length)
-
Draw a horizontal line from a point.
Parameters:
-
xy1
: x-y coord for point. -
length
: length of line.
Usage:
draw.LineH2v({10.0,40.0},5.0)
See also:
-
- LineH3f (x1, y1, length)
-
Draw a horizontal line from a point.
Parameters:
-
x1
: x-coord of point. -
y1
: y-coord of point. -
length
: length of line.
Usage:
draw.LineH3f(10.0,40.0,5.0)
See also:
-
- LineP2v (xy1, xy2)
-
Draw a line using two points.
Parameters:
-
xy1
: x-y coord for first point. -
xy2
: x-y coord for second point.
Usage:
draw.LineP2v({20.0,40.0},{25.0,45.0})
See also:
-
- LineP4f (x1, y1, x2, y2)
-
Draw a line using two points.
Parameters:
-
x1
: x-coord of first point. -
y1
: y-coord of first point. -
x2
: x-coord of second point. -
y2
: y-coord of second point.
Usage:
draw.LineP4f(20.0,40.0,25.0,45.0)
See also:
-
- LineV2v (xy1, length)
-
Draw a vertical line from a point.
Parameters:
-
xy1
: table of x-y coord for point. -
length
: length of line.
Usage:
draw.LineV2v({30.0,40.0},5.0)
See also:
-
- LineV3f (x1, y1, length)
-
Draw a vertical line from a point.
Parameters:
-
x1
: x-coord of point. -
y1
: y-coord of point. -
length
: length of line.
Usage:
draw.LineV3f(30.0,40.0,5.0)
See also:
-
- Quad2v (xy1, xy2)
-
Draw a quadrilateral using two points.
Parameters:
-
xy1
: x-y coord of first point. -
xy2
: x-y coord of second point.
Usage:
draw.Quad2v({0.0,65.0},{20.0,75.0})
See also:
-
- Quad4f (x1, y1, x2, y2)
-
Draw a quadrilateral using two points.
Parameters:
-
x1
: x-coord of first point. -
y1
: y-coord of first point. -
x2
: x-coord of second point. -
y2
: y-coord of second point.
Usage:
draw.Quad4f(0.0,65.0,20.0,75.0)
See also:
-
- SemiCircle2v (xy1, radius)
-
Draw a semicircle. Uses a set number of segments.
Parameters:
-
xy1
: table of x-y coord for the mid-point along the straight edge. -
radius
: length from xy1 to curved edge.
Usage:
draw.SemiCircle2v({0.0,85.0},5.0)
See also:
-
- SemiCircle3f (x1, y1, radius)
-
Draw a semicircle. Uses a set number of segments.
Parameters:
-
x1
: x-coord for the mid-point along the straight edge. -
y1
: y-coord for the mid-point along the straight edge. -
radius
: length from x1,y1 to curved edge.
Usage:
draw.SemiCircle3f(0.0,55.0,5.0)
See also:
-
- SemiCircle3v (xy1, radius, rotation)
-
Draw a semicircle. Uses a set number of segments.
Parameters:
-
xy1
: x-y coord for the mid-point along the straight edge. -
radius
: length from xy1 to curved edge. -
rotation
: amount to rotate in radians.
Usage:
draw.SemiCircle3v({15.0,55.0},5.0,math.pi*0.25)
See also:
-
- SemiCircle4f (x1, y1, radius, rotation)
-
Draw a semicircle. Uses a set number of segments.
Parameters:
-
x1
: x-coord for the mid-point along the straight edge. -
y1
: y-coord for the mid-point along the straight edge. -
radius
: length from x1,y1 to curved edge. -
rotation
: amount to rotate in radians.
Usage:
draw.SemiCircle4f(15.0,55.0,5.0,math.pi*0.25)
See also:
-
- SemiCircle4vi (xy1, radius, rotation, segments)
-
Draw a semicircle.
Parameters:
-
xy1
: x-y coord for the mid-point along the straight edge. -
radius
: length from xy1 to curved edge. -
rotation
: amount to rotate in radians. -
segments
: number of segments to use.
Usage:
draw.SemiCircle4vi({30.0,55.0},5.0,math.pi,20)
See also:
-
- SemiCircle5fi (x1, y1, radius, rotation, segments)
-
Draw a semicircle.
Parameters:
-
x1
: x-coord for the mid-point along the straight edge. -
y1
: y-coord for the mid-point along the straight edge. -
radius
: length from x1,y1 to curved edge. -
rotation
: amount to rotate in radians. -
segments
: number of segments to use.
Usage:
draw.SemiCircle5fi(30.0,55.0,5.0,math.pi,20)
See also:
-
- SetArrowHeadAngle (angle)
-
Set arrow head angle.
Parameters:
-
angle
:
See also:
-
- SetArrowHeadRatio (ratio)
-
Set arrow head ratio.
Parameters:
-
ratio
:
See also:
-
- SetCircleSegments (segments)
-
Set circle segments.
Parameters:
-
segments
:
See also:
-
- SetSemiCircleSegments (segments)
-
Set semicircle segments.
Parameters:
-
segments
:
See also:
-
- SetYieldFreq (freq)
-
Set yield frequency.
Parameters:
-
freq
:
See also:
-
- Square2v (cxy, length)
-
Draw a square
Parameters:
-
cxy
: x-y coord of centre point. -
length
: length of an edge.
Usage:
draw.Square2v({0.0,85.0},5.0)
See also:
-
- Square3f (cx, cy, length)
-
Draw a square
Parameters:
-
cx
: x-coord of centre point. -
cy
: y-coord of centre point. -
length
: length of an edge.
Usage:
draw.Square3f(0.0,85.0,5.0)
See also:
-
- Square3v (cxy, length, rotation)
-
Draw a square
Parameters:
-
cxy
: x-y coord of centre point. -
length
: length of a side. -
rotation
: amount to rotate in radians.
Usage:
draw.Square3v({15.0,85.0},10.0,math.pi*0.25)
See also:
-
- Square4f (cx, cy, length, rotation)
-
Draw a square
Parameters:
-
cx
: x-coord of centre point. -
cy
: y-coord of centre point. -
length
: length of a side. -
rotation
: amount to rotate in radians.
Usage:
draw.Square4f(15.0,85.0,10.0,math.pi*0.25)
See also:
-
- Teapot2v (cxy, size)
-
Draw a teapot.
Parameters:
-
cxy
: x-y coord of centre point. -
size
: scale of teapot.
Usage:
draw.Teapot2v({0.0,-15.0},15.0)
See also:
-
- Teapot3f (cx, cy, size)
-
Draw a teapot.
Parameters:
-
cx
: x-coord of centre point. -
cy
: y-coord of centre point. -
size
: scale of teapot.
Usage:
draw.Teapot3f(0.0,-15.0,15.0)
See also:
-
- Teapot3v (cxy, size, rotation)
-
Draw a teapot.
Parameters:
-
cxy
: x-y coord of centre point. -
size
: scale of teapot. -
rotation
: amount of rotation in radians.
Usage:
draw.Teapot3v({15.0,-15.0},7.0,math.pi*-0.25)
See also:
-
- Teapot4f (cx, cy, size, rotation)
-
Draw a teapot.
Parameters:
-
cx
: x-coord of centre point. -
cy
: y-coord of centre point. -
size
: scale of teapot. -
rotation
: amount of rotation in radians.
Usage:
draw.IsoTriangle4f(30.0,100.0,10.0,math.pi*0.2)
See also:
-
- Triangle3v (xy1, xy2, xy3)
-
Draw a triangle using three points.
Parameters:
-
xy1
: x-y coord of first point. -
xy2
: x-y coord of second point. -
xy3
: x-y coord of third point.
Usage:
draw.Teapot3v({15.0,-15.0},7.0,math.pi*-0.25)
See also:
-
- Triangle6f (x1, y1, x2, y2, x3, y3)
-
Draw a triangle using three points.
Parameters:
-
x1
: x-coord of first point. -
y1
: y-coord of first point. -
x2
: x-coord of second point. -
y2
: y-coord of second point. -
x3
: x-coord of third point. -
y3
: y-coord of third point.
Usage:
draw.Triangle6f(65.0,100.0,65.0,110.0,90.0,100.0)
See also:
-
- TrigRotate6f (cx, cy, coord, scale, sinv, cosv)
-
Trigonmetry to rotate point
Parameters:
-
cx
: x-coord to rotate around. -
cy
: y-coord to rotate around. -
coord
: point to be rotated. -
scale
: scale point/length. Use 1.0 to not scale. -
sinv
: sin value for angle of rotation i.e. sin(angle) -
cosv
: cos value for angle of rotation i.e. cos(angle)
-
- TrigTriangle (cx, cy, dx, dy, sinv, cosv)
-
Compute and draw a rotated triangle.
Parameters:
-
cx
: x-coord of centre. -
cy
: y-coord of centre. -
dx
: length from centre to x-most point. -
dy
: length from centre to y-most point. -
sinv
: sin value for angle of rotation i.e. sin(angle). -
cosv
: cos value for angle of rotation i.e. cos(angle).
-
Tables
- default_options
- Default options.
Fields:
-
yield_frequency
: Determines how many iterations of a loop should be executed before yielding. Set to -1 to never yield in a loop. -
arrow_head_ratio
: Ratio of arrow head compared to its length. -
arrow_head_angle
: Determines how pointy arrow is in radians. -
circle_segments
: Numbers of segments to draw for a circle. Minimum 5. -
semicircle_segments
: Numbers of segments to draw for a semicircle. Minimum 5.
-
- teapot_data
- Teapot data. Data used to describe the points of the teapot