Пример #1
0
        private void Reset()
        {
            _time   = 0.1f;
            _points = null;
            Random random = new Random((int)DateTime.Now.TimeOfDay.Ticks);

            _baseHue = (float)random.NextDouble();
            Invalidate();
        }
Пример #2
0
        public override List <Coordinate> ToCommonCoordinates(bool includeEndPoint)
        {
            // create a coordinate array containing the from-point, all the control points, and the to-point

            Coordinate[] c = new Coordinate[ControlPointArray.Length + 2];
            PointN       p = FromPoint as PointN;

            c[0] = new Coordinate(p.X, p.Y);

            ControlPointArray.Cast <PointN>().Select(o => o.ToCoordinate()).ToArray().CopyTo(c, 1);

            p = ToPoint as PointN;
            c[c.Length - 1] = new Coordinate(p.X, p.Y);

            // determine the number of points to interpolate

            int interpolateCount = 0;

            for (int i = 1; i < c.Length - 1; ++i)
            {
                double ax = c[i - 1].X - c[i].X;
                double ay = c[i - 1].Y - c[i].Y;
                double bx = c[i + 1].X - c[i].X;
                double by = c[i + 1].Y - c[i].Y;

                double dot = ax * bx + ay * by;
                double ad  = Math.Sqrt(ax * ax + ay * ay);
                double bd  = Math.Sqrt(bx * bx + by * by);

                double angle = Math.PI - Math.Abs(Math.Acos(dot / (ad * bd)));
                interpolateCount += Convert.ToInt32(Math.Floor(angle / SweepAngle));
            }

            // add the from-point to the output coordinates

            List <Coordinate> coords = new List <Coordinate>();

            coords.Add(c[0]);

            // add interpolated points along the Bezier curve to the output coordinates

            for (int i = 1; i < interpolateCount; ++i)
            {
                coords.Add(Interpolate(c, (double)i / interpolateCount));
            }

            // add the to-point to the output coordinates

            if (includeEndPoint)
            {
                coords.Add(c[c.Length - 1]);
            }

            return(coords);
        }
Пример #3
0
 private Task <List <Tuple <Geometry, Color> > > CreateGeometries(float time)
 {
     return(Task.Run(() =>
     {
         ControlPointArray temp = Points;
         int count = Points.Count;
         List <Tuple <Geometry, Color> > geometries = new List <Tuple <Geometry, Color> >();
         for (int index = 0; index < count - 1; ++index)
         {
             float hue = (_baseHue + (index + 1) / (float)(count + 1)) % 1;
             Vector4 hsv = new Vector4(hue, 1.0f, 1f, 1);
             Color rgba = XMath.ColorHsvToRgb(hsv);
             ControlPointArray array = temp.Reduce(time);
             geometries.Add(new Tuple <Geometry, Color>(array.CreateGeometry(_factory), rgba));
             temp = array;
         }
         return geometries;
     }));
 }