class Fractal::Similar
Constants
- INITIAL_POINT
Attributes
points[R]
Public Class Methods
new(repetition:, size_square: 100.0)
click to toggle source
# File lib/Similar.rb, line 5 def initialize(repetition:, size_square: 100.0) @new_points = INITIAL_POINT.map{|t| [t[0]*size_square, t[1]*size_square]} @points = @new_points.dup @repetition = repetition @iteration = [] end
Public Instance Methods
add(x:, y:, rotation:, size:)
click to toggle source
# File lib/Similar.rb, line 12 def add(x:, y:, rotation:, size:) rotation_temp = rotation* Math::PI / 180 @iteration << [[x,y], [Math.cos(rotation_temp), Math.sin(rotation_temp)], size] end
build()
click to toggle source
# File lib/Similar.rb, line 19 def build @repetition.times do new_points = [] @iteration.each do |i| @new_points.each do |po| new_points << [ i[2] * (i[1][0]*po[0]-i[1][1]*po[1]) + i[0][0], i[2] * (i[1][1]*po[0]+i[1][0]*po[1]) + i[0][1] ] end end @points += new_points @new_points = new_points end end