Class: TrianglePattern::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/triangle_pattern/pattern.rb

Instance Method Summary collapse

Constructor Details

#initialize(width, height, cell_size, variance, seed, colors, svg = TrianglePattern::SvgImage.new) ⇒ Pattern

Returns a new instance of Pattern.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/triangle_pattern/pattern.rb', line 3

def initialize(width, height, cell_size, variance, seed, colors, svg = TrianglePattern::SvgImage.new)
  @svg    = svg
  @width = width
  @height = height
  @points = TrianglePattern::Grid.new(@width, @height, cell_size, variance, seed).generate_grid
  d = Delaunator::Triangulator.new(@points.flatten)
  d.triangulate
  @delauny_indicies = d.triangles
  @colors = colors
  @triangles = generate_triangles
end

Instance Method Details

#to_base64Object



19
20
21
# File 'lib/triangle_pattern/pattern.rb', line 19

def to_base64
  Base64.strict_encode64(to_svg)
end

#to_svgObject



15
16
17
# File 'lib/triangle_pattern/pattern.rb', line 15

def to_svg
  image.to_s
end