void add(uint[] buffer, int width, int height, Texture texture, int posx, int posy, int xsize, int ysize) { var w = xsize; var h = ysize; var xBase = posx; var yBase = posy; var tx = texture.width * 255; var ty = texture.height * 255; var tw = texture.width; var dtx = tx / w; var dty = ty / h; var txBase = MathUtility.Crop(-xBase * dtx, 0, 255 * tx); var tyBase = MathUtility.Crop(-yBase * dty, 0, 255 * ty); var xend = MathUtility.Crop(xBase + w, 0, width); var yend = MathUtility.Crop(yBase + h, 0, height); int pos, offset1, offset2; xBase = MathUtility.Crop(xBase, 0, width); yBase = MathUtility.Crop(yBase, 0, height); ty = tyBase; for (var j = yBase; j < yend; j++) { tx = txBase; offset1 = j * width; offset2 = (ty >> 8) * tw; for (var i = xBase; i < xend; i++) { buffer[i + offset1] = ColorUtility.add(texture.pixel[(tx >> 8) + offset2], pixel[i + offset1]); tx += dtx; } ty += dty; } }
public Texture colorize(uint[] pal) { var range = (uint)pal.Length - 1; for (var i = width * height - 1; i >= 0; i--) { pixel[i] = pal[MathUtility.Crop(pixel[i], 0, range)]; } return(this); }
public Texture valToGray() { uint intensity; for (var i = width * height - 1; i >= 0; i--) { intensity = MathUtility.Crop(pixel[i], 0, 255); pixel[i] = ColorUtility.getColor(intensity, intensity, intensity); } return(this); }
// Perlin noise functions static float perlin2d(float x, float y, float wavelength, float persistence, int samples) { float sum = 0; var freq = 1f / wavelength; var amp = persistence; float range = 0; for (var i = 0; i < samples; i++) { sum += amp * interpolatedNoise(x * freq, y * freq, i); range += amp; amp *= persistence; freq *= 2; } return(MathUtility.Crop(sum / persistence * 0.5f + 0.5f, 0, 1)); }
public void setReflectivity(uint factor) { reflectivity = MathUtility.Crop(factor, 0, 255); }
public void setTransparency(uint factor) { transparency = MathUtility.Crop(factor, 0, 255); opaque = (transparency == 0); }