Search Unity

Creating a Float Gradient (World Generation using Noise and Fractals)

Discussion in '2D' started by LankyJon, Mar 21, 2018.

  1. LankyJon

    LankyJon

    Joined:
    Mar 18, 2018
    Posts:
    13
    Hello all. Just getting started with Unity, and really with coding, and am trying to work through how to create a randomly generated world with noise and fractals. I am more or less trying to follow along with this article (Accidental Noise Library). I understand all the concepts on a theoretical level, but getting them to work in Unity/C# is where I'm having trouble.

    I think the main problem I have, right at the moment is how to create a gradient of float values. That is, I can likely figure out how to create a gradient from white to black, but not how to create a gradient from 0 to 1. Once I have this gradient set up in a float[,], I can use a noise generator to adjust the values in that array. and then draw the world after that point.

    Any help would be greatly appreciated!
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    :D To me this sounds like "I'm just getting started with using a hammer, and really with building anything, and I'm trying to work through how to create the Taj Mahal in my garage." :) But I don't want to discourage you; you can certainly do it if you stick to it long enough.

    (Still, you might want to start with something more like Pong or Flappy Bird...)

    I'd love to see how you create a gradient from white to black — I would expect that to be a bit harder than a gradient of values from 0 to 1. I also don't understand how you want to fill a 2D array with an inherently 1D gradient. But maybe something like this:

    Code (csharp):
    1.  
    2. for (int x=0; x<100; x++) {
    3.    for (int y=0; y<100; y++) {
    4.      floatGradient[x,y] = (float)x/100;
    5.    }
    6. }
    HTH
    - Joe
     
  3. LankyJon

    LankyJon

    Joined:
    Mar 18, 2018
    Posts:
    13
    Meh. I suppose that might make sense, but I'd just go at this head on. I could make a fpong clone no problem. Flappy Bird would be harder, but... I guess I just don't feel like it.

    At any rate, this helps. I suppose I would just turn the gradient generation into its own method, using the world height (or a subset thereof) rather than 100.