当前位置: 首页>>代码示例>>Python>>正文


Python noise.snoise2函数代码示例

本文整理汇总了Python中noise.snoise2函数的典型用法代码示例。如果您正苦于以下问题:Python snoise2函数的具体用法?Python snoise2怎么用?Python snoise2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了snoise2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setNextPositionPerlin

    def setNextPositionPerlin(self, *args, **kwargs):
        self.updateFunction = self.updatePerlin

        if('slow' in args):
            self.currentSpeedLimit = StewartPlatform.SERVO_SPEED_LIMIT/2
        else:
            self.currentSpeedLimit = StewartPlatform.SERVO_SPEED_LIMIT*2

        t = (time()-StewartPlatform.INIT_TIME) * StewartPlatform.PERLIN_TIME_SCALE
        (x,y,z) = self.currentPosition.getTranslationAsList()

        # direction
        u = snoise4(x*StewartPlatform.PERLIN_POSITION_SCALE + 1*StewartPlatform.PERLIN_PHASE,
            y*StewartPlatform.PERLIN_POSITION_SCALE + 1*StewartPlatform.PERLIN_PHASE,
            z*StewartPlatform.PERLIN_POSITION_SCALE + 1*StewartPlatform.PERLIN_PHASE,
            t + 1*StewartPlatform.PERLIN_PHASE)
        v = snoise4(x*StewartPlatform.PERLIN_POSITION_SCALE + 2*StewartPlatform.PERLIN_PHASE,
            y*StewartPlatform.PERLIN_POSITION_SCALE + 2*StewartPlatform.PERLIN_PHASE,
            z*StewartPlatform.PERLIN_POSITION_SCALE + 2*StewartPlatform.PERLIN_PHASE,
            t + 2*StewartPlatform.PERLIN_PHASE)
        w = snoise4(x*StewartPlatform.PERLIN_POSITION_SCALE + 3*StewartPlatform.PERLIN_PHASE,
            y*StewartPlatform.PERLIN_POSITION_SCALE + 3*StewartPlatform.PERLIN_PHASE,
            z*StewartPlatform.PERLIN_POSITION_SCALE + 3*StewartPlatform.PERLIN_PHASE,
            t + 3*StewartPlatform.PERLIN_PHASE)

        #magnitude
        thisSpeedScale = StewartPlatform.PERLIN_SPEED_SCALE/3 if ('slow' in args) else StewartPlatform.PERLIN_SPEED_SCALE
        speed = min(StewartPlatform.PERLIN_MAX_SPEED, max(StewartPlatform.PERLIN_MIN_SPEED, thisSpeedScale*(snoise4(u,v,w,t)*0.5+0.5)))

        # result
        deltaDistances = (
            u*speed,
            v*speed,
            w*speed)
        deltaAngles = (
            snoise2(v,t)*StewartPlatform.PERLIN_ANGLE_SCALE,
            snoise2(w,t)*StewartPlatform.PERLIN_ANGLE_SCALE,
            snoise2(u,t)*StewartPlatform.PERLIN_ANGLE_SCALE)

        # pick new valid position
        translateArg = kwargs.get('translate', '')
        rotateArg = kwargs.get('rotate', '')

        done = False
        while not done:
            translation = Vector3(
                deltaDistances[0] if 'x' in translateArg else 0,
                deltaDistances[1] if 'y' in translateArg else 0,
                deltaDistances[2] if 'z' in translateArg else 0) + self.currentPosition.translation
            translation.constrain(-StewartPlatform.PERLIN_DISTANCE_LIMIT, StewartPlatform.PERLIN_DISTANCE_LIMIT)

            rotation = Vector3(
                deltaAngles[0] if 'x' in rotateArg else 0,
                deltaAngles[1] if 'y' in rotateArg else 0,
                deltaAngles[2] if 'z' in rotateArg else 0) + self.currentPosition.rotation
            rotation.constrain(-StewartPlatform.PERLIN_ANGLE_LIMIT, StewartPlatform.PERLIN_ANGLE_LIMIT)

            done = self.setTargetAnglesSuccessfully(translation, rotation)
            deltaDistances = map(lambda x:0.9*x, deltaDistances)
            deltaAngles = map(lambda x:0.9*x, deltaAngles)
开发者ID:The-Hacktory,项目名称:memememe,代码行数:60,代码来源:stewartPlatform.py

示例2: _calculate

    def _calculate(seed, width, height):
        """Precipitation is a value in [-1,1]"""
        border = width / 4
        random.seed(seed * 13)
        base = random.randint(0, 4096)
        precipitations = numpy.zeros((height, width), dtype=float)

        octaves = 6
        freq = 64.0 * octaves

        for y in range(height):#TODO: numpy
            y_scaled = float(y) / height
            latitude_factor = 1.0 - (abs(y_scaled - 0.5) * 2)
            for x in range(width):
                n = snoise2(x / freq, y / freq, octaves, base=base)

                # Added to allow noise pattern to wrap around right and left.
                if x < border:
                    n = (snoise2(x / freq, y / freq, octaves,
                                 base=base) * x / border) + (
                        snoise2((x + width) / freq, y / freq, octaves,
                                base=base) * (border - x) / border)

                precipitation = (latitude_factor + n * 4) / 5.0
                precipitations[y, x] = precipitation

        return precipitations
开发者ID:kengonakajima,项目名称:worldengine,代码行数:27,代码来源:precipitation.py

示例3: gradients_perlin

def gradients_perlin(writer, period, speed):
	"""
	Creates random Perlin-noise gradients emanating from centre.
	:param writer: A writer to use
	:type writer: :class:`skyscreen_core.memmap_interface.NPMMAPScreenWriter`
	"""
	period = float(period)
	speed = int(speed)
	with writer as writer_buf:
		screen = np.zeros((Screen.screen_vane_count, Screen.screen_max_magnitude, 3))
		writer_buf_reshaped = writer_buf.reshape((Screen.screen_vane_count, Screen.screen_max_magnitude, 3))

		count = 0
		while True:
			for i in xrange(speed):
				r = noise.snoise2(1, count/period) * 128 + 128
				g = noise.snoise2(2, count/period) * 128 + 128
				b = noise.snoise2(3, count/period) * 128 + 128
				colour = (r, g, b)

				screen[:, :-1, :] = screen[:,1:,:]
				screen[:, -1, :] = colour
				count += 1
			writer_buf_reshaped[:,:,:] = screen
			writer.frame_ready()
开发者ID:jarrahl,项目名称:skyscreen,代码行数:25,代码来源:gradients.py

示例4: precipitation

def precipitation(seed, width, height):
    """"Precipitation is a value in [-1,1]"""
    border = width / 4 
    random.seed(seed * 13)
    base = random.randint(0, 4096)
    temp = [[0 for x in xrange(width)] for y in xrange(height)]

    from noise import snoise2

    octaves = 6
    freq = 64.0 * octaves

    for y in range(0, height):
        yscaled = float(y) / height
        latitude_factor = 1.0 - (abs(yscaled - 0.5) * 2)
        for x in range(0, width):
            n = snoise2(x / freq, y / freq, octaves, base=base)

            #Added to allow noise pattern to wrap around right and left.
            if x < border: 
		n = (snoise2(x / freq, y / freq, octaves, base=base) * x / border) + (snoise2((x+width) / freq, y / freq, octaves, base=base) * (border-x)/border)

            t = (latitude_factor + n * 4) / 5.0
            temp[y][x] = t

    return temp
开发者ID:SourceRyan,项目名称:lands,代码行数:26,代码来源:geo.py

示例5: temperature

def temperature(seed, elevation, mountain_level):
    width = len(elevation[0])
    height = len(elevation)

    random.seed(seed * 7)
    base = random.randint(0, 4096)
    temp = [[0 for x in xrange(width)] for y in xrange(height)]

    from noise import snoise2

    border = width / 4
    octaves = 6
    freq = 16.0 * octaves

    for y in range(0, height):
        yscaled = float(y) / height
        latitude_factor = 1.0 - (abs(yscaled - 0.5) * 2)
        for x in range(0, width):
            n = snoise2(x / freq, y / freq, octaves, base=base)

            #Added to allow noise pattern to wrap around right and left.
            if x <= border:
                n = (snoise2(x / freq, y / freq, octaves, base=base) * x / border) + (snoise2((x+width) / freq, y / freq, octaves, base=base) * (border-x)/border)

            t = (latitude_factor * 3 + n * 2) / 5.0
            if elevation[y][x] > mountain_level:
                if elevation[y][x] > (mountain_level + 29):
                    altitude_factor = 0.033
                else:
                    altitude_factor = 1.00 - (float(elevation[y][x] - mountain_level) / 30)
                t *= altitude_factor
            temp[y][x] = t

    return temp
开发者ID:SourceRyan,项目名称:lands,代码行数:34,代码来源:geo.py

示例6: fault_level

def fault_level(x, y, seed):
    FL = 1.0 - abs(snoise2(x * FAULT_SCALE_F, y * FAULT_SCALE_F, FAULT_OCTAVES, 
        base=seed + 10, repeatx=FAULT_SCALE))
    thold = max(0.0, (FL - FAULT_THRESHOLD) / (1.0 - FAULT_THRESHOLD))
    FL *= abs(snoise2(x * ERODE_SCALE_F, y * ERODE_SCALE_F, FAULT_EROSION_OCTAVES, 0.85, 
        base=seed, repeatx=FAULT_EROSION_SCALE))
    FL *= math.log10(thold * 9.0 + 1.0)
    return FL
开发者ID:sweetkristas,项目名称:mercy,代码行数:8,代码来源:genmap.py

示例7: noise_tile

def noise_tile(x, y, seed):
    """Computes a (simplex) noise value for a given coordinate and seed"""
    nx = float(x) / size - 0.5
    ny = float(y) / size - 0.5

    e = snoise2(nx, ny, octaves=8, base=seed)
    e += 0.5 * snoise2(2*nx, 2*ny, octaves=8, base=seed)
    e += 0.25 * snoise2(4*nx, 4*ny, octaves=8, base=seed)
    return e
开发者ID:robertopedroso,项目名称:WorldMapGen,代码行数:9,代码来源:worldmap.py

示例8: sumInflectedNoise

def sumInflectedNoise(point, frequency, octaves=2, lacunarity=2.0, persistence=0.5):
    sum = abs(snoise2(point[0] / frequency, point[1] / frequency))
    amplitude = 1.0
    ran = 1.0
    for o in range(1, octaves):
        frequency /= lacunarity
        amplitude *= persistence
        ran += amplitude
        sum += abs(snoise2(point[0] / frequency, point[1] / frequency)) * amplitude
    return sum / ran
开发者ID:ianjsikes,项目名称:continent-generator,代码行数:10,代码来源:Generators.py

示例9: sumNoise

def sumNoise(point, frequency, octaves=2, lacunarity=2.0, persistence=0.5):
    sum = (snoise2(point[0] / frequency, point[1] / frequency) / 2.0) + 0.5
    amplitude = 1.0
    ran = 1.0
    for o in range(1, octaves):
        frequency /= lacunarity
        amplitude *= persistence
        ran += amplitude
        sum += (snoise2(point[0] / frequency, point[1] / frequency) * 0.5 + 0.5) * amplitude
    return sum / ran
开发者ID:ianjsikes,项目名称:continent-generator,代码行数:10,代码来源:Generators.py

示例10: __getitem__

 def __getitem__(self, idx):
   x, y, zoom = idx
   return snoise2(
     (self.xseed + (x)*zoom) / self.frequency,
     (self.yseed + (y)*zoom) / self.frequency,
     self.octaves
   )
开发者ID:traeger,项目名称:_,代码行数:7,代码来源:worldNoise.py

示例11: make_layer

def make_layer(type_id, width, height, threshold=0.3, jitter=0.5, scale=16, offset=None):
    layer = ''
    if offset is None:
        offset = random.random() * random.randint(width, width * 100)
    else:
        random.seed(offset)
    for y in range(0, height):
        for x in range(0, width):
            weight1 = noise.snoise2(
                x / scale,
                y / scale,
                octaves=1,
                persistence=0.01,
                base=offset,
            )
            weight2 = random.random() * 2 - 1
            weight = (weight1 * (2-jitter) + weight2 * jitter) / 2
            if callable(threshold):
                t = threshold(x, y)
            else:
                t = default_threshold(x, y, threshold)
            if weight > t:
                layer += type_id
            else:
                layer += ' '
        layer += '\n'
    return layer
开发者ID:sheppard,项目名称:bg,代码行数:27,代码来源:util.py

示例12: image_layer_noise_old

def image_layer_noise_old(width=256, height=256, white_min=0.5, white_range=None):
    #Add Noise
    #TODO: Make a function to generate different types of noise, some for blending colors, others for contrast, etc.

    x_start = 0
    y_start = 0

    # freq = 32.0 * octaves
    freq = width
    white_min *= 255.0
    if not white_range:
        white_range = 1-white_min
    white_range *= 255.0

    octaves = 42
    period = 128.0

    image_data = []
    for y in range(height):
        for x in range(width):
#            noisenum = noise.snoise2(x_start + (x / freq), y_start + (y / freq), octaves)
            noisenum = noise.snoise2(x/period, y/period, octaves)

            # noisenum = pnoise2(x * 16.0 / width, y * 16.0 / width, octaves=64, repeatx=64.0, repeaty=64.0)
            image_data.append((255, 255, 255, int(noisenum * white_range + white_min)))

    return image_data
开发者ID:jaycrossler,项目名称:procyon,代码行数:27,代码来源:texture_generator.py

示例13: test_simplex_2d_range

 def test_simplex_2d_range(self):
     from noise import snoise2
     for i in range(-10000, 10000):
         x = i * 0.49
         y = -i * 0.67
         n = snoise2(x, y)
         self.assertTrue(-1.0 <= n <= 1.0, (x, y, n))
开发者ID:Connor124,项目名称:Gran-Theft-Crop-Toe,代码行数:7,代码来源:test.py

示例14: generate_map

def generate_map(worldId=0,width=WIDTH,height=HEIGHT,xoffset=0.0,yoffset=0.0,zoom=1.0):
    """ Return a simple matrix of simplex noise from 0-255."""
    mapdata = []
    random.seed(worldId)
    zoom=zoom * 100.0
    riversource=[]
    for x in xrange(height):
        row=[]
        for y in xrange (width):
            xparam=float((x+xoffset)/zoom)
            yparam=float((y+yoffset)/zoom)
            noisevalue=snoise2(xparam, yparam,  NOISEOCTAVES, 0.52,2.0, height/zoom*2, width/zoom, float(worldId) )
            #convert 1.0...-1.0 to 255...0
            pixel=int((noisevalue+1)/2*PIXEL_DEPTH-1)
            cell={'height': pixel, 'x':x, 'y':y }
            if (pixel < SEALEVEL):
                cell['type']='water'
            else:
                cell['type']='land'
                if (random.randint(0,10000) <5):
                    cell['riverhead']=True
                    riversource.append(cell)
                    
            row.append( cell )
        mapdata.append(row)


    #pp = pprint.PrettyPrinter(indent=4)
    #pp.pprint(riversource) 
    return mapdata
开发者ID:Draconomial,项目名称:Megacosm-Generator,代码行数:30,代码来源:WorldMap.py

示例15: add_noise_to_elevation

def add_noise_to_elevation(world, seed):
    octaves = 8
    freq = 16.0 * octaves
    for y in range(world.height):
        for x in range(world.width):
            n = snoise2(x / freq * 2, y / freq * 2, octaves, base=seed)
            world.elevation['data'][y][x] += n
开发者ID:tmfoltz,项目名称:worldengine,代码行数:7,代码来源:generation.py


注:本文中的noise.snoise2函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。