Search code examples
unity-game-enginetexturesprocedural-generation

Please explain this effect, Unity Textures


The following code was taken from here. How Does this Particular Line Work - texture.SetPixel(x, y, new Color((x + 0.5f) * stepSize % 0.1f, (y + 0.5f) * stepSize % 0.1f, 0f) * 10f); Multiplying Color with 10 and modulus with 0.1f is confusing me ?


Solution

  • All he's done in that line is have the color pattern repeat itself ten times over.

    By calculating the modulo with 0.1, each loop of 0 - 1 will yield ten values (0, 0.1, 0.2...)

    Further, by multiplying by 10, the color stays visible, and the result is the 10 x 10 grid pattern

    Just take a look at the images the author has put up