Rac

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: Rac.js, line 20

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: Rac.js, line 304

Build of the class. Intended for debugging purpouses.

Contains a commit-count and short-hash of the repository when the build was done.

E.g. 904-011be8f.

(static, constant) TAU :number

# | source: Rac.js, line 318

Tau, equal to Math.PI * 2.

Tau Manifesto.

(static, constant) utils :utils

# | source: Rac.js, line 289

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

Also available through Rac#utils.

(static, constant) version :string

# | source: Rac.js, line 293

Version of the class. Same as the version used for the npm package.

E.g. 1.2.0.

(constant) build :string

# | source: Rac.js, line 38

Build of the instance, same as Rac.build.

E.g. 904-011be8f.

controller

# | source: Rac.js, line 154

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

drawer :object

# | source: Rac.js, line 133

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

equalityThreshold :number

# | source: Rac.js, line 68

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

Default value is based on 1/1000 of a point.

textFormatDefaults :object

# | source: Rac.js, line 122

Defaults for the optional properties of Text.Format.

When a Text is draw which format.font or format.size is 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: Rac.js, line 83

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.

Default value is based on 1/1000 of the turn of an arc of radius 500 and length of 1: 1/(500*6.28)/1000

utils :utils

# | source: Rac.js, line 94

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

Also available through Rac.utils.

(constant) version :string

# | source: Rac.js, line 27

Version of the instance, same as Rac.version.

E.g. 1.2.0.

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 that creates a new Angle setup with this.

The function also contains additional methods and properties listed in instance.Angle.

See:
Parameters:
Name Type Description
turn number

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

Arc(x, y, start, endopt, clockwiseopt) → {Rac.Arc}

Convenience function that creates a new Arc setup with this.

The function also contains additional methods and properties listed in instance.Arc.

See:
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

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:
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 that creates a new Color setup with this.

The function also contains additional methods and properties listed in instance.Color.

See:
Parameters:
Name Type Attributes Description
r number
g number
b number
a number <optional>

equals(a, b) → {boolean}

# | source: Rac.js, line 181

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 that creates a new Fill setup with this.

The function also contains additional methods and properties listed in instance.Fill.

See:
Parameters:
Name Type Attributes Description
color Rac.Color <optional>

Point(x, y) → {Rac.Point}

Convenience function that creates a new Point setup with this.

The function also contains additional methods and properties listed in instance.Point.

See:
Parameters:
Name Type Description
x number

The x coordinate

y number

The y coordinate

Ray(x, y, angle) → {Rac.Ray}

Convenience function that creates a new Ray setup with this.

The function also contains additional methods and properties listed in instance.Ray.

See:
Parameters:
Name Type Description
x number
y number
angle Rac.Angle | number

Segment(x, y, angle, length) → {Rac.Segment}

Convenience function that creates a new Segment setup with this.

The function also contains additional methods and properties listed in instance.Segment.

See:
Parameters:
Name Type Description
x number
y number
angle Rac.Angle | number
length number

setupDrawer(p5Instance)

# | source: Rac.js, line 167

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, colornullable) → {Rac.Stroke}

Convenience function that creates a new Stroke setup with this.

The function also contains additional methods and properties listed in instance.Stroke.

See:
Parameters:
Name Type Attributes Description
weight number <nullable>
color Rac.Color <nullable>

Style(strokenullable, fillnullable) → {Rac.Style}

Convenience function that creates a new Style setup with this.

The function also contains additional methods and properties listed in instance.Style.

See:
  • instance.Style
Parameters:
Name Type Attributes Description
stroke Rac.Stroke <nullable>
fill Rac.Fill <nullable>

Text(x, y, string, format) → {Rac.Text}

Convenience function that creates a new Text setup with this.

The function also contains additional methods and properties listed in instance.Text.

See:
Parameters:
Name Type 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

The format for the drawn text

TextFormat()

Alias of rac.Text.Format.

To display in documentation along the rest of utility instance functions.

unitaryEquals(a, b) → {boolean}

# | source: Rac.js, line 197

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