w
of the gradient unit vector at x
, y
w
at 0 targets the X axis, at 1 the Y axis.
Returns a value between -1.0 and 1.0.
Require: w == 0 or w == 1
# Get the component `w` of the gradient unit vector at `x`, `y`
#
# `w` at 0 targets the X axis, at 1 the Y axis.
#
# Returns a value between -1.0 and 1.0.
#
# Require: `w == 0 or w == 1`
protected fun gradient_vector(x, y, w: Int): Float
do
assert w == 0 or w == 1
# Use our own deterministic pseudo random number generator
#
# These magic prime numbers were determined good enough by
# non-emperical experimentation. They may need to be changed/improved.
var seed = 817721 + self.seed
var i = seed * (x+seed) * 25111217 * (y+seed) * 72233613
var mod = 137121
var angle = (i.mask.abs%mod).to_f*2.0*pi/mod.to_f
# Debug code to evaluate the efficiency of the random angle generator
# The average of the produced angles should be at pi
#
#var sum = once new Container[Float](0.0)
#var count = once new Container[Float](0.0)
#sum.item += angle
#count.item += 1.0
#if count.item.to_i % 1000 == 0 then print "avg:{sum.item/count.item}/{count.item} i:{i} a:{angle} ({x}, {y}: {seed})"
if w == 0 then return angle.cos
return angle.sin
end
lib/noise/noise.nit:310,2--341,4