Method: AutoColors::ColorScheme#rand_seq

Defined in:
lib/autocolors/colorscheme.rb

#rand_seq(min, max, points, contraction = 1.0) ⇒ Object (protected)



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/autocolors/colorscheme.rb', line 178

def rand_seq(min, max, points, contraction=1.0)
  max = max.to_f; min = min.to_f; contraction = contraction.to_f
  spread = max - min
  base_step = spread / (points.to_f - 1.0) * contraction
  partial = base_step / 3.0
  curr = 0.0
  res = [curr]
  while res.size < points
    curr += nrand(base_step, partial / 2.0, base_step - (partial), base_step + (partial))
    res << curr
  end
  if curr > spread
    factor = spread / curr
    res.map!{|v| factor * v}
  else
    offset = (spread - curr) * rand
    res.map!{|v| offset + v}
  end
  return res.map{|v| v + min}
end