Class: VectorSalad::StandardShapes::Heart

Inherits:
BasicShape
  • Object
show all
Defined in:
lib/vector_salad/standard_shapes/heart.rb

Overview

Perfect heart shape.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Heart) initialize(size, **options)

Create a perfect heart

Parameters:

  • size (Pos)
  • options ({})

    +{}+



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vector_salad/standard_shapes/heart.rb', line 11

def initialize(size, **options)
  r = size / 4 # two circles next to each other
  r2 = Math.sqrt(2 * r**2)
  the_little_bit = r2 - r
  the_long_one = size + 2 * the_little_bit
  l = Math.sqrt(the_long_one**2 / 2) - r

  @shape = Union.new(**options) do
    circle(r)[-r, 0]
    circle(r)[r, 0]
    difference do
      square(l)[-l / 2, -l / 2].rotate(45).move(0, r2 / 2)
      square(l * 2)[-l, -l * 2]
    end
  end
  self
end

Instance Attribute Details

- (Object) options Originally defined in class BasicShape

Returns the value of attribute options

Instance Method Details

- (Object) to_path

Convert the shape to a path



30
31
32
# File 'lib/vector_salad/standard_shapes/heart.rb', line 30

def to_path
  @shape
end