贝塞尔曲线,【Silverlight】实现贝塞尔曲线动画

先看效果:(点击可全屏)
public void Step(double step) { Debug.Assert(_postion.Length == _vector.Length); for (int i = 0; i < _postion.Length; i++) { if (i % 3 == 0) { int j = i - 1; int k = i / 3; if (j < 0) j += _postion.Length; _postion[i].X = (_postion[j].X - _postion[i + 1].X) * Math.Abs(_r[k] - _splitPoint) + _postion[i + 1].X; _postion[i].Y = (_postion[j].Y - _postion[i + 1].Y) * Math.Abs(_r[k] - _splitPoint) + _postion[i + 1].Y; _r[k] = (_r[k] + 0.003) % (_splitPoint * 2); } else { _postion[i].X += _vector[i].X * step; _postion[i].Y += _vector[i].Y * step; if (_postion[i].X < 0) _vector[i].X = Math.Abs(_vector[i].X); if (_postion[i].Y < 0) _vector[i].Y = Math.Abs(_vector[i].Y); if (_postion[i].X > _screenWidth) _vector[i].X = -Math.Abs(_vector[i].X); if (_postion[i].Y > _screenHeight) _vector[i].Y = -Math.Abs(_vector[i].Y); } } var en = _postion.Select(s => new object[] { s.X, s.Y }).SelectMany(s => s); if (_postion.Length != 0) { string data = string.Format(_format, en.ToArray()); SplineModel line = new SplineModel(); line.Data = data; if (_currentColor >= _colorAnimation.Length) { string name = _colorAnimation.Last(); double A1 = int.Parse(name.Substring(1, 2), NumberStyles.HexNumber); double R1 = int.Parse(name.Substring(3, 2), NumberStyles.HexNumber); double G1 = int.Parse(name.Substring(5, 2), NumberStyles.HexNumber); double B1 = int.Parse(name.Substring(7, 2), NumberStyles.HexNumber); name = _availableColors[Tools.NextInt(_availableColors.Length)]; double A2 = int.Parse(name.Substring(1, 2), NumberStyles.HexNumber); double R2 = int.Parse(name.Substring(3, 2), NumberStyles.HexNumber); double G2 = int.Parse(name.Substring(5, 2), NumberStyles.HexNumber); double B2 = int.Parse(name.Substring(7, 2), NumberStyles.HexNumber); _colorAnimation = new string[_colorInterval]; for (int i = 0; i < _colorInterval; i++) { _colorAnimation[i] = string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", (int)((A2 - A1) * i / _colorInterval + A1), (int)((R2 - R1) * i / _colorInterval + R1), (int)((G2 - G1) * i / _colorInterval + G1), (int)((B2 - B1) * i / _colorInterval + B1) ); } _currentColor = 0; } line.ColorName = _colorAnimation[_currentColor++]; _lines.Add(line); } }
这其中有许多细节都没有说到,需要自行阅读代码理解。至于界面是怎么设计制作的?只是使用了基本的控件布局和 VSM 而已,使用 MVVM 模式。这些不是本文讲解的重点,不太了解的可以自行查看资料理解。
完整包下载地址:http://files.cnblogs.com/Aimeast/SLBezierSpline.zip
Tags: 

延伸阅读

最新评论

发表评论