使用Graphics.DrawCurve绘制easeInOutCubic曲线

时间:2017-06-12 19:07:31

标签: c#

如何使用Graphics.DrawCurve在.NET中绘制EaseInOutCubic曲线?

链接到我正在谈论的曲线的视觉效果 http://easings.net/#easeInOutCubic

我知道如何绘制一条简单的曲线,但我不明白如何专门绘制这种类型的曲线。我如何实现这一目标?

enter image description here

这是JS中曲线的等式,它很容易转换为C#。

// t: current time, b: begInnIng value, c: change In value, d: duration
easeInOutCubic: function (x, t, b, c, d) {
    if ((t/=d/2) < 1) return c/2*t*t*t + b;
    return c/2*((t-=2)*t*t + 2) + b;
},

样本C#绘制曲线:

private void DrawCurvePoint(PaintEventArgs e)
{

    // Create pens.
    Pen redPen = new Pen(Color.Red, 3);
    Pen greenPen = new Pen(Color.Green, 3);

    // Create points that define curve.
    Point point1 = new Point(50, 50);
    Point point2 = new Point(100, 25);
    Point point3 = new Point(200, 5);
    Point point4 = new Point(250, 50);
    Point point5 = new Point(300, 100);
    Point point6 = new Point(350, 200);
    Point point7 = new Point(250, 250);
    Point[] curvePoints = {point1, point2, point3, point4, point5, point6, point7};

    // Draw lines between original points to screen.
    e.Graphics.DrawLines(redPen, curvePoints);

    // Draw curve to screen.
    e.Graphics.DrawCurve(greenPen, curvePoints);
}

0 个答案:

没有答案