Procedurality.Channel.erodeThermal C# (CSharp) Method

erodeThermal() public method

public erodeThermal ( float talus, int iterations ) : Channel
talus float
iterations int
return Channel
		public Channel erodeThermal(float talus, int iterations) {
			float h, h1, h2, h3, h4, d1, d2, d3, d4, max_d;
			int i, j;
			for (int iter = 0; iter < iterations; iter++) {
				for (int y = 1; y < height - 1; y++) {
					for (int x = 1; x < width - 1; x++) {
						h = getPixel(x, y);
						h1 = getPixel(x, y + 1);
						h2 = getPixel(x - 1, y);
						h3 = getPixel(x + 1, y);
						h4 = getPixel(x, y - 1);
						d1 = h - h1;
						d2 = h - h2;
						d3 = h - h3;
						d4 = h - h4;
						i = 0;
						j = 0;
						max_d = 0f;
						if (d1 > max_d) {
							max_d = d1;
							j = 1;
						}
						if (d2 > max_d) {
							max_d = d2;
							i = -1;
							j = 0;
						}
						if (d3 > max_d) {
							max_d = d3;
							i = 1;
							j = 0;
						}
						if (d4 > max_d) {
							max_d = d4;
							i = 0;
							j = -1;
						}
						if (max_d < talus) {
							continue;
						}
						max_d *= 0.5f;
						putPixel(x, y, getPixel(x, y) - max_d);
						putPixel(x + i, y + j, getPixel(x + i, y + j) + max_d);
					}
				}
			}
			return this;
		}