Class: PascalTriangle
- Inherits:
-
Object
- Object
- PascalTriangle
- Defined in:
- lib/pascal.rb
Overview
This was used to generate the coefficients for the gaussian blur. It would be better to make it dynamic.
Instance Method Summary collapse
Instance Method Details
#generate_c(max_radius = 10) ⇒ Object
25 26 27 28 29 |
# File 'lib/pascal.rb', line 25 def generate_c(max_radius=10) values = pascal_triangle(max_radius*2 + 1).reject {|a| a.size % 2 == 0} puts values.inspect.gsub('[', '{').gsub(']', '}') puts sums(max_radius).inspect.gsub('[', '{').gsub(']', '}') end |
#pascal_triangle(levels) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/pascal.rb', line 4 def pascal_triangle(levels) values = [[1]] (levels - 1).times do level = [1] values.last[1..-1].each_with_index do |x, i| level << x + values.last[i] end level << 1 values << level end values end |
#sums(max_radius) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/pascal.rb', line 17 def sums(max_radius) sums = [] (max_radius + 1).times do |i| sums << 2**(i*2) end sums end |