Class: VectorSalad::StandardShapes::Scale

Inherits:
Transform
  • Object
show all
Defined in:
lib/vector_salad/standard_shapes/scale.rb

Overview

Scale the contained shapes by multiplier about the origin.

Instance Method Summary (collapse)

Constructor Details

- (Any) initialize(x_multiplier, y_multiplier = x_multiplier, canvas:, **_options, &block)

Supply just 1 multiplier to scale evenly, or x and y multipliers to stretch or squash the axies.

Examples:

scale(2) do
  triangle(30, at: [50, -50])
  pentagon(40, at: [50, -100])
end

Uneven scaling

scale(2, 0.5) do
  triangle(30, at: [50, -50])
  pentagon(40, at: [50, -100])
end

Parameters:

  • x_multiplier (Coord)

    +Num; a coordinate+. 1 is no change, 2 is double size, 0.5 is half, etc.

  • y_multiplier (Coord) (defaults to: x_multiplier)

    +Num; a coordinate+

  • canvas ([])
  • _options ([])
  • block (Proc)


24
25
26
27
28
29
30
31
32
# File 'lib/vector_salad/standard_shapes/scale.rb', line 24

def initialize(x_multiplier,
               y_multiplier = x_multiplier,
               canvas:, **_options, &block)
  instance_eval(&block) # inner_canvas is populated

  @canvas.each do |shape|
    canvas << shape.scale(x_multiplier, y_multiplier)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class VectorSalad::DSL