Search Unity

Implemented Diamond-Square algorithm, want to visualize it

Discussion in '2D' started by harrisonn, Jul 21, 2014.

  1. harrisonn

    harrisonn

    Joined:
    Jul 18, 2014
    Posts:
    2
    Thanks in advance for the help.

    So, my Diamond-square algorithm generates a 2D array of floats,

    Code (CSharp):
    1. float[arrSize, arrSize] ds;
    Basically, what I want to do is somehow visualize these values similar to this:


    The first thing I tried was something like this:

    Code (CSharp):
    1. Texture2D texture = new Texture2D(mapSize, mapSize, TextureFormat.ARGB32, false);
    2. cols = new Color32 [mapSize * mapSize];
    3. Color32[] cols = new Color32(arrSize, arrSize);
    4. int index = 0;
    5.  
    6. for (int y = 0; y <arrSize; ++y)
    7. {
    8.      for (int x = 0; x <arrSize; ++x) {
    9.           cols[index] = computeColor(map[x,y]);
    10.          ++index;
    11.      }
    12. }
    13. texture.SetPixels32(cols);
    14. texture.Apply();
    15. renderer.material.mainTexture = texture;
    16.  
    and computeColor just returns a Color that depends on the range in which the float resides.

    The problem is when I go to run this script all I get is one single color when I double click the texture. So I don't think I'm doing it right.

    Anybody have any better suggestions?
     
  2. harrisonn

    harrisonn

    Joined:
    Jul 18, 2014
    Posts:
    2
    Nevermind, I fixed it. Thanks a lot!