Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def generate(baseNoise, octave)
- smoothNoise = ([[0]*@height] * @width)
- samplePeriod = 1 << octave
- sampleFrequency = 1.0 / samplePeriod
- horizontal_blend = 0
- smoothNoise.each_index do |i|
- sample_i0 = (i / samplePeriod) * samplePeriod
- sample_i1 = (sample_i0 + samplePeriod) % @width
- horizontal_blend = (i - sample_i0) * sampleFrequency
- # puts horizontal_blend
- smoothNoise[i].each_index do |j|
- sample_j0 = (j / samplePeriod) * samplePeriod
- sample_j1 = (sample_j0 + samplePeriod) % @height
- vertical_blend = ( j - sample_j0 ) * sampleFrequency
- top = Math.interpolate(baseNoise[sample_i0][sample_j0], baseNoise[sample_i1][sample_j0], horizontal_blend)
- bottom = Math.interpolate(baseNoise[sample_i0][sample_j1],baseNoise[sample_i1][sample_j1], horizontal_blend)
- # smoothNoise[i][j] = Math.interpolate(top, bottom, vertical_blend)
- smoothNoise[i][j] = horizontal_blend
- #to this place horizontal_blend is changed and well assigned to smoothNoise
- end
- end
- #but in this place smoothNoise is all filed in last horizontal_blend value
- puts horizontal_blend
- @noise = smoothNoise
- end
Advertisement
Add Comment
Please, Sign In to add comment