简体   繁体   中英

Image cosine wave

I need help with this problem that I am having. What I am trying to do is make an image move in a cosine wave pattern in C# Windows Forms, but whatever I try never works. This is what I have so far in the timer

dblX = (Double)picture.Left;
dblY = (Double)picture.Top;
dblY = Math.Cos(dblX);
picture.Top = dblY;
picture.Left +=10;

What this does is make the image flash and go up and down very quickly. Any suggestions?

Math.Cos期望弧度,因此您可能需要Math.Cos(dblX * Math.PI / 180)。

Math.Cos expects an argument in radians.

You are adding 10 radians each time. There are 2 * PI radians in a cycle.

As your picture moves right you probably want to take the Cosine of 2 * PI * (left / total width)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM