public void Update()
        {
            double Mass1X = X0 + L1 * Math.Sin(Phi1);
            double Mass1Y = Y0 + L1 * Math.Cos(Phi1);
            double Mass2X = Mass1X + L2 * Math.Sin(Phi2);
            double Mass2Y = Mass1Y + L2 * Math.Cos(Phi2);

            SetSize(mass1, 2 * M1);
            SetSize(mass2, 2 * M2);
            SetPosition(mass1, Mass1X - M1, Mass1Y - M1);
            SetPosition(mass2, Mass2X - M2, Mass2Y - M2);
            SetPosition(Arm1, X0, Y0, Mass1X, Mass1Y);
            SetPosition(Arm2, Mass1X, Mass1Y, Mass2X, Mass2Y);

            var sp = new StylusPoint(Mass2X, Mass2Y);

            if (col == null || col.Count >= 1000)
            {
                var ncol = new StylusPointCollection();
                if (col != null)
                {
                    ncol.Add(col.Last());
                }
                ncol.Add(sp);
                stroke = new Stroke(ncol);
                stroke.DrawingAttributes.Color = Colors.Blue;
                _ink.Strokes.Add(stroke);
                col = ncol;
            }
            else
            {
                col.Add(sp);
            }
        }
Example #2
0
        private static StylusPointCollection Points(StylusPointCollection stylusPoints)
        {
            var start = stylusPoints.First().ToPoint();
            var end   = stylusPoints.Last().ToPoint();

            LineDynamicRenderer.Prepare(ref start, ref end);

            return(new StylusPointCollection(new[] { start, end }));
        }
Example #3
0
        private static StylusPointCollection Points(StylusPointCollection stylusPoints)
        {
            var start = stylusPoints.First().ToPoint();
            var end   = stylusPoints.Last().ToPoint();

            LineDynamicRenderer.Prepare(ref start, ref end);

            ArrowDynamicRenderer.GetArrowPoints(start, end, out var p1, out var p2);

            return(new StylusPointCollection(new[] { start, end, p1, end, p2 }));
        }
Example #4
0
        public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points)
        {
            Point  pt = (Point)points.Last();
            Vector v  = Point.Subtract(pt, first);

            if (v.Length > 4)
            {
                dc.DrawLine(tool.inkPen, first, pt);
            }
            return(first);
        }
Example #5
0
        public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points)
        {
            Point  pt = (Point)points.Last();
            Vector v  = Point.Subtract(pt, first);

            if (v.Length > 4)
            {
                Rect rect = new Rect(first, v);
                dc.DrawImage(bi, rect);
            }
            return(first);
        }
Example #6
0
        static StylusPointCollection Points(StylusPointCollection StylusPointCollection)
        {
            var start = StylusPointCollection.First().ToPoint();
            var end   = StylusPointCollection.Last().ToPoint();

            RectangleDynamicRenderer.Prepare(ref start, ref end, out var w, out var h);

            var center = new Point(start.X + w / 2, start.Y + h / 2);

            var stylusPoints = new StylusPointCollection();

            const double step = 0.05;

            var arc1 = new List <StylusPoint>();
            var arc2 = new List <StylusPoint>();
            var arc3 = new List <StylusPoint>();
            var arc4 = new List <StylusPoint>();

            for (var dx = 0.0; dx < w / 2; dx += step)
            {
                var dy = (h / 2) * Math.Sqrt(1 - Math.Pow(2 * dx / w, 2));

                arc1.Add(new StylusPoint(center.X + dx, center.Y + dy));
                arc2.Add(new StylusPoint(center.X - dx, center.Y + dy));
                arc3.Add(new StylusPoint(center.X - dx, center.Y - dy));
                arc4.Add(new StylusPoint(center.X + dx, center.Y - dy));
            }

            foreach (var point in arc1.AsEnumerable().Reverse())
            {
                stylusPoints.Add(point);
            }

            foreach (var point in arc2)
            {
                stylusPoints.Add(point);
            }

            foreach (var point in arc3.AsEnumerable().Reverse())
            {
                stylusPoints.Add(point);
            }

            foreach (var point in arc4)
            {
                stylusPoints.Add(point);
            }

            stylusPoints.Add(arc1[arc1.Count - 1]);

            return(stylusPoints);
        }
Example #7
0
        static StylusPointCollection Points(StylusPointCollection StylusPointCollection)
        {
            var start = StylusPointCollection.First().ToPoint();
            var end   = StylusPointCollection.Last().ToPoint();

            RectangleDynamicRenderer.Prepare(ref start, ref end, out var w, out var h);

            return(new StylusPointCollection(new []
            {
                start,
                new Point(start.X, end.Y),
                end,
                new Point(end.X, start.Y),
                start
            }));
        }
Example #8
0
        public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points)
        {
            Point  pt      = (Point)points.Last();
            Vector v       = Point.Subtract(pt, first);
            double radiusX = (pt.X - first.X) / 2.0;
            double radiusY = (pt.Y - first.Y) / 2.0;
            Point  center  = new Point((pt.X + first.X) / 2.0, (pt.Y + first.Y) / 2.0);

            if (tool.inkDrawOption == InkDrawOption.仅填充)
            {
                dc.DrawEllipse(tool.inkBrush, null, center, radiusX, radiusY);
            }
            else if (tool.inkDrawOption == InkDrawOption.仅轮廓)
            {
                dc.DrawEllipse(null, tool.inkPen, center, radiusX, radiusY);
            }
            else
            {
                dc.DrawEllipse(tool.inkBrush, tool.inkPen, center, radiusX, radiusY);
            }
            return(first);
        }
Example #9
0
        public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points)
        {
            Point  pt = (Point)points.Last();
            Vector v  = Point.Subtract(pt, first);

            if (v.Length > 4)
            {
                Rect rect = new Rect(first, v);
                if (tool.inkDrawOption == InkDrawOption.仅填充)
                {
                    dc.DrawRectangle(tool.inkBrush, null, rect);
                }
                else if (tool.inkDrawOption == InkDrawOption.仅轮廓)
                {
                    dc.DrawRectangle(null, tool.inkPen, rect);
                }
                else
                {
                    dc.DrawRectangle(tool.inkBrush, tool.inkPen, rect);
                }
            }
            return(first);
        }
Example #10
0
        //this event is not raised when stroke object is added programatically but rather when the pen is lifted up
        protected override void OnStrokeCollected(InkCanvasStrokeCollectedEventArgs e)
        {
            void addStroke(StylusPointCollection c, bool h, out StylusPointCollection tspc)
            {
                DrawingAttributes d = new DrawingAttributes();

                //change color acc to earlier hitstate
                if (h == true)
                {
                    d.Color = Colors.LightGreen;
                }
                else if (h == false)
                {
                    d.Color = Colors.Red;
                }
                Stroke stroke = new Stroke(c, d);

                this.Strokes.Add(stroke);
                tspc = new StylusPointCollection();
            }

            //if stroke is checked and the hit points are not null
            if (hitChangedPoints.Count != 0)
            {
                StudentStrokeCount += 1;
                //Debug.WriteLine("StudentIC / StudentStrokeCount :" + StudentStrokeCount);
                //remove the stroke and instead create new stroke from _tempSPCollection at the end even though the PreviousColor may not have changed
                this.Strokes.Remove(e.Stroke);
                //stylus point collection that holds all the points in the arguements
                StylusPointCollection spc     = new StylusPointCollection(e.Stroke.StylusPoints);
                StylusPointCollection tempSPC = new StylusPointCollection();
                bool HitStateChanged          = false;
                for (int i = 0; i < spc.Count; i++)
                {
                    tempSPC.Add(spc[i]);
                    //if its the first iteration
                    if (i == 0)
                    {
                        HitStateChanged = hitChangedPoints.Contains(spc[i].ToPoint());
                        continue;
                    }
                    //if its the last point
                    if (i == spc.Count - 1)
                    {
                        addStroke(tempSPC, HitStateChanged, out tempSPC);
                        return;
                    }
                    //if the stroke hit state has changed
                    bool tempHitCheck = hitChangedPoints.Contains(spc[i].ToPoint());
                    if (tempHitCheck != HitStateChanged)
                    {
                        //pass it to the new collection for continuation
                        StylusPoint tempSPholder = tempSPC.Last();
                        addStroke(tempSPC, HitStateChanged, out tempSPC);
                        tempSPC.Add(tempSPholder);
                        HitStateChanged = tempHitCheck;
                    }
                }
            }
            hitChangedPoints = new List <Point>();
        }
 protected override void OnDraw(DrawingContext drawingContext, StylusPointCollection stylusPoints, Geometry geometry, Brush fillBrush)
 {
     drawingContext.DrawRectangle(new SolidColorBrush(Colors.Black), null, new Rect(firstPoint, (Point)stylusPoints.Last()));
 }