Using perelin noise to generate trees

I am stuck with a project and i want to generate a forest with perelin noise, on the black spots i want trees an on the white ones no. How can i get the pixel color an position? Please help :slight_smile:

I haven’t tested this, and there is definitely some improvements you can make to this script, but this should give you an idea of the direction to go:

public float averageTreeDistance = 10; //How far apart your trees should be
public float perlinScaling = 0.1f; //How big your perlin wave pattern is
public Vector2 perlinSeed; //Change this for a different pattern
public float treeSpawnThreshold = 0.5f; //If perlin value is bigger than this, spawn a tree
public float maxDistanceX = 500f; //Map size x
public float maxDistanceZ = 500f; //Map size z

void GeneratePerlinTrees(){
    for(float i = 0; i < maxDistanceX; i += averageTreeDistance){
        for(float j = 0; j < maxDistanceZ; j += averageTreeDistance){
            if(Mathf.PerlinNoise(perlinSeed.x + (i*perlinScaling), perlinSeed.y + (j*perlinScaling)) > treeSpawnThreshold){
                SpawnTree(new Vector3(i, 0, j)); //Spawn a tree at position