private void CalculateSection(int startIndex, int endIndex) { for (int i = startIndex; i < endIndex; i++) { for (int j = 0; j < _width; j++) { var value = Math.Max(0.0f, Math.Min(1.0, (double)Perlin.Function2D((double)i, (double)j) * 0.5 + 0.5)); // from 0.0 - 1.0 to 0 - 255 byte data value = value * 255; // assign values at rgb positions this[i, j] = (byte)value; } } }