About Me
Portfolio
Résumé
Contact
I wrote this C# code for
Paint.NET
, an open source image editing program.
It applies this water reflection effect to the lower half of the currently open image. It's somewhat like a Photoshop "filter."
Code:
float RippleFrequency = 10f; //0+ float RippleAmplitude = 100; //0 to 100 (Percent) float RippleSizeChange = 1; //0+ float anglecoefficient; float cosinecoefficient; float sizechange; float yadj; float halfy; float maxy; float yoff; float height; ColorBgra color; void Render(Surface dst, Surface src, Rectangle rect) { maxy = (dst.Height - 1f) / 2; halfy = maxy / 2f; anglecoefficient = RippleFrequency / 1000; cosinecoefficient = RippleAmplitude * halfy / 100; sizechange = RippleSizeChange / 100; for(float y = rect.Top; y < rect.Bottom; y++) { for (float x = rect.Left; x < rect.Right; x++) { yoff = y - maxy; if (y >= maxy) { yadj = (int)(cosinecoefficient * Math.Cos(yoff * anglecoefficient * sizechange * (maxy * 2 - yoff))) + halfy; color.A = (byte)(256 - (yoff / maxy) * 256f); } else { yadj = y; } color = src.GetBilinearSample(x, yadj, true); dst[(int)x, (int)y] = color; } } }