Ejemplo n.º 1
0
def loopTest():

    loopCount = 10000
    print 'dimensions', 'ms', 'max value', 'min value'
    #histo=[0 for i in xrange(100)]

    print 'der'

    for i in xrange(2, 5):
        s = SimplexNoise(0, i)
        maxV = 0.0
        minV = 0.0
        t = time()
        for a in xrange(loopCount):
            v = s.simplexNoise([random.random() * 100 for x in xrange(i)],
                               True)
            d = v[1]
            v = d[0]
            maxV = max(maxV, v)
            minV = min(minV, v)

        #print i,(time()-t)/loopCount*1000,maxV,minV

        print 'derivative check'
        stepSize = .01
        stepCount = 200
        v = [
            s.simplexNoise([x * stepSize] * i, True) for x in xrange(stepCount)
        ]
        estimate = v[0][0]
        for val in v[:-1]:
            der = val[1]
            estimate += sum(der)
        estimate *= stepSize
        true = v[-1][0]
        print estimate - true, estimate, true

    print 'reg'

    if False:

        for i in xrange(2, 5):
            s = SimplexNoise(0, i)
            maxV = 0.0
            minV = 0.0
            t = time()
            for a in xrange(loopCount):
                v = s.simplexNoise(
                    ([random.random() * 100 for x in xrange(i)]))
                maxV = max(maxV, v)
                minV = min(minV, v)

            print i, (time() - t) / loopCount * 1000, maxV, minV
Ejemplo n.º 2
0
def verifyDerivatives(dimensions, verbose=True):
    if verbose: print 'verifyDerivatives:'
    passedList = []
    for d in dimensions:
        s = SimplexNoise(0, d)
        stepSize = .01
        stepCount = 256
        v = [
            s.simplexNoise([x * stepSize] * d, True) for x in xrange(stepCount)
        ]
        estimate = v[0][0]
        changeSum = 0
        for i in xrange(len(v) - 1):
            val = v[i]
            der = val[1]
            estimate += sum(der)
            changeSum += abs(val[0] - v[1 + 1][0])
        estimate *= stepSize
        true = v[-1][0]
        error = abs(estimate - true)
        error /= changeSum
        error *= 100
        passed = error < 0.1
        if verbose:
            print str(d) + ' dimensional:'
            print '    error percent: %5.8f' % error
            print '    ' + ('passed' if passed else 'FAILED')
        passedList.append(passed)
    return all(passedList)
Ejemplo n.º 3
0
def analyze(dimensions, verbose=True):
    if verbose: print 'analyze:'
    for d in dimensions:
        if verbose:
            print str(d) + ' dimensional:'
        count = 50000
        s = SimplexNoise(0, d)

        data = [
            s.simplexNoise([random.random() * 1000.0 for a in xrange(d)], True)
            for x in xrange(count)
        ]
        distributionCheck([v[0] for v in data], [v[1] for v in data], verbose)
def noise1D(sizeX, scale):
    s = SimplexNoise(0, 1)
    noiseTex = Texture("NoiseTex")
    noiseTex.setup2dTexture(sizeX, sizeX, Texture.TUnsignedByte, Texture.FRgb)
    p = noiseTex.modifyRamImage()
    print 'making tex ' + str(sizeX) + ' by ' + str(sizeX)
    for y in range(sizeX):
        v, der = s.simplexNoise([y / scale], True)
        for x in range(sizeX):
            index = (sizeX * y + x) * noiseTex.getNumComponents(
            ) * noiseTex.getComponentWidth()

            p.setElement(index, min(255, max(0, 0)))  #Blue
            p.setElement(index + 1, min(255, max(0, 0)))  #Green
            p.setElement(index + 2, min(255, max(0, v * 128 + 128)))  #Red
    return noiseTex
def noise3D(sizeX, sizeY, sizeZ, scale):
    s = SimplexNoise(0, 3)
    noiseTex = Texture("NoiseTex")
    noiseTex.setup3dTexture(sizeX, sizeY, sizeZ, Texture.TUnsignedByte,
                            Texture.FRgba)
    p = noiseTex.modifyRamImage()
    for z in range(sizeZ):
        offset = sizeX * sizeY * z
        print 'making slice ' + str(z) + ' of ' + str(sizeZ)
        for y in range(sizeY):
            for x in range(sizeX):
                index = (offset + sizeX * y + x) * noiseTex.getNumComponents(
                ) * noiseTex.getComponentWidth()
                v = s.simplexNoise([x / scale, y / scale, z / scale], True)
                der = v[1]
                v = v[0]
                p.setElement(index, min(255,
                                        max(0, der[1] * 8 * 128 + 128)))  #Blue
                p.setElement(index + 1,
                             min(255, max(0, der[0] * 8 * 128 + 128)))  #Green
                p.setElement(index + 2, min(255, max(0, v * 128 + 128)))  #Red
                p.setElement(index + 3, 255)  #Alpha
    return noiseTex