2017-06-13 16 views
0

私は、3色のグラデーションがグラデーションされていると想像してください:ダークレッド、レッド、ライトレッド。私はその行のこれらの色の位置を変更したい。私の目的は、何かが線に沿って動いていることを示している。 わかりませんグラデーションカラーの線で各色の位置を変更するアニメーションを作成する方法を教えてください。 https://docs.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/how-to-animate-the-position-or-color-of-a-gradient-stopC#のライン上のグラデーションの色をアニメーション化する

をしかし、それはあまりにも明らかではない。

enter image description here

私はこれを発見しました。ここ

+0

winformsでは、LinearGradientBrushを使用し、Tickイベントで開始点を外側に移動することができます。 – TaW

+1

私はそれを追加しました。 @TaW –

答えて

2

は一例であり:それは左定義矩形トップの開始点を移動させる、LineraGradientBrushを使用

enter image description here

を塗装PictureBox矩形を回転:

Point p1 = Point.Empty; 

private void timer1_Tick(object sender, EventArgs e) 
{ 
    int deltaX = -3; 
    int deltaY = -3; 
    p1 = new Point(p1.X + deltaX , p1.Y + deltaY); // roll.. 
    if (p1.X < deltaX * 1000) p1 = Point.Empty; // ..around 
    pictureBox1.Invalidate(); 

} 

private void pictureBox1_Paint(object sender, PaintEventArgs e) 
{ 
    float angle = 33f; 
    if (!timer1.Enabled) return; 
    Rectangle rectG = new Rectangle(p1.X, p1.Y, 122, 22); 
    Rectangle rectR = new Rectangle(22, 22, 222, 22); 
    LinearGradientBrush lBrush = new LinearGradientBrush(rectG, 
            Color.Red, Color.Red, angle, false); 

    ColorBlend cblend = new ColorBlend(5); 
    cblend.Colors = new Color[5] 
     { Color.Red, Color.Pink, Color.MistyRose, Color.LightCoral, Color.White }; 
    cblend.Positions = new float[5] { 0f, 0.2f, 0.5f, 0.8f, 1f }; 
    lBrush.InterpolationColors = cblend; 
    lBrush.WrapMode = WrapMode.TileFlipXY; 

    e.Graphics.RotateTransform(angle); 
    e.Graphics.TranslateTransform(22,11); 
    e.Graphics.FillRectangle(lBrush, rectR); 
} 

これはWinformsなので、実際のスムーズなアニメーションを得ることはできませんが、描画するコントロール/フォームがleaの場合はDoubleBuferedそれはちらつくことはありません..

関連する問題