コード例 #1
0
ファイル: stewartPlatform.py プロジェクト: scgowda/memememe
    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)
コード例 #2
0
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
コード例 #3
0
ファイル: sandSpline.py プロジェクト: kylestew/AlgodoneRings
    def __next__(self):
        num = len(self.path) # number of segments in spline

        # randomly permute path positions
        # generate a random number from (-1,1) for each spline section
        r = np.zeros(num)
        for i in range(num):
            r[i] = snoise2(i, self.i/self.noiseDetail)
        # dampen random values
        r *= self.noiseScale
        # permute our noise value by applying random values
        # remember they are centered around 0 so noise will not drift
        self.noise[:] += r

        # pick a new random set or angles to drive towards
        a = np.zeros(num)
        for i in range(num):
            a[i] = 2.0*pi*snoise2(i, self.i/self.noiseDetail)
        rnd = np.column_stack((np.cos(a), np.sin(a)))
        # using noise, move current points towards random points a little
        self.path += rnd * np.reshape(self.noise, (num, 1))

        # always force last item to equal first so there isn't disconnection in spline
        self.path[num-1] = self.path[0]

        # output an interpolate spline path from the points
        self.interpolatedPath = self.randomInterpolation(self.path, self.density)

        self.i += 1
        return self.interpolatedPath
コード例 #4
0
def create_noise_map(octaves):
    biome = open("biome.pgm", 'wt')
    foliage = open("foliage.pgm", 'wt')

    width = 500
    height = 500

    biomefreq = 16.0 * octaves[0]
    biome.write('P2\n')
    biome.write('%s %s\n' % (width, height))
    biome.write('255\n')

    foliagefreq = 20.0 * octaves[1]
    foliage.write('P2\n')
    foliage.write('%s %s\n' % (width, height))
    foliage.write('255\n')

    for y in range(width):
        for x in range(height):
            biome.write("%s\n" % int(
                snoise2(x / biomefreq, y / biomefreq, octaves[0]) * 127.0 +
                128.0))

    for y in range(width):
        for x in range(height):
            foliage.write("%s\n" % int(
                snoise2(x / foliagefreq, y / foliagefreq, octaves[1]) * 127.0 +
                128.0))

    biome.close()
    foliage.close()
コード例 #5
0
    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
コード例 #6
0
ファイル: geo.py プロジェクト: SourceRyan/lands
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
コード例 #7
0
    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)
コード例 #8
0
ファイル: gradients.py プロジェクト: jarrahl/skyscreen
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()
コード例 #9
0
    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
コード例 #10
0
    def land_gen(self):
        """
        Uses simplex noise to create a random map of values that roughly resemble real life elevation values
        Uses notes from https://www.redblobgames.com/maps/terrain-from-noise/
        """
        self.sea_value = 0
        elevation_seed = np.random.randint(1, 1000)
        moisture_seed = np.random.randint(1, 1000)
        print("Elevation seed: ", elevation_seed, "\nMoisture seed: ",
              moisture_seed)
        for x in range(self.size[0]):
            for y in range(self.size[1]):

                elevation = snoise2(x / self.size[0],
                                    y / self.size[1],
                                    octaves=8,
                                    base=elevation_seed) / 2 + 0.5
                moisture = snoise2(x / self.size[0],
                                   y / self.size[1],
                                   octaves=24,
                                   base=moisture_seed) / 2 + 0.5
                sea_level = 0.4
                if elevation < sea_level:
                    self.sea_value += 1
                self.elevation[x][y] = elevation
                self.moisture[x][y] = moisture
コード例 #11
0
ファイル: geo.py プロジェクト: SourceRyan/lands
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
コード例 #12
0
def random_pos(pos_x, pos_y):
    return [
        pos_x * cell_size +
        noise.snoise2(pos_x * 124.324 - 519.6534, pos_y * 312.1253 + 812.1241)
        * cell_size * 0.5, pos_y * cell_size +
        noise.snoise2(pos_y * 224.324 - 219.6534,
                      pos_x * 414.1253 + 912.1241) * cell_size * 0.5
    ]
コード例 #13
0
ファイル: genmap.py プロジェクト: sweetkristas/mercy
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
コード例 #14
0
def random_color(pos_x, pos_y):
    return [
        int(128 + noise.snoise2(pos_x * 124.324 - 519.6534, pos_y * 312.1253 +
                                812.1241) * 128),
        int(128 + noise.snoise2(pos_y * 224.324 - 219.6534, pos_x * 414.1253 +
                                912.1241) * 128),
        int(128 + noise.snoise2(pos_x * 274.324 - 119.6534, pos_y * 114.1253 +
                                512.1241) * 128)
    ]
コード例 #15
0
 def generateElevations(self):
     elevation = [0] * self.width
     base = self.height / 4
     j = self.seed / Constants.SEED_MAX
     for i in range(self.width):
         elevation[i] += snoise2(i / self.width, j, 4)
         elevation[i] += snoise2(i / self.width, j, 16)
         elevation[i] *= base
     return elevation
コード例 #16
0
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
コード例 #17
0
    def at_point(self, point: Tuple[float, float]) -> float:
        x = point[0] + self.seed[0]
        y = point[1] + self.seed[1]

        value1 = (snoise2(x / 10000, y / 10000) + 1) / 2
        value2 = (snoise2((x / 20000) + 500, (y / 20000) + 500) + 1) / 2
        value3 = (snoise2((x / 20000) + 1000, (y / 20000) + 1000) + 1) / 2

        return math.pow(((value1 * value2) + value3), 2)
コード例 #18
0
def f(x: float, y: float) -> float:
    scale = 15

    fxy = (
        0 + scale / 1 * noise.snoise2(x / 100 * 1 + 0, y / 100.0 * 1 + 0) +
        scale / 4 * noise.snoise2(x / 100 * 2 + 100, y / 100.0 * 2 + 100)
        # + scale / 16 * noise.snoise2(x / 100 * 4, y / 100.0 * 4)
    )
    return fxy
コード例 #19
0
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
コード例 #20
0
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
コード例 #21
0
    def make_world(self, map_width, map_height, player, entities, max_monsters_per_spawn, kolors, current_roster, current_mm):
        #elevation = randint(0, 3) #low, level, moderate, high
        #moisture = randint(0, 2) #dry, normal, water
        #temperature = randing(0, 2) #cold, normal, hot
        #vegetation = randint(0, 2) #none, grass, woods
        scale = 100.0
        octaves = 6
        persistence = 0.5
        lacunarity = 2.0
        seed_h = randint(0, 131072)
        seed_v = randint(0, 131072)

        water_threshold = -0.25
        shallows_threshold = -0.2
        sand_threshold = -0.1775
        plains_threshold = 0.1
        hills_threshold = 0.3
        mountain_threshold = 0.425
        vegetation_threshold = -0.05

        world_height = [[0
            for y in range(0, map_height)]
                for x in range(0, map_width)]

        world_vegetation = [[0
            for y in range(0, map_height)]
                for x in range(0, map_width)]

        for y in range(0, map_height):
            for x in range(0, map_width):
                #Height map
                world_height[x][y] = noise.snoise2(x/scale, y/scale, octaves=octaves, persistence=persistence, lacunarity=lacunarity, repeatx=map_width, repeaty=map_height, base=seed_h)
                if world_height[x][y] < water_threshold:
                    self.tiles[x][y].terrain = 0 #Water
                elif world_height[x][y] < shallows_threshold:
                    self.tiles[x][y].terrain = 1 #Shallows
                elif world_height[x][y] < sand_threshold:
                    self.tiles[x][y].terrain = 2 #Sand
                elif world_height[x][y] < plains_threshold:
                    self.tiles[x][y].terrain = 3 #Plains
                elif world_height[x][y] < hills_threshold:
                    self.tiles[x][y].terrain = 4 #Hills
                elif world_height[x][y] < mountain_threshold:
                    self.tiles[x][y].terrain = 5 #Mountains
                else:
                    self.tiles[x][y].terrain = 6 #Snow
                #Vegetation map
                world_vegetation[x][y] = noise.snoise2(x/scale, y/scale, octaves=octaves, persistence=persistence, lacunarity=lacunarity, repeatx=map_width, repeaty=map_height, base=seed_v)
                if world_vegetation[x][y] < vegetation_threshold:
                    self.tiles[x][y].vegetation = 1 #Yes
                else:
                    self.tiles[x][y].vegetation = 0 #None
                #Tile settings
                self.tiles[x][y].blocked = False
                self.tiles[x][y].block_sight = False
コード例 #22
0
def snoise2(x, y=None, octaves=1, gain=0.5, lacunarity=2, amp=1, repeat=1):
    if y is not None:
        return amp * fit_11_to_01(
            noise.snoise2(x * repeat, y * repeat, octaves, gain, lacunarity))
    else:
        r = np.empty((len(x), ), dtype=np.float64)
        for i, d in enumerate(x):
            r[i] = amp * fit_11_to_01(
                noise.snoise2(d[0] * repeat, d[1] * repeat, octaves, gain,
                              lacunarity))
        return r
コード例 #23
0
    def map_selection_lasso(self):
        url = self.locust.host + '/map/selection/lasso'
        
        # for lasso we will extrude a circle from a point placed upon the usa
        point  = (util.rng_usa_lat(), util.rng_usa_lng())

        # size of shape
        latsize = random.uniform(1, 5)
        lngsize = random.uniform(1, 10)

        # how many vertices 
        detail = 3 
        
        # spacing on ellipsoid between each vertex
        spacing = (math.pi * 2) / detail

        # mag or magnitude refers to the amount our noise value should apply
        # should it be strong (large hills) or weak (small bumps)
        mag = random.uniform(1, 7)

        # mult refers to how much our positions should be taken into account.
        # a low value will result in a smooth surface, a large value equates to a very varying surface
        mult = random.uniform(0.25, 0.5)


        vertices = []

        for i in range(0, detail):
            angle = spacing * i
            ax = math.cos(angle)
            ay = math.sin(angle)

            axm = ax * mult
            aym = ay * mult

            lat = point[0] + (ax * latsize * ((1.1 + noise.snoise2(axm, aym)) * mag))
            lng = point[1] + (ay * lngsize * ((1.1 + noise.snoise2(axm, aym)) * mag))

            vertices.append(str(lat) + "," + str(lng))

        params = {
            'filter[rating]': '0',
            'filter[is_approved]': 'true',
            'filter[type]': util.rng_event(),
            'vertices[]': vertices
        }

        self.response = self.client.request(
            method='GET',
            url=url,
            headers=shared.get_headers(),
            params=params,
        )
コード例 #24
0
    def layeredSimplex(self, x, y, seed):
        period = 0.5
        adjustedX = (x / 2) * period
        adjustedY = (y / 2) * period

        map1 = snoise2(adjustedX, adjustedY, 1, base=seed)
        map2 = snoise2(adjustedX, adjustedY, 2, base=seed)
        map3 = snoise2(adjustedX, adjustedY, 3, base=seed)

        merged = (map1 * 3 + map2 * 2 + map3 * 1) / 6

        return merged
コード例 #25
0
def gethighlow():
    l = h = (noise.snoise2(((0 + shiftx) / freq),
                           ((0 + shifty) / freq), octave) + 1) / 2
    for x in range(imgwidth):
        for y in range(imgheight):
            i = (noise.snoise2(((x + shiftx) / freq),
                               ((y + shifty) / freq), octave) + 1) / 2
            if i > h:
                h = i
            if i < l:
                l = i
    h = (h - l)
    return h, l
コード例 #26
0
def main(seed, mx, my, wx, wy, flatness=0.4):
    MAP_ROUND = 4
    mx, my = range(mx * MAP_ROUND), range(my * MAP_ROUND)
    octaves = 32
    freq = octaves * 8
    l = [[0 for i in my] for i in my]
    for x in mx:
        for y in my:
            l[x][y] = snoise2(x / freq + wx * len(mx),
                              y / freq + wy * len(my),
                              octaves,
                              base=0)
    fl = []
    for x in range(len(l) // MAP_ROUND):
        fl.append([])
        for y in range(len(l[0]) // MAP_ROUND):
            avg = 0
            c = 0
            for i in range(MAP_ROUND):
                for j in range(MAP_ROUND):
                    c += 1
                    avg += l[MAP_ROUND * x + i][MAP_ROUND * y + j]

            fl[x].append(avg / c)

    return l
コード例 #27
0
def create_noise_map(size, freq, octaves):
    nmap = []
    freq *= octaves
    for x in range(size):
        for y in range(size):
            nmap.append(snoise2(x / freq, y / freq, octaves))
    return nmap
コード例 #28
0
ファイル: terrain.py プロジェクト: samcorcoran/hexagons
def createNoiseList(width, height, inBytes=False):
    octaves = 4
    freq = 8.0 * octaves
    # minZ= 0
    # maxZ = 0
    # cumulativeZ = 0
    # count = 0
    texels = [] #[0 for n in range(width*height)]
    for y in range(height):
        row = []
        for x in range(width):
            #z = int(snoise2(x / freq, y / freq, octaves) * 127.0 + 128.0)
            # Noise between 0 and 1
            z = snoise2(x / freq, y / freq, octaves)
            if inBytes:
                z = struct.pak('<B', z & 0xFFFF)

            # if z < minZ:
            #   minZ = z
            # if z > maxZ:
            #   maxZ = z
            # cumulativeZ += z
            # count += 1
            
            row.append(z)
        texels.append(row)
    # print("minZ: " + str(minZ))
    # print("maxZ: " + str(maxZ))
    # print("Average Z: " + (str(cumulativeZ/count)))
    return texels
コード例 #29
0
def create_trees(pmap, spawn_rate, x_offset, y_offset):

    def mergeable(x, y):
        if (x, y - 1) not in pmap.ground_layer.keys() and (x + 1, y - 1) not in pmap.ground_layer.keys():
            if pmap.get_tile("ground_layer", x, y) == ("na", 2, 2) and pmap.get_tile("ground_layer", x + 1, y) == ("na", 2, 2):
                if pmap.get_tile("secondary_ground", x, y - 1) == ("na", 2, 1) and pmap.get_tile("secondary_ground", x + 1, y - 1) == ("na", 2, 1):
                    return True
        return False

    octaves = 2
    freq = 40
    for y in range(pmap.height):
        for x in range(pmap.width):
            if pmap.tile_heights.get((x, y), -1) <= pmap.highest_path:
                if (x, y) not in pmap.ground_layer.keys() and (x, y) not in pmap.secondary_ground.keys() and (x, y - 1) not in pmap.secondary_ground.keys() and (x, y) not in pmap.buildings.keys() and (x, y) not in pmap.decoration_layer.keys() and (x, y - 1) not in pmap.decoration_layer.keys():
                    if abs(snoise2((x + x_offset) / freq, (y + y_offset) / freq, octaves)) * 2 > 1 - (spawn_rate / 100) and random.random() > 0.5:
                        pmap.decoration_layer[(x, y - 2)] = ("na", 2, 0)
                        pmap.secondary_ground[(x, y - 1)] = ("na", 2, 1)
                        pmap.ground_layer[(x, y)] = ("na", 2, 2)

    for y in range(pmap.height):
        for x in range(pmap.width):
            if mergeable(x, y):
                pmap.decoration_layer[(x, y - 2)] = ("na", 1, 5)
                pmap.decoration_layer[(x + 1, y - 2)] = ("na", 2, 5)
                pmap.secondary_ground[(x, y - 1)] = ("na", 1, 6)
                pmap.secondary_ground[(x + 1, y - 1)] = ("na", 2, 6)
                pmap.ground_layer[(x, y)] = ("na", 1, 7)
                pmap.ground_layer[(x + 1, y)] = ("na", 2, 7)
コード例 #30
0
    def create_heightmap(self, _freq_multiplier, _octaves):
        freq = self.size_x * _freq_multiplier
        offset = round((random() + random()) * 100000)
        # _min, _max = 1000, 0
        for k in range(self.size_y):
            for i in range(self.size_x):
                self.height[i, k] = round((1 + snoise2(
                    (i + offset) / freq,
                    (k + offset) / freq, octaves=_octaves)) *
                                          (self.stepping / 2))
                self.colormap[i, k] = Tools.get_color(self.height[i, k],
                                                      self.stepping,
                                                      self.waterlvl,
                                                      self.grasslvl)
                # _min = self.height[i, k] if self.height[i, k] < _min else _min
                # _max = self.height[i, k] if self.height[i, k] > _max else _max

        print('-' * 24)
        print('Distribution of heights:')
        _terrain = ['Water', 'Forest', 'Mountain']
        _prop_heights = Tools.get_prop_heights()
        for i in _prop_heights:
            print(
                _terrain[i].zfill(10).replace('0', ' '), '->',
                round((_prop_heights[i] * 100) / (self.size_x * self.size_y),
                      2), '%')
        print('-' * 24)
コード例 #31
0
 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))
コード例 #32
0
ファイル: randomdraw2.py プロジェクト: enra64/iot-ledmatrix
    def update(self, canvas):
        # count the number of neighbours
        canvas.clear()
        for x in range(0, canvas.width):
            for y in range(0, canvas.height):
                noise = int(
                    snoise2((x + self.xoff) / self.freq, y /
                            self.freq, self.octaves) * 127.0 + 128.0)
                if (noise > 200):
                    canvas.draw_pixel(x, y, Color(1, 41, 95))
                elif (noise > 170):
                    canvas.draw_pixel(x, y, Color(67, 127, 151))
                elif (noise > 140):
                    canvas.draw_pixel(x, y, Color(132, 147, 36))
                elif (noise > 110):
                    canvas.draw_pixel(x, y, Color(255, 179, 15))
                elif (noise > 80):
                    canvas.draw_pixel(x, y, Color(253, 21, 27))
                elif (noise > 50):
                    canvas.draw_pixel(x, y, Color(181, 189, 104))
                elif (noise > 20):
                    canvas.draw_pixel(x, y, Color(245, 151, 78))
                elif (noise > 0):
                    canvas.draw_pixel(x, y, Color(241, 85, 65))

        self.xoff += 1
コード例 #33
0
ファイル: util.py プロジェクト: sheppard/bg
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
コード例 #34
0
    def fill_map(cls, sim_map, octaves, freq, persistence, nb_clusters, seed):
        """Met à jour l'état de la grille.

        Calcule le bruit de Perlin pour chaque position x et y dans la
        grille et selon l'unité de temps actuelle. L'unité de temps est
        un entier itérant à l'infini dans un intervalle arbitraire (ici
        0..W).

        Une fois le bruit calculé pour une position, teste si la valeur
        de cette position a changé et si c'est le cas, met à jour les
        pixels de l'image correspondants à cette position.
        """

        for index, _ in ndenumerate(sim_map.grid):
            x, y = index

            i = cls.normalize(float(x), float(sim_map.width))
            j = cls.normalize(float(y), float(sim_map.height))

            noise = snoise2(i / freq,
                            j / freq,
                            persistence=persistence,
                            octaves=octaves,
                            base=seed)
            id_cluster = floor(cls.normalize(noise, -1, +1) * nb_clusters)
            sim_map.grid[x][y] = int(id_cluster)
コード例 #35
0
ファイル: random.py プロジェクト: whutch/cwmud
def generate_noise(x, y=0, z=None, w=None, scale=1, offset_x=0.0, offset_y=0.0,
                   octaves=1, persistence=0.5, lacunarity=2.0):
    """Generate simplex noise.

    :param x: The x coordinate of the noise value
    :param y: The y coordinate of the noise value
    :param z: The z coordinate of the noise value
    :param w: A fourth dimensional coordinate
    :param scale: The scale of the base plane
    :param float offset_x: How much to offset `x` by on the base plane
    :param float offset_y: How much to offset `y` by on the base plane
    :param int octaves: The number of passes to make calculating noise
    :param float persistence: The amplitude multiplier per octave
    :param float lacunarity: The frequency multiplier per octave

    """
    x = (x + offset_x) / scale
    y = (y + offset_y) / scale
    if z is not None:
        z /= scale
    if w is not None:
        w /= scale
    if z is None and w is None:
        return noise.snoise2(x, y, octaves=octaves,
                             lacunarity=lacunarity,
                             persistence=persistence)
    elif w is None:
        return noise.snoise3(x, y, z, octaves=octaves,
                             lacunarity=lacunarity,
                             persistence=persistence)
    else:
        return noise.snoise4(x, y, z, w, octaves=octaves,
                             lacunarity=lacunarity,
                             persistence=persistence)
コード例 #36
0
ファイル: sim.py プロジェクト: hershkumar/terrain
def generate_heightmap(mapsize, method):
    heightmap = np.zeros((mapsize, mapsize))
    if (method == "perlin"):
        offset = randint(0, (mapsize - 1))
        print("Generating Perlin Terrain...")
        for x in range(mapsize):
            for y in range(mapsize):
                heightmap[x][y] = noise.snoise2(x / (mapsize - 1) + offset,
                                                y / (mapsize - 1) + offset,
                                                octaves=4) * 128 + 128
    if (method == "worley"):
        print("Generating Worley Terrain...")
        NUM_PTS = 50
        N = 0
        wp_ys = np.zeros((NUM_PTS))
        wp_xs = np.zeros((NUM_PTS))
        for i in range(NUM_PTS):
            wp_ys[i] = randint(0, (mapsize - 1))
            wp_xs[i] = randint(0, (mapsize - 1))
        for x in range(mapsize):
            for y in range(mapsize):
                distances = [
                    hypot(wp_xs[i] - x, wp_ys[i] - y) for i in range(NUM_PTS)
                ]
                distances.sort()
                heightmap[x][y] = (mapsize - 1) - (
                    2 * (mapsize - 1) * distances[N] / distances[-1] +
                    (mapsize - 1) / 1.25 * distances[N + 1] / distances[-1] +
                    (mapsize - 1) / 1.5 * distances[N + 2] / distances[-1] +
                    (mapsize - 1) / 1.75 * distances[N + 3] / distances[-1])
    print("Complete!")
    return heightmap
コード例 #37
0
def TempList(width,
             height,
             xoff,
             yoff,
             scale=.012,
             octaves=2,
             persistence=.2,
             lacunarity=4):
    start_time = time.clock()
    tlist = [[0 for i in range(width * 2)] for j in range(height)]
    miny = 1
    maxy = 0
    for x in range(width * 2):
        for y in range(height):
            lat = 2.0 * abs((1.0 * y / height) - 0.5)
            triglat = math.cos(math.asin(lat))
            tlist[y][x] = triglat**2 * (snoise2(
                (x + xoff) * scale, (y + yoff) * scale, octaves, persistence,
                lacunarity, width * scale) + 1) / 2
            #tlist[y][x] = triglat**5
            if tlist[y][x] < miny: miny = tlist[y][x]
            if tlist[y][x] > maxy: maxy = tlist[y][x]
            #noise2(x, y, octaves=1, persistence=0.5, lacunarity=2.0, repeatx=1024, repeaty=1024, base=0.0)
    print "TempList created,", time.clock() - start_time, "SECONDS"
    #print "Miny", miny, "Maxy",maxy
    return tlist
コード例 #38
0
def create_noise_map(size, freq, octaves):
    nmap = []
    freq *= octaves
    for x in range(size):
        for y in range(size):
            nmap.append(snoise2(x/freq, y/freq, octaves))
    return nmap
コード例 #39
0
ファイル: worldgen.py プロジェクト: gumptiousCreator/dmtools
def get_elevation(x, y, seed=0):
    e = 0
    e += DETAIL*snoise2(CONTINENT_SCALE*x, CONTINENT_SCALE*y,
        octaves=PERLIN_OCTAVES,
        persistence=PERLIN_PERSISTENCE, lacunarity=PERLIN_LACUNARITY,
        base=seed, repeatx=MAP_WIDTH*CONTINENT_SCALE)
    return e
コード例 #40
0
ファイル: generation.py プロジェクト: woodbury/worldengine
def add_noise_to_elevation(world, seed):
    octaves = 6
    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
コード例 #41
0
ファイル: generation.py プロジェクト: fr33k3r/worldengine
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.layers['elevation'].data[y, x] += n
コード例 #42
0
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
コード例 #43
0
ファイル: generation.py プロジェクト: Mindwerks/worldengine
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.layers['elevation'].data[y, x] += n
コード例 #44
0
ファイル: worldNoise.py プロジェクト: traeger/_
 def __getitem__(self, idx):
   x, y, zoom = idx
   return snoise2(
     (self.xseed + (x)*zoom) / self.frequency,
     (self.yseed + (y)*zoom) / self.frequency,
     self.octaves
   )
コード例 #45
0
ファイル: game.py プロジェクト: tuomas56/bug-free-train
	def get_height(self, x, y):
		if 0 < y < self.world.height or 0 < x < self.world.width:
			height = abs(noise.snoise2(self.seed + x / 64, self.seed + y / 64, 1))
			height = int(height*255)
			return height
		else:
			return 0
コード例 #46
0
ファイル: test.py プロジェクト: Connor124/Gran-Theft-Crop-Toe
 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))
コード例 #47
0
ファイル: mapGenerator2.py プロジェクト: Dirvann/randemon
        def random_grass():
            def choose_sne_type(excluded_sne):
                sne_type = random.randint(0, self.NB_SNE)
                while sne_type in excluded_sne:
                    sne_type = random.randint(0, self.NB_SNE)

                # Turn 80 percent of the flowers into tall grass
                if sne_type == 2 and random.random() < 0.8: sne_type = 0
                # Turn 0.5 percent of the tall grass into tall grass with a hidden item
                if sne_type == 0 and random.random() < 0.005: sne_type = "0_p"

                return "sne_" + str(sne_type)

            octaves = 1
            freq = 7
            sne_probability = snoise2((x + x_offset) / freq,
                                      (y + y_offset) / freq, octaves) + 0.5

            if sne_probability > (
                    self.tall_grass_coverage /
                    100) or "l_1" in self.decoration_layer.get(
                        (x, y), "") or "l_5" in self.decoration_layer.get(
                            (x, y), ""):
                grass_type = random.randint(0, 3)
                return "g_" + str(grass_type)
            else:
                return choose_sne_type(self.EXCLUDED_SNE)
コード例 #48
0
def generate_simplex_row(x,
                         size,
                         scale=100.0,
                         octaves=6,
                         persistence=0.5,
                         base=0.0):
    """
    generate_simplex_row - function of generating one row of simplex noise.
    :param x: number of row, just for purposes of generation 2d array
    :param size: size of the main array, here it is size of the row
    :param scale: for controlling speed of changes in the array
    :param octaves: number of layers, each with more detail
    :param persistence: influence of each octave on the main one
    :param base: seed for the array generation (same seed - same output)
    :return: list of simplex noise values, of given size
    """
    noise_row = []
    x_scale = x / scale
    for y in range(size):
        noise_row.append(
            snoise2(x_scale,
                    y / scale,
                    octaves=octaves,
                    persistence=persistence,
                    base=base))
    return noise_row
コード例 #49
0
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
コード例 #50
0
    def getBarricades(self,
                      octaves=1,
                      persistence=0.5,
                      lacunarity=2.0,
                      sensitivity=0.65,
                      scale=0.05,
                      underworld=False):
        barricades = {}

        for y in range(0, self.height):
            for x in range(0, self.width):
                if noise.snoise2(x * scale * 3,
                                 y * scale * 3,
                                 persistence=persistence,
                                 lacunarity=lacunarity,
                                 octaves=octaves) > sensitivity:
                    if not underworld:  # Generate for overworld
                        if not self.overworld[y][x] in ["#", "H"]:
                            barricades[f"{y}/{x}"] = Barricade(
                                y, x, f"{y}/{x}", 0
                            )  # Assign id to each barricade based on initial coordinates
                    else:  # Generate for underworld
                        if not self.underworld[y][x] in ["#", "H"]:
                            barricades[f"{y}/{x}"] = Barricade(
                                y, x, f"{y}/{x}", 1
                            )  # Assign id to each barricade based on initial coordinates

        return barricades
コード例 #51
0
ファイル: generation.py プロジェクト: tmfoltz/worldengine
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
コード例 #52
0
ファイル: main.py プロジェクト: tps12/Generation-Generation
def noiseat(x, y):
    global dx
    global dy
    return 1 + noise.snoise2(
            (x+dx)/10.0,
            (y+dy)/800.0,
            24,
            1)
コード例 #53
0
def get_noise(octaves=42, width=256, height=256):
    freq = 16.0 * octaves
    output = []

    for y in range(height):
        for x in range(width):
            output.append(int(noise.snoise2(x / freq, y / freq, octaves) * 127.0 + 128.0))
    return output
コード例 #54
0
ファイル: test.py プロジェクト: Connor124/Gran-Theft-Crop-Toe
 def test_simplex_2d_octaves_range(self):
     from noise import snoise2
     for i in range(-1000, 1000):
         for o in range(10):
             x = -i * 0.49
             y = i * 0.67
             n = snoise2(x, y, octaves=o + 1)
             self.assertTrue(-1.0 <= n <= 1.0, (x, n))
コード例 #55
0
ファイル: world.py プロジェクト: naderm/lakeception
 def getElevationAtPoint(self, point):
     # Scale position and world dimensions according to elevation scaling value
     x, y, worldWidth, worldHeight = [e*self.elevationScale for e in point+self.dimensions]
     noiseValue = noise.snoise2(x, y, octaves=10, repeatx=worldWidth, repeaty=worldHeight)
     
     # noiseValue is [-1.0, +1.0], so let's rescale and quantize it over [0, 20]
     elevation = int(round((noiseValue + 1) * 10))
     
     return elevation
コード例 #56
0
ファイル: geo.py プロジェクト: SourceRyan/lands
def elevnoise(elevation, seed):
    width = len(elevation[0])
    height = len(elevation)

    octaves = 6
    freq = 16.0 * octaves
    for y in range(0, height):
        for x in range(0, width):
            n = int(snoise2(x / freq * 2, y / freq * 2, octaves, base=seed))
            elevation[y][x] += n
コード例 #57
0
ファイル: terrain.py プロジェクト: Exodus111/Projects
def make_array(oct, scale, wlevel=False, lac=2.0):
    array = np.zeros((size, size), np.float32)
    val = random.randint(0, 256)
    for y in xrange(size):
        for x in xrange(size):
            v = snoise2(x * scale, y * scale, oct, persistence=.5, lacunarity=lac, base = val)
            if wlevel != False:
                v = add_waterlevel(v, wlevel)
            array[x, y] += v
    return array
コード例 #58
0
def generateNoise(resolution, octaves, frequency):
    arr = list()

    for x in range(resolution):
        arr.append(list())
        for y in range(resolution):
            sample = snoise2(x / frequency, y / frequency, octaves) + 0.5
            arr[x].append(sample)

    return arr
コード例 #59
0
ファイル: my_noise.py プロジェクト: Pellanor/proc-dungeon-py
def simplex_noise_1d(i, seed=0, octaves=1, freq_ratio=16.0) -> float:
    """
    Create simplex noise between 0 and 1
    :param i: index of the noise
    :param seed: seed to use
    :param octaves: higher number makes the noise smoother
    :param freq_ratio: how often to sample as the ratio changes
    :return: float between 0 and 1
    """
    freq = octaves * freq_ratio
    return (noise.snoise2(seed, i / freq, octaves) + 1) / 2
コード例 #60
0
def generate(resolution, octaves, frequency):
    img = Image.new('RGB', (resolution, resolution), "black")
    pixels = img.load()

    for x in range(img.size[0]):
        for y in range(img.size[1]):
            sample = int(snoise2(x / frequency, y / frequency, octaves) * 127 + 128)
            color = (sample, sample, sample)
            pixels[x, y] = color

    return img