Guest User

Ruby Problem

a guest
Nov 22nd, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.16 KB | None | 0 0
  1. def generate(baseNoise, octave)
  2.             smoothNoise = ([[0]*@height] * @width)
  3.             samplePeriod = 1 << octave
  4.             sampleFrequency = 1.0 / samplePeriod
  5.             horizontal_blend = 0
  6.             smoothNoise.each_index  do |i|
  7.                 sample_i0 = (i / samplePeriod) * samplePeriod
  8.                 sample_i1 = (sample_i0 + samplePeriod) % @width
  9.                 horizontal_blend = (i - sample_i0) * sampleFrequency
  10.                 # puts horizontal_blend
  11.                 smoothNoise[i].each_index do |j|
  12.                     sample_j0 = (j / samplePeriod) * samplePeriod
  13.                     sample_j1 = (sample_j0 + samplePeriod) % @height
  14.                     vertical_blend = ( j - sample_j0 ) * sampleFrequency
  15.  
  16.                     top = Math.interpolate(baseNoise[sample_i0][sample_j0], baseNoise[sample_i1][sample_j0], horizontal_blend)
  17.                     bottom = Math.interpolate(baseNoise[sample_i0][sample_j1],baseNoise[sample_i1][sample_j1], horizontal_blend)
  18.                     # smoothNoise[i][j] = Math.interpolate(top, bottom, vertical_blend)
  19.                     smoothNoise[i][j] = horizontal_blend
  20.                     #to this place horizontal_blend is changed and well assigned to smoothNoise
  21.                 end
  22.             end
  23.             #but in this place smoothNoise is all filed in last horizontal_blend value
  24.             puts horizontal_blend
  25.             @noise = smoothNoise
  26.         end
Advertisement
Add Comment
Please, Sign In to add comment