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

Attributes inherited from BasicShape

#options

Instance Method Summary collapse

Methods inherited from BasicShape

#flip, #flip_x, #flip_y, #jitter, #move, #rotate, #scale, #to_a, #to_bezier_path, #to_cubic_path, #to_multi_path, #to_simple_path, #to_svg

Constructor Details

#initialize(size, **options) ⇒ Heart

Returns a new instance of Heart.



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

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 Method Details

#to_pathObject

Convert the shape to a path



28
29
30
# File 'lib/vector_salad/standard_shapes/heart.rb', line 28

def to_path
  @shape
end