Rac

# | source: src/Rac.js, line 22

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

# | source: src/Rac.js, line 22

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

# | source: src/Rac.js, line 331

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 E.g. '1057-94b059d'

(static, constant) dated :String

# | source: src/Rac.js, line 347

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 E.g. '2022-10-13T23:06:12.500Z'

(static, constant) TAU :Number

# | source: src/Rac.js, line 362

Tau, equal to Math.PI * 2.

See Tau Manifesto.

(static, constant) utils :utils

# | source: src/Rac.js, line 315

Container of utility functions. See the utils namespace for the available members.

Also available through rac.utils.

(static, constant) version :String

# | source: src/Rac.js, line 319

Version of the class. Equivalent to the version used for the npm package.

Example
Rac.version // returns E.g. '1.2.1'

(constant) build :String

# | source: src/Rac.js, line 41

Build of the instance, equivalent to Rac.build.

Example
rac.build // returns E.g. '1057-94b059d'

controller

# | source: src/Rac.js, line 179

Controller of the instance. This objecs handles all of the controls and pointer events related to this instance of Rac.

(constant) dated :String

# | source: src/Rac.js, line 53

Date of the build of the instance, equivalent to Rac.dated.

Example
rac.dated // returns E.g. '2022-10-13T23:06:12.500Z'

(nullable) drawer :Object

# | source: src/Rac.js, line 155

Drawer of the instance. This object handles the drawing for all drawable object created using this.

Default Value:
  • null

equalityThreshold :Number

# | source: src/Rac.js, line 85

Value used to determine equality between two numeric values. Used for values that tend to be integers, like screen coordinates. Used by equals.

When checking for equality x is equal to non-inclusive (x-equalityThreshold, x+equalityThreshold):

  • x is not equal to x ± equalityThreshold
  • x is equal to x ± 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

# | source: src/Rac.js, line 143

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 Text which format.font is set to null; when set to null the font is not set upon drawing

size Number 15

Default size, used when drawing a Text which format.size is set to null

unitaryEqualityThreshold :Number

# | source: src/Rac.js, line 106

Value used to determine equality between two unitary numeric values. Used for values that tend to exist in the [0, 1] range, like angle.turn. Used by unitaryEquals.

Equality logic is the same as 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

# | source: src/Rac.js, line 117

Container of utility functions. See the utils namespace for the available members.

Also available through Rac.utils.

(constant) version :String

# | source: src/Rac.js, line 29

Version of the instance, equivalent to Rac.version.

Example
rac.version // returns E.g. '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.

Parameters:
Name Type Description
turn Number

The turn value of the angle, in the range [O,1)

Example
let rac = new Rac()
let angle = rac.Angle(0.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.

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 null, start is used instead

clockwise Boolean <optional>
true

The orientation of the arc

Example
let rac = new Rac()
let arc = rac.Arc(55, 77, 0.2)
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.

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.

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

Composite(sequence) → {Rac.Composite}

Convenience function to create a new Composite. The created composite.rac is setup with this.

Parameters:
Name Type Description
sequence Array

An array of drawable objects to contain

Example
let rac = new Rac()
let composite = rac.Composite()
composite.rac === rac // true

equals(a, b) → {Boolean}

# | source: src/Rac.js, line 207

Returns true if the absolute distance between a and b is under 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.

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.

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.

Parameters:
Name Type Description
x Number
y Number
angle Rac.Angle | Number
Example
let rac = new Rac()
let ray = rac.Ray(55, 77, 0.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.

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, 0.2, 100)
segment.rac === rac // true

setupDrawer(p5Instance)

# | source: src/Rac.js, line 193

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.

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.

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.

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, hPaddingopt, vPaddingopt) → {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.

Parameters:
Name Type Attributes Default Description
hAlign String

The horizontal alignment, left-to-right; one of the values from horizontalAlign

vAlign String

The vertical alignment, top-to-bottom; one of the values from verticalAlign

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

hPadding Number <optional>
0

The horizontal padding, left-to-right

vPadding Number <optional>
0

The vertical padding, top-to-bottom

Example
let rac = new Rac()
let format = rac.Text.Format('left', 'baseline', 0.2)
format.rac === rac // true

unitaryEquals(a, b) → {Boolean}

# | source: src/Rac.js, line 223

Returns true if the absolute distance between a and b is under unitaryEqualityThreshold.

Parameters:
Name Type Description
a Number

First number to compare

b Number

Second number to compare