Got it!
Unfortunately, the script i use is really simple (i can't set the frequency and octaves number as input), i'll try using libnoise(maybe swig can do the magic) with python.
Btw now i understood how to generate the vegetation map.
The last question i have is:
once i know how many trees add in a tile, how can i calculate their coordinates(x,y)? I think a method could be iterate for each coord in the tile calling the perlin noise, and if the value is greater the, let's say, 0,5, put there a tree. But this is computationally heavy, i prefer to have a simpler method.. Do you have any idea?
(last time i bother you )
Ps: yes, the sin and cos where to change the values from integer
Well, the easy way to implement changing frequency is just to multiply your x and y coordinates by frequency before calling pnoise.
As far as determining the coordinates of a tree within a tile, this might not be as simple as calling a noise function, if you have to take into account keeping trees from overlapping each other. This becomes a physical modeling problem, and for this type of situation I like to use a hash of the tile coordinates to generate sequences of pseudo-random numbers that are deterministic per-tile. A simple example might be to use a FNV-1 hash + a basic seedable random number generator:
// FNV-1a hash
unsigned int fnv_hash(void *data, size_t size, unsigned int hash=2166136261)
{
for(unsigned char *p=(unsigned char *)data; p<(unsigned char *)data+size; ++p)
{
hash ^= *p;
hash *= 16777619;
}
return hash;
}
unsigned int hashTileCoords(unsigned int tx, unsigned int ty)
{
unsigned int tc[2]={tx,ty};
return fnv_hash((void *)tc, sizeof(unsigned int)*2);
}
Once you have hashed your tile coords to an unsigned int, use that unsigned int to seed a random number generator (for example, call srand() with the hash, then generate random numbers via rand()). This generates a sequence of random numbers that will always be the same sequence for a given tile coordinate, suitable for a streaming-type setup where you can't just globally seed a random generator and hope for sane results.
With this in hand, you can do something to scatter trees at randomized locations within a tile. You can iterate some number of times, generating randomized locations within the tile and checking for overlap with already-generated positions, until you have enough positions or the procedure fails because it can't find a suitable spot. Or you could place locations at evenly-spaced starting points, then use a series of random numbers, scaled to the range [-1,1] then multiplied by some kind of "wobble factor", to perturb the locations randomly from their starting location.