Exemplo n.º 1
0
def _get_fov_type(fov):
    "Return a FOV from a string"
    oldFOV = fov
    fov = str(fov).upper()
    if fov in _FOVTYPES:
        return _FOVTYPES[fov]
    if fov[:10] == 'PERMISSIVE' and fov[10].isdigit() and fov[10] != '9':
        return 4 + int(fov[10])
    raise _tdl.TDLError('No such fov option as %s' % oldFOV)
Exemplo n.º 2
0
    def __init__(self,
                 algorithm='PERLIN',
                 mode='FLAT',
                 hurst=0.5,
                 lacunarity=2.0,
                 octaves=4.0,
                 seed=None,
                 dimensions=4):
        if algorithm.upper() not in _NOISE_TYPES:
            raise _tdl.TDLError('No such noise algorithm as %s' % algorithm)
        self._algorithm = algorithm.upper()

        if mode.upper() not in _NOISE_MODES:
            raise _tdl.TDLError('No such mode as %s' % mode)
        self._mode = mode.upper()

        if seed is None:
            seed = _random.getrandbits(32)
        try:
            seed = int(seed)
        except TypeError:
            seed = hash(seed)
        self._seed = seed
        # convert values into ctypes to speed up later functions
        self._dimensions = min(_MAX_DIMENSIONS, int(dimensions))
        if self._algorithm == 'WAVELET':
            self._dimensions = min(self._dimensions,
                                   3)  # Wavelet only goes up to 3
        self._random = _lib.TCOD_random_new_from_seed(
            _MERSENNE_TWISTER,
            _ffi.cast('uint32_t', self._seed),
        )
        self._hurst = hurst
        self._lacunarity = lacunarity
        self._noise = _lib.TCOD_noise_new(self._dimensions, self._hurst,
                                          self._lacunarity, self._random)
        _lib.TCOD_noise_set_type(self._noise, _NOISE_TYPES[self._algorithm])
        self._noiseFunc = _NOISE_MODES[self._mode]
        self._octaves = octaves
        self._useOctaves = (self._mode != 'FLAT')
        self._arrayType = 'float[%i]' % self._dimensions
Exemplo n.º 3
0
    def run(self):
        """Delegate control over to this App instance.  This function will
        process all events and send them to the special methods ev_* and key_*.

        A call to :any:`App.suspend` will return the control flow back to where
        this function is called.  And then the App can be run again.
        But a single App instance can not be run multiple times simultaneously.
        """
        if getattr(self, '_App__running', False):
            raise _tdl.TDLError('An App can not be run multiple times simultaneously')
        self.__running = True
        while self.__running:
            self.runOnce()
Exemplo n.º 4
0
    def __init__(self,
                 algorithm='PERLIN',
                 mode='FLAT',
                 hurst=0.5,
                 lacunarity=2.0,
                 octaves=4.0,
                 seed=None,
                 dimensions=4):
        """Create a new noise generator specifying a noise algorithm and how
        it's used.

        @type algorithm: string
        @param algorithm: The primary noise algorithm to be used.

                          Can be one of 'PERLIN', 'SIMPLEX', 'WAVELET'
                           - 'PERLIN' -
                             A popular noise generator.

                           - 'SIMPLEX' -
                             In theory this is a slightly faster generator with
                             less noticeable directional artifacts.

                           - 'WAVELET'
                             A noise generator designed to reduce aliasing and
                             not lose detail when summed into a fractal
                             (as with the 'FBM' and 'TURBULENCE' modes.)

                             This works faster at higher dimensions.

        @type mode: string
        @param mode: A secondary parameter to determine how noise is generated.

                     Can be one of 'FLAT', 'FBM', 'TURBULENCE'
                      - 'FLAT' -
                        Generates the simplest form of noise.
                        This mode does not use the hurst, lacunarity,
                        and octaves parameters.

                      - 'FBM' -
                        Generates fractal brownian motion.

                      - 'TURBULENCE' -
                        Generates detailed noise with smoother and more
                        natural transitions.

        @type hurst: float
        @param hurst: The hurst exponent describes the raggedness of the
                      resultant noise, with a higher value leading to a
                      smoother noise.
                      It should be in the 0.0-1.0 range.

                      This is only used in 'FBM' and 'TURBULENCE' modes.

        @type lacunarity: float
        @param lacunarity: A multiplier that determines how quickly the
                           frequency increases for each successive octave.

                           The frequency of each successive octave is equal to
                           the product of the previous octave's frequency and
                           the lacunarity value.

                           This is only used in 'FBM' and 'TURBULENCE' modes.

        @type octaves: float
        @param octaves: Controls the amount of detail in the noise.

                        This is only used in 'FBM' and 'TURBULENCE' modes.

        @type seed: object
        @param seed: You can use any hashable object to be a seed for the
                     noise generator.

                     If None is used then a random seed will be generated.
        """
        if algorithm.upper() not in _NOISE_TYPES:
            raise _tdl.TDLError('No such noise algorithm as %s' % algorithm)
        self._algorithm = algorithm.upper()

        if mode.upper() not in _NOISE_MODES:
            raise _tdl.TDLError('No such mode as %s' % mode)
        self._mode = mode.upper()

        if seed is None:
            seed = _random.getrandbits(32)
        else:
            seed = hash(seed)
        self._seed = seed
        # convert values into ctypes to speed up later functions
        self._dimensions = min(_MAX_DIMENSIONS, int(dimensions))
        if self._algorithm == 'WAVELET':
            self._dimensions = min(self._dimensions,
                                   3)  # Wavelet only goes up to 3
        self._random = _lib.TCOD_random_new_from_seed(_MERSENNE_TWISTER,
                                                      self._seed)
        self._hurst = hurst
        self._lacunarity = lacunarity
        self._noise = _lib.TCOD_noise_new(self._dimensions, self._hurst,
                                          self._lacunarity, self._random)
        _lib.TCOD_noise_set_type(self._noise, _NOISE_TYPES[self._algorithm])
        self._noiseFunc = _NOISE_MODES[self._mode]
        self._octaves = octaves
        self._useOctaves = (self._mode != 'FLAT')
        self._arrayType = 'float[%i]' % self._dimensions