Root class of RAC. All drawable, style, control, and drawer classes are contained in this class.
An instance must be created with new Rac()
in order to
build drawable, style, and other objects.
To perform drawing operations, a drawer must be setup with
setupDrawer
. Currently the only available
implementation is P5Drawer
.
Constructor
new Rac()
Creates a new instance of Rac. The new instance has no drawer
setup.
Classes
- Angle
- Arc
- ArcControl
- Bezier
- Color
- Composite
- Control
- Controller
- Exception
- Fill
- P5Drawer
- Point
- Ray
- RayControl
- Segment
- Shape
- Stroke
- StyleContainer
- Text
Members
(static, constant) build :String
Build of the class. Intended for debugging purpouses.
Contains a commit-count and short-hash of the repository when the build was done.
Example
Rac.build // returns as example '1057-94b059d'
(static, constant) dated :String
Date of the build of the class. Intended for debugging purpouses.
Contains a ISO-8601 standard date when the build was done.
Example
Rac.dated // returns as example '2022-10-13T23:06:12.500Z'
(static, constant) TAU :Number
Tau, equal to Math.PI * 2
.
See Tau Manifesto.
(static, constant) utils :utils
Container of utility functions. See utils
for the available
members.
Also available through Rac#utils
.
(static, constant) version :String
Version of the class. Same as the version used for the npm package.
Example
Rac.version // returns as example '1.2.1'
(constant) build :String
Build of the instance, same as Rac.build
.
Example
rac.build // returns as example '1057-94b059d'
controller
Controller of the instance. This objecs handles all of the controls
and pointer events related to this instance of Rac
.
(constant) dated :String
Date of the build of the instance, same as Rac.dated
.
Example
rac.dated // returns as example '2022-10-13T23:06:12.500Z'
(nullable) drawer :Object
Drawer of the instance. This object handles the drawing for all
drawable object created using this
.
- Default Value:
-
null
-
equalityThreshold :Number
Value used to determine equality between two numeric values. Used for
values that tend to be integers, like screen coordinates. Used by
Rac#equals
.
When checking for equality x
is equal to non-inclusive
(x-equalityThreshold, x+equalityThreshold)
:
x
is not equal tox ± equalityThreshold
x
is equal tox ± equalityThreshold/2
Due to floating point precision some opertation like intersections can return odd or oscilating values. This threshold is used to snap values too close to a limit, as to prevent oscilating efects in user interaction.
The default value is based on 1/1000
of a point.
- Default Value:
-
0.001
-
textFormatDefaults :Object
Defaults for the optional properties of
Text.Format
.
When a Text
is draw which
format.font
or
format.size
are set to null
, the
values set here are used instead.
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
font |
String
|
<nullable> |
null
|
Default font, used when drawing a |
size |
Number
|
15
|
Default size, used when drawing a |
unitaryEqualityThreshold :Number
Value used to determine equality between two unitary numeric values.
Used for values that tend to exist in the [0, 1]
range, like
Rac.Angle#turn
. Used by Rac#unitaryEquals
.
Equality logic is the same as Rac#equalityThreshold
.
The default value is based on 1/1000 of the turn of an complete circle arc of radius 500:
1/(500*6.28)/1000 = 0.000_000_318471338
- Default Value:
-
0.000_000_3
-
utils :utils
Container of utility functions. See utils
for the available
members.
Also available through Rac.utils
.
(constant) version :String
Version of the instance, same as Rac.version
.
Example
rac.version // returns as example '1.2.1'
Methods
(static) setupDrawableProtoFunctions(drawableClass)
Adds to drawableClass.prototype
all the functions contained in
Rac.drawableProtoFunctions
. These are the functions shared by all
drawable objects, for example draw()
and debug()
.
Parameters:
Name | Type | Description |
---|---|---|
drawableClass |
class
|
Class to setup with drawable functions |
Angle(turn) → {Rac.Angle}
Convenience function to create a new Angle
. The created angle.rac
is setup with this
.
The function also contains additional methods and properties listed in
instance.Angle
.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
turn |
Number
|
The turn value of the angle, in the range |
Example
let rac = new Rac()
let angle = rac.Angle(1/2)
angle.rac === rac // true
Arc(x, y, start, endopt, clockwiseopt) → {Rac.Arc}
Convenience function to create a new Arc
with the given primitive
values. The created arc.rac
is setup with this
.
The function also contains additional methods and properties listed in
instance.Arc
.
- See also:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
Number
|
The x coordinate for the arc center |
||
y |
Number
|
The y coordinate for the arc center |
||
start |
Rac.Angle
|
Number
|
The start of the arc |
||
end |
Rac.Angle
|
Number
|
<optional> |
null
|
The end of the arc; when
ommited or set to |
clockwise |
Boolean
|
<optional> |
true
|
The orientation of the arc |
Example
let rac = new Rac()
let arc = rac.Arc(55, 77, 1/4)
arc.rac === rac // true
Bezier(startX, startY, startAnchorX, startAnchorY, endAnchorX, endAnchorY, endX, endY) → {Rac.Bezier}
Convenience function that creates a new Bezier
setup with this
.
The function also contains additional methods and properties listed in
instance.Bezier
.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
startX |
Number
|
|
startY |
Number
|
|
startAnchorX |
Number
|
|
startAnchorY |
Number
|
|
endAnchorX |
Number
|
|
endAnchorY |
Number
|
|
endX |
Number
|
|
endY |
Number
|
Color(r, g, b, aopt) → {Rac.Color}
Convenience function to create a new Color
. The created color.rac
is setup with this
.
The function also contains additional methods and properties listed in
instance.Color
.
- See also:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
r |
Number
|
|||
g |
Number
|
|||
b |
Number
|
|||
a |
Number
|
<optional> |
1
|
Example
let rac = new Rac()
let color = rac.Color(0.2, 0.4, 0.6)
color.rac === rac // true
equals(a, b) → {Boolean}
Returns true
if the absolute distance between a
and b
is
under Rac#equalityThreshold
.
Parameters:
Name | Type | Description |
---|---|---|
a |
Number
|
First number to compare |
b |
Number
|
Second number to compare |
Fill(coloropt) → {Rac.Fill}
Convenience function to create a new Fill
. The created fill.rac
is
setup with this
.
The function also contains additional methods and properties listed in
instance.Fill
.
- See also:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
color |
Rac.Color
|
<optional> |
null
|
Example
let rac = new Rac()
let color = rac.Color(0.2, 0.4, 0.6)
let fill = rac.Fill(color)
fill.rac === rac // true
Point(x, y) → {Rac.Point}
Convenience function to create a new Point
. The created point.rac
is setup with this
.
The function also contains additional methods and properties listed in
instance.Point
.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
x |
Number
|
The x coordinate |
y |
Number
|
The y coordinate |
Example
let rac = new Rac()
let point = rac.Point(55, 77)
point.rac === rac // true
Ray(x, y, angle) → {Rac.Ray}
Convenience function to create a new Ray
with the given primitive
values. The created ray.rac
is setup with this
.
The function also contains additional methods and properties listed in
instance.Ray
.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
x |
Number
|
|
y |
Number
|
|
angle |
Rac.Angle
|
Number
|
Example
let rac = new Rac()
let ray = rac.Ray(55, 77, 1/2)
ray.rac === rac // true
Segment(x, y, angle, length) → {Rac.Segment}
Convenience function to create a new Segment
with the given primitive
values. The created segment.rac
is setup with this
.
The function also contains additional methods and properties listed in
instance.Segment
.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
x |
Number
|
|
y |
Number
|
|
angle |
Rac.Angle
|
Number
|
|
length |
Number
|
Example
let rac = new Rac()
let segment = rac.Segment(55, 77, 1/2, 100)
segment.rac === rac // true
setupDrawer(p5Instance)
Sets the drawer for the instance. Currently only a p5.js instance is supported.
The drawer will also populate some classes with prototype functions
relevant to the drawer. For p5.js this include apply
functions for
colors and style object, and vertex
functions for drawable objects.
Parameters:
Name | Type | Description |
---|---|---|
p5Instance |
P5
|
Stroke(weightnullable, coloropt) → {Rac.Stroke}
Convenience function to create a new Stroke
. The created stroke.rac
is setup with this
.
The function also contains additional methods and properties listed in
instance.Stroke
.
- See also:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
weight |
Number
|
<nullable> |
||
color |
Rac.Color
|
<optional> |
null
|
Example
let rac = new Rac()
let color = rac.Color(0.2, 0.4, 0.6)
let stroke = rac.Stroke(2, color)
stroke.rac === rac // true
Style(strokeopt, fillopt) → {Rac.Style}
Convenience function to create a new Style
. The created style.rac
is setup with this
.
The function also contains additional methods and properties listed in
instance.Style
.
- See also:
-
- instance.Style
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
stroke |
Rac.Stroke
|
<optional> |
null
|
|
fill |
Rac.Fill
|
<optional> |
null
|
Example
let rac = new Rac()
let color = rac.Color(0.2, 0.4, 0.6)
let style = rac.Style(rac.Stroke(2, color), rac.Fill(color))
style.rac === rac // true
Text(x, y, string, formatopt) → {Rac.Text}
Convenience function to create a new Text
. The created text.rac
is
setup with this
.
The function also contains additional methods and properties listed in
instance.Text
.
- See also:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
Number
|
The x coordinate location for the drawn text |
||
y |
Number
|
The y coordinate location for the drawn text |
||
string |
String
|
The string to draw |
||
format |
Rac.Text.Format
|
<optional> |
rac.Text.Format.topLeft
|
The format for the drawn text |
Example
let rac = new Rac()
let text = rac.Text(55, 77, "black quartz")
text.rac === rac // true
TextFormat(hAlign, vAlign, angleopt, fontopt, sizeopt) → {Rac.Text.Format}
Convenience function to create a new Text.Format
. The created
format.rac
is setup with this
.
The function also contains additional methods and properties listed in
instance.Text.Format
.
rac.Text.Format
is an alias of this
function.
- See also:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
hAlign |
String
|
The horizontal alignment, left-to-right; one
of the values from |
||
vAlign |
String
|
The vertical alignment, top-to-bottom; one of
the values from |
||
angle |
Rac.Angle
|
<optional> |
rac.Angle.zero
|
The angle towards which the text is drawn |
font |
String
|
<optional> |
null
|
The font name |
size |
Number
|
<optional> |
null
|
The font size |
Example
let rac = new Rac()
let format = rac.Text.Format('left', 'baseline', 1/8)
format.rac === rac // true
unitaryEquals(a, b) → {Boolean}
Returns true
if the absolute distance between a
and b
is
under Rac#unitaryEqualityThreshold
.
Parameters:
Name | Type | Description |
---|---|---|
a |
Number
|
First number to compare |
b |
Number
|
Second number to compare |