Class: VectorSalad::StandardShapes::N
- Inherits:
-
Object
- Object
- VectorSalad::StandardShapes::N
- Includes:
- Mixins::At
- Defined in:
- lib/vector_salad/standard_shapes/n.rb
Overview
N node. A node is the simplest primitive but useless on its own. Use nodes to build up a path (see Path). A node is a point in space with x and y coordinates.
Instance Attribute Summary (collapse)
-
- (Object) type
Returns the value of attribute type.
-
- (Object) x
Returns the value of attribute x.
-
- (Object) y
Returns the value of attribute y.
Class Method Summary (collapse)
-
+ (N) c(x, y)
Shorthand that creates a :cubic type bezier curve handle node.
-
+ (N) g(x, y)
Shorthand that creates a smooth spiro :g4 node.
-
+ (N) l(x, y)
Shorthand that creates a :left spiro node.
-
+ (N) m
Creates a :mirrored type node.
-
+ (N) n(x, y, type = :node)
Shorthand for calling
new
to create a node. -
+ (N) q(x, y)
Shorthand that creates a :quadratic type bezier curve handle node.
-
+ (N) r(x, y)
Shorthand that creates a :right spiro node.
-
+ (N) s(x, y)
Shorthand that creates a smooth spiro :g2 node.
Instance Method Summary (collapse)
-
- (Any) [](x, y)
included
from Mixins::At
Set the x, y coordinates of the shape.
-
- (Coords) at
included
from Mixins::At
Get the x, y coordinates of the shape.
-
- (Any) at=(at)
included
from Mixins::At
Set the x, y coordinates of the shape directly.
-
- (N) initialize(x, y, type = :node)
constructor
Create an N node.
-
- (Any) move(x, y)
included
from Mixins::At
Move the shape relatively.
Constructor Details
- (N) initialize(x, y, type = :node)
Create an N node.
The coordinates must be nil if the node type is :mirror, else they must be numeric.
A node also has a type, the simplest is :node for corners. To create node types other than :node see the shorthand class methods.
Examples: new(50, 100) new(50, 100, :cubic) new(nil, nil, :mirror)
15 16 17 18 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 15 def initialize(x, y, type) create(x, y, type) self end |
Instance Attribute Details
- (Object) type
Returns the value of attribute type
12 13 14 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 12 def type @type end |
- (Object) x
Returns the value of attribute x
12 13 14 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 12 def x @x end |
- (Object) y
Returns the value of attribute y
12 13 14 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 12 def y @y end |
Class Method Details
+ (N) c(x, y)
Shorthand that creates a :cubic type bezier curve handle node. This "off curve" node isn't part of the path but distorts pulling it. Two :cubic nodes must come between two :node type nodes. E.g. n c c n. As the interaction of two cubic nodes distorts the line segment this can be quite difficult to imagine, see :quadratic or :spiro for easier alternatives to make curves.
62 63 64 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 62 def self.c(x, y) new(x, y, :cubic) end |
+ (N) g(x, y)
Shorthand that creates a smooth spiro :g4 node. There are :g2 and :g4 spiro node types; :g4 is smoothest but has longer distance effects and may sometimes fail.
90 91 92 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 90 def self.g(x, y) new(x, y, :g4) end |
+ (N) l(x, y)
Shorthand that creates a :left spiro node. It joins a straight line segment on the right to a curve on the left.
104 105 106 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 104 def self.l(x, y) new(x, y, :left) end |
+ (N) m
Creates a :mirrored type node. It makes it easier to make smooth curves. The reflection is based on the cubic or quadratic node before the last standard :node so there must be one.
51 52 53 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 51 def self.m new(nil, nil, :mirror) end |
+ (N) n(x, y, type = :node)
Shorthand for calling new
to create a node.
The type defaults to :node for basic corner or line segment nodes.
See the documentation for new
for usage.
43 44 45 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 43 def self.n(x, y, type = :node) new(x, y, type) end |
+ (N) q(x, y)
Shorthand that creates a :quadratic type bezier curve handle node. This "off curve" node isn't part of the path but distorts pulling it. One :quadratic node must come between two :node type nodes. E.g. n q n. Only one quadratic node is needed to make a curve, however :spiro type nodes are even easier for making smooth curves.
72 73 74 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 72 def self.q(x, y) new(x, y, :quadratic) end |
+ (N) r(x, y)
Shorthand that creates a :right spiro node. It joins a straight line segment on the left to a curve on the right.
97 98 99 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 97 def self.r(x, y) new(x, y, :right) end |
+ (N) s(x, y)
Shorthand that creates a smooth spiro :g2 node. Spiro nodes are "on curve" so the path bends through them, finding the smoothest possible route. They are perfect for making organic curves. There are :g2 and :g4 spiro node types; :g2 is most robust and a good all rounder.
82 83 84 |
# File 'lib/vector_salad/standard_shapes/n.rb', line 82 def self.s(x, y) new(x, y, :g2) end |
Instance Method Details
- (Any) [](x, y) Originally defined in module Mixins::At
Set the x, y coordinates of the shape.
- (Coords) at Originally defined in module Mixins::At
Get the x, y coordinates of the shape.
- (Any) at=(at) Originally defined in module Mixins::At
Set the x, y coordinates of the shape directly.
- (Any) move(x, y) Originally defined in module Mixins::At
Move the shape relatively.