import math

def random( x ) :
    x = ( x << 13 ) ^ x
    return 1.0 - ( ( x * ( x * x * 15731 + 789221 ) + 1376312589 ) &
        0x7fffffff ) / 1073741824.0

def cosine_interpolate( a, b, x ) :
    f = ( 1 - math.cos( x * math.pi ) ) * 0.5
    return a * ( 1 - f ) + b * f

class Noise :

    def __init__( self, persistence, octave_count ) :
        self.persistence = persistence
        self.octave_count = octave_count

    def generate( self, x ) :
        retval = 0
        for octave in range( self.octave_count ) :
            frequency = 2 ** octave
            amplitude = self.persistence ** octave
            retval += self._interpolated_random( x * frequency ) * amplitude
        return retval

    def _interpolated_random( self, x ) :
        x_int = int( x )
        x_fract = x - x_int
        x1 = random( x_int )
        x2 = random( x_int + 1 )
        return cosine_interpolate( x1, x2, x_fract )

@@ -10,272 +10,8 @@
 th%0A%0A
-def random( x ) :%0A    x = ( x %3C%3C 13 ) %5E x%0A    return 1.0 - ( ( x * ( x * x * 15731 + 789221 ) + 1376312589 ) &%0A        0x7fffffff ) / 1073741824.0%0A%0Adef cosine_interpolate( a, b, x ) :%0A    f = ( 1 - math.cos( x * math.pi ) ) * 0.5%0A    return a * ( 1 - f ) + b * f%0A%0A
 clas
@@ -168,16 +168,16 @@
 def 
-generate
+__call__
 ( se
@@ -551,16 +551,23 @@
    x1 = 
+Noise._
 random( 
@@ -587,16 +587,23 @@
    x2 = 
+Noise._
 random( 
@@ -629,16 +629,23 @@
  return 
+Noise._
 cosine_i
@@ -670,12 +670,342 @@
 , x_fract )%0A
+%0A    @staticmethod%0A    def _random( x ) :%0A        x = ( x %3C%3C 13 ) %5E x%0A        return 1.0 - ( ( x * ( x * x * 15731 + 789221 ) + 1376312589 ) &%0A            0x7fffffff ) / 1073741824.0%0A%0A    @staticmethod%0A    def _cosine_interpolate( a, b, x ) :%0A        f = ( 1 - math.cos( x * math.pi ) ) * 0.5%0A        return a * ( 1 - f ) + b * f%0A

samples : python : perlin : refactoring