public INoise Generate() { LockBitmap bitmap = new LockBitmap(new Bitmap(w, h)); const int featureSize = 16; values = new double[w * h]; for (int y = 0; y < h; y += featureSize) { for (int x = 0; x < h; x += featureSize) { SetSample(x, y, Randomizer.NextDouble() * 2 - 1); } } int stepSize = featureSize; double scale = 1.0f / w; double scaleMod = 1f; do { int halfStep = stepSize / 2; for (int y = 0; y < w; y += stepSize) { for (int x = 0; x < w; x += stepSize) { double a = Sample(x, y); double b = Sample(x + stepSize, y); double c = Sample(x, y + stepSize); double d = Sample(x + stepSize, y + stepSize); double e = (a + b + c + d) / 4.0 + (Randomizer.NextDouble() * 2 - 1) * stepSize * scale; SetSample(x + halfStep, y + halfStep, e); } } for (int y = 0; y < w; y += stepSize) { for (int x = 0; x < w; x += stepSize) { double a = Sample(x, y); double b = Sample(x + stepSize, y); double c = Sample(x, y + stepSize); double d = Sample(x + halfStep, y + halfStep); double e = Sample(x + halfStep, y - halfStep); double f = Sample(x - halfStep, y + halfStep); double H = (a + b + d + e) / 4.0 + (Randomizer.NextDouble() * 2 - 1) * stepSize * scale * 0.5; double g = (a + c + d + f) / 4.0 + (Randomizer.NextDouble() * 2 - 1) * stepSize * scale * 0.5; SetSample(x + halfStep, y, H); SetSample(x, y + halfStep, g); } } stepSize /= 2; scale *= (scaleMod + 0.8); scaleMod *= 0.3; } while (stepSize > 1); bitmap.Lock(); for (int i = 0; i < values.Length; i++) { double val = values[i]; int x = i % w; int y = i / w; byte c = (byte) Math.Abs(255 * val); Color col = Color.FromArgb(c, c, c); bitmap.SetPixel(x, y, col); } this.NoiseMap = bitmap.Unlock(); return this; }
public INoise Generate() { LockBitmap lockNoise = new LockBitmap(new Bitmap(Width, Height)); lockNoise.Lock(); noiseValues = new double[Width * Height]; Generate(0, 0, 0, 5, 5, 5, 5, 5, 5, 2); for (int i = 0; i < lockNoise.Height; i++) { int x = i % this.Width; int y = i / this.Width; byte cval = (byte) (255f * noiseValues[i]); Color col = Color.FromArgb(cval, cval, cval); lockNoise.SetPixel(x, y, col); } this.NoiseMap = lockNoise.Unlock(); return this; }
public INoise Generate() { LockBitmap lockNoise = new LockBitmap(new Bitmap(Width, Height)); lockNoise.Lock(); Random r = new Random(); for (int y = 0; y < lockNoise.Height; y++) { for (int x = 0; x < lockNoise.Width; x++) { int rStart = StartRange; int rEnd = EndRange; if (rStart > rEnd) { rStart = rEnd; rEnd = rStart; } Color col = Color.Black; int c1 = r.Next(rStart, rEnd); int c2 = r.Next(rStart, rEnd); int c3 = r.Next(rStart, rEnd); if (!R && !G && !B) col = Color.FromArgb(c1, c1, c1); if (R && !G && !B) col = Color.FromArgb(c2, c1, c1); if (!R && G && !B) col = Color.FromArgb(c1, c2, c1); if (!R && !G && B) col = Color.FromArgb(c1, c1, c2); if (R && G && !B) col = Color.FromArgb(c1, c2, c3); if (!R && G && B) col = Color.FromArgb(c1, c2, c3); if (R && !G && B) col = Color.FromArgb(c1, c2, c3); if (R && G && B) col = Color.FromArgb(c1, c2, c3); lockNoise.SetPixel(x, y, col); } } this.NoiseMap = lockNoise.Unlock(); return this; }