Answer the question
In order to leave comments, you need to log in
What's wrong with sine?
I wanted to make a similar wave effect :
For this I used the following algorithm:
for (int y = 0; y < img.Height; ++y)
{
Span<Rgba32> pixelRowSpan = img.GetPixelRowSpan(y);
for (int x = 0; x < img.Width; ++x)
{
int y1 = Convert.ToInt32(y + 20.0 * Math.Sin(x / 32.0));
if (y1 >= img.Height)
y1 = img.Height - 1;
if (y1 < 0)
y1 = 0;
var sourcePixel = img.GetPixelRowSpan(y1)[x];
pixelRowSpan[x] = sourcePixel;
}
}
Answer the question
In order to leave comments, you need to log in
You change the image in place by walking over it from top to bottom. When your sine shifts the pixels down, you overwrite all the pixels in the topmost column.
It is necessary either to copy with changes to a new image, or to change the direction of the passage depending on the sign of the sine.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question