Class: VectorSalad::Canvas

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/vector_salad/canvas.rb

Overview

All shapes must be added to the global canvas for export, and block transform shapes like StandardShapes::Union or StandardShapes::Move have an internal canvas that shapes must be added to.

In most cases you'll want to use the DSL which abstracts away the canvas so you don't have to think about it.

Examples:

Manually adding a circle to a canvas:

canvas << Circle.new(100)

Implicitly adding a circle to a canvas using DSL:

circle(100)

Instance Method Summary collapse

Constructor Details

#initializeCanvas

Returns a new instance of Canvas.



17
18
19
# File 'lib/vector_salad/canvas.rb', line 17

def initialize
  @canvas = []
end

Instance Method Details

#<<(shape) ⇒ Object

Add a shape to the canvas



22
23
24
# File 'lib/vector_salad/canvas.rb', line 22

def <<(shape)
  @canvas << shape
end

#[](i) ⇒ Object

Access a specific shape in the canvas. Often used to get the first shape [0] for situations where only a single shape is allowed.



40
41
42
# File 'lib/vector_salad/canvas.rb', line 40

def [](i)
  @canvas[i].class==VectorSalad::ShapeProxy ? @canvas[i].shape : @canvas[i]
end

#each(&block) ⇒ Object

Loop over the shapes in the canvas.



27
28
29
30
31
32
33
34
35
# File 'lib/vector_salad/canvas.rb', line 27

def each(&block)
  @canvas.each do |shape|
    shape = shape.shape if shape.class == VectorSalad::ShapeProxy
    unless shape.class == VectorSalad::StandardShapes::Custom ||
          !shape.kind_of?(VectorSalad::StandardShapes::BasicShape)
      yield(shape)
    end
  end
end