How to apply a tweener on a Line object?

Jun 18, 2010 at 10:25 PM
Edited Jun 18, 2010 at 10:37 PM

Hi!

I'm currently trying to use the Artefact Animator on a Line object, however, I can't seem to attach the X1, Y1, X2, Y2 objects. Is there any way to do this?
For now I'm using a hack which involves a second object and an update callback.

 

public Line bar = new Line();
public Ellipse ball = new Ellipse();

void myFunction()
{
    // Create local drawing canvas
    Canvas localCanvas = new Canvas();

    // Create ball
    ball.Width = 30;
    ball.Height = 30;
    ball.Stroke = System.Windows.Media.Brushes.Red;
    ball.Fill = System.Windows.Media.Brushes.Blue;
    Canvas.SetLeft(ball, 0);
    Canvas.SetTop(ball, 0);
    localCanvas.Children.Add(ball);
    
    // Create bar
    bar.Stroke = System.Windows.Media.Brushes.Red;
    bar.StrokeEndLineCap = bar.StrokeStartLineCap = PenLineCap.Round;
    bar.StrokeThickness = 2;
    bar.X1 = 0;
    bar.X2 = 0;
    bar.Y1 = 100;
    bar.Y2 = 0;
    localCanvas.Children.Add(bar);

    // create ease
    EaseObject easeObject = ArtefactAnimator.AddEase(ball, AnimationTypes.X, 250, 8.0, AnimationTransitions.BounceEaseInOut, 0.0);

    // add callback
    easeObject.Update += new EaseObjectHandler(UpdateHandler);           
}

// handle callback
void UpdateHandler(EaseObject easeObject, double percent)
{
    bar.X1 = Canvas.GetLeft(ball);
}


Nevermind figured it out already:

AnimationTypes.RegisterShortcut("X1", Line.X1Property);
ArtefactAnimator.AddEase(abc, "X1", 250, 8.0, AnimationTransitions.BounceEaseInOut, 0);

 

Coordinator
Aug 21, 2010 at 5:00 AM
Edited Aug 21, 2010 at 5:03 AM

Silverlight version.

public Line bar = new Line();

public MainPage()
{
    InitializeComponent();

    // Create bar
    bar.Stroke = new SolidColorBrush(Colors.Red);
    bar.StrokeEndLineCap = bar.StrokeStartLineCap = PenLineCap.Round;
    bar.StrokeThickness = 2;
    bar.X1 = 0;
    bar.X2 = 0;
    bar.Y1 = 100;
    bar.Y2 = 0;
    LayoutRoot.Children.Add(bar);

    MouseLeftButtonDown += _down;
}

double RandomDouble(double max)
{
    return new Random().NextDouble() * max;
}

void _down (object sender, MouseButtonEventArgs e)
{
    // single
    ArtefactAnimator.AddEase(bar, Line.X1Property, RandomDouble(40), .8);

    // multiple
    ArtefactAnimator.AddEase(bar,
        new object[] { Line.Y1Property, Line.X2Property, Line.Y2Property },
        new object[] { RandomDouble(40), RandomDouble(40), RandomDouble(40) }, 
        .4);
}