Ejemplo n.º 1
0
        /// <summary>
        /// Draws the different types of shapes.
        /// </summary>
        private void DrawStaticShapes()
        {
            // Init some size vars
            int w    = this.writeableBmp.PixelWidth - 2;
            int h    = this.writeableBmp.PixelHeight - 2;
            int w3rd = w / 3;
            int h3rd = h / 3;
            int w6th = w3rd >> 1;
            int h6th = h3rd >> 1;

            // Clear
            writeableBmp.Clear();

            // Draw some points
            for (int i = 0; i < 200; i++)
            {
                writeableBmp.SetPixel(rand.Next(w3rd), rand.Next(h3rd), GetRandomColor());
            }

            // Draw Standard shapes
            writeableBmp.DrawLine(rand.Next(w3rd, w3rd * 2), rand.Next(h3rd), rand.Next(w3rd, w3rd * 2), rand.Next(h3rd), GetRandomColor());
            writeableBmp.DrawTriangle(rand.Next(w3rd * 2, w - w6th), rand.Next(h6th), rand.Next(w3rd * 2, w), rand.Next(h6th, h3rd), rand.Next(w - w6th, w), rand.Next(h3rd), GetRandomColor());

            writeableBmp.DrawQuad(rand.Next(0, w6th), rand.Next(h3rd, h3rd + h6th), rand.Next(w6th, w3rd), rand.Next(h3rd, h3rd + h6th), rand.Next(w6th, w3rd), rand.Next(h3rd + h6th, 2 * h3rd), rand.Next(0, w6th), rand.Next(h3rd + h6th, 2 * h3rd), GetRandomColor());
            writeableBmp.DrawRectangle(rand.Next(w3rd, w3rd + w6th), rand.Next(h3rd, h3rd + h6th), rand.Next(w3rd + w6th, w3rd * 2), rand.Next(h3rd + h6th, 2 * h3rd), GetRandomColor());

            // Random polyline
            int[] p = new int[rand.Next(7, 10) * 2];
            for (int j = 0; j < p.Length; j += 2)
            {
                p[j]     = rand.Next(w3rd * 2, w);
                p[j + 1] = rand.Next(h3rd, 2 * h3rd);
            }
            writeableBmp.DrawPolyline(p, GetRandomColor());

            // Random closed polyline
            p = new int[rand.Next(6, 9) * 2];
            for (int j = 0; j < p.Length - 2; j += 2)
            {
                p[j]     = rand.Next(w3rd);
                p[j + 1] = rand.Next(2 * h3rd, h);
            }
            p[p.Length - 2] = p[0];
            p[p.Length - 1] = p[1];
            writeableBmp.DrawPolyline(p, GetRandomColor());

            // Ellipses
            writeableBmp.DrawEllipse(rand.Next(w3rd, w3rd + w6th), rand.Next(h3rd * 2, h - h6th), rand.Next(w3rd + w6th, w3rd * 2), rand.Next(h - h6th, h), GetRandomColor());
            writeableBmp.DrawEllipseCentered(w - w6th, h - h6th, w6th >> 1, h6th >> 1, GetRandomColor());

            // Draw Grid
            writeableBmp.DrawLine(0, h3rd, w, h3rd, Colors.Black);
            writeableBmp.DrawLine(0, 2 * h3rd, w, 2 * h3rd, Colors.Black);
            writeableBmp.DrawLine(w3rd, 0, w3rd, h, Colors.Black);
            writeableBmp.DrawLine(2 * w3rd, 0, 2 * w3rd, h, Colors.Black);

            // Invalidate
            writeableBmp.Invalidate();
        }
Ejemplo n.º 2
0
        private void drawPointerMM(double x, double y, Color color)
        {
            int xi = fwdXi(x);
            int yi = fwdYi(y);

            writeableBitmap.DrawLine(xi - 20, yi, xi - 5, yi, color);
            writeableBitmap.DrawLine(xi + 20, yi, xi + 5, yi, color);
            writeableBitmap.DrawLine(xi, yi - 20, xi, yi - 5, color);
            writeableBitmap.DrawLine(xi, yi + 20, xi, yi + 5, color);
            writeableBitmap.DrawEllipseCentered(xi, yi, 15, 15, color);
            writeableBitmap.DrawEllipseCentered(xi, yi, 10, 10, color);
        }
Ejemplo n.º 3
0
        internal static void Transform(WriteableBitmap context, sb.Geometry <sb.Point> original, sb.Point location, int border, int fill)
        {
            if (original.Geometries != null)
            {
                foreach (var geometry in original.Geometries)
                {
                    Transform(context, geometry, location, border, fill);
                }
            }
            else
            {
                if (original.NumberOfPoints < 1)
                {
                    return;
                }

                var firstPoint = original.Points[0];

                if (original.Type == sb.GeometryType.Point)
                {
                    context.DrawEllipseCentered(border, (int)(firstPoint.X + location.X), (int)(firstPoint.Y + location.Y), pointSize, pointSize);
                }
                else if (original.Type == IRI.Msh.Common.Primitives.GeometryType.LineString)
                {
                    AddLineString(context, original, location, border, fill);
                }
            }
        }
Ejemplo n.º 4
0
        private void DrawPolarGrid(WriteableBitmap bitmap)
        {
            var markProvider = new PolarAxisMarkProvider {
                MinStep = 20, MinMajorStep = 100
            };                                                                                //{ MinStep = 5, MinMajorStep = 25 };

            markProvider.IterateRadiusGrid(Viewport.HorizontalAxis, Viewport.VerticalAxis,
                                           (x0, y0, x, y) => bitmap.DrawLine((int)x0, (int)y0, (int)x, (int)y, _minorGridColor), false);
            markProvider.IterateEllipseGrid(Viewport.HorizontalAxis, Viewport.VerticalAxis,
                                            (x0, y0, x, y) => bitmap.DrawEllipseCentered((int)x0, (int)y0, (int)x, (int)y, _minorGridColor), false);

            markProvider.IterateRadiusGrid(Viewport.HorizontalAxis, Viewport.VerticalAxis,
                                           (x0, y0, x, y) => bitmap.DrawLine((int)x0, (int)y0, (int)x, (int)y, _majorGridColor), true);
            markProvider.IterateEllipseGrid(Viewport.HorizontalAxis, Viewport.VerticalAxis,
                                            (x0, y0, x, y) => bitmap.DrawEllipseCentered((int)x0, (int)y0, (int)x, (int)y, _majorGridColor), true);
        }
Ejemplo n.º 5
0
        public void PaintCircle_Rect(WriteableBitmap bmp, Point position, int size, Color color)
        {
            //g.DrawEllipse(pen, position.X, position.Y, size, size);
            //g.DrawRectangle(pen, position.X + size / 4, position.Y + size / 4, size / 2, size / 2);

            bmp.DrawEllipseCentered((int)position.X, (int)position.Y, size, size, color);
            bmp.DrawRectangle((int)position.X + size / 4, (int)position.Y + size / 4, size / 2, size / 2, color);
        }
Ejemplo n.º 6
0
        public void PaintCircle_Point(WriteableBitmap bmp, Point position, int size, Color color)
        {
            //g.DrawEllipse(pen, position.X, position.Y, size, size);
            //g.FillEllipse(brush, position.X + size / 8 * 3, position.Y + size / 8 * 3, size / 4, size / 4);

            bmp.DrawEllipseCentered((int)position.X, (int)position.Y, size, size, color);
            bmp.FillEllipseCentered((int)position.X, (int)position.Y, size / 2, size / 2, color);
        }
Ejemplo n.º 7
0
        public void DrawEllipseCentered(double startX, double startY, double endX, double endY, Color color, int thickness)
        {
            int count = (int)(thickness * Scale);
            if (count < 1)
            {
                count = 1;
            }
            if (count == 1)
            {
                startX = Offset.X + startX * Scale;
                startY = Offset.Y + startY * Scale;
                endX = Offset.X + endX * Scale;
                endY = Offset.Y + endY * Scale;

                double cx = (startX + endX) / 2.0;
                double cy = (startY + endY) / 2.0;
                double xr = Math.Abs(startX - endX) / 2.0;
                double yr = Math.Abs(startY - endY) / 2.0;

                bmp.DrawEllipseCentered((int)cx, (int)cy, (int)xr, (int)yr, color);
            }
            else
            {
                if (count % 2 == 0)
                {
                    count++;
                }
                double step = thickness * Scale / count;
                double half = thickness * Scale / 2.0;

                startX = Offset.X + startX * Scale;
                startY = Offset.Y + startY * Scale;
                endX = Offset.X + endX * Scale;
                endY = Offset.Y + endY * Scale;

                int cx = (int)((startX + endX) / 2.0);
                int cy = (int)((startY + endY) / 2.0);
                int minRad = (int)(Math.Abs(startX - endX) / 2.0 - half);
                int maxRad = (int)(Math.Abs(startX - endX) / 2.0 + half);
                for (int i = minRad; i <= maxRad; i++)
                {
                     bmp.DrawEllipseCentered((int)cx, (int)cy, (int)i, (int)i, color);
                }
            }
        }
 private void CompositionTarget_Rendering(object sender, EventArgs e)
 {
     writeableBitmap.DrawEllipseCentered(
         random.Next(width),
         random.Next(height),
         20,
         20,
         Color.FromRgb((byte)random.Next(255), (byte)random.Next(255), (byte)random.Next(255)));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf
        /// x2 has to be greater than x1 and y2 has to be greater than y1.
        /// </summary>
        /// <param name="bmp">The WriteableBitmap.</param>
        /// <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>
        /// <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>
        /// <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>
        /// <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>
        /// <param name="color">The color for the line.</param>
        public static void DrawEllipse(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color)
        {
            // Calc center and radius
            int xr = (x2 - x1) >> 1;
            int yr = (y2 - y1) >> 1;
            int xc = x1 + xr;
            int yc = y1 + yr;

            bmp.DrawEllipseCentered(xc, yc, xr, yr, color);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf
        /// Uses a different parameter representation than DrawEllipse().
        /// </summary>
        /// <param name="bmp">The WriteableBitmap.</param>
        /// <param name="xc">The x-coordinate of the ellipses center.</param>
        /// <param name="yc">The y-coordinate of the ellipses center.</param>
        /// <param name="xr">The radius of the ellipse in x-direction.</param>
        /// <param name="yr">The radius of the ellipse in y-direction.</param>
        /// <param name="color">The color for the line.</param>
        public static void DrawEllipseCentered(this WriteableBitmap bmp, int xc, int yc, int xr, int yr, Color color)
        {
            // Add one to use mul and cheap bit shift for multiplicaltion
            int a   = color.A + 1;
            int col = (color.A << 24)
                      | ((byte)((color.R * a) >> 8) << 16)
                      | ((byte)((color.G * a) >> 8) << 8)
                      | ((byte)((color.B * a) >> 8));

            bmp.DrawEllipseCentered(xc, yc, xr, yr, col);
        }
Ejemplo n.º 11
0
        public void DrawMaskData()
        {
            if (mViewModel.MaskDataList != null && mViewModel.MaskDataList.Count > 0)
            {
                var maskDataArr = getMaskDataPointArr();
                mWriteableBmpForSpectrumChart.DrawPolylineAa(maskDataArr, Colors.GreenYellow);

                int r = 6;
                for (int i = 0; i < maskDataArr.Length / 2; i++)
                {
                    int X = maskDataArr[2 * i];
                    int Y = maskDataArr[2 * i + 1];
                    mWriteableBmpForSpectrumChart.DrawEllipseCentered(X, Y, r, r, Colors.White);
                }
            }
        }
Ejemplo n.º 12
0
        private void AddPoint(WriteableBitmap context, SqlGeometry point, Func <Point, Point> transform, int border, int fill, ImageSource imageSymbol, sb.Primitives.Geometry <sb.Primitives.Point> geometrySymbol)
        {
            var center = transform(point.AsWpfPoint()).AsPoint();

            if (geometrySymbol != null)
            {
                GeometryHelper.Transform(context, geometrySymbol, center, border, fill);
            }
            else if (imageSymbol != null)
            {
                throw new NotImplementedException();
            }
            else
            {
                context.DrawEllipseCentered((int)center.X, (int)center.Y, pointSize, pointSize, border);
            }
        }
Ejemplo n.º 13
0
        public WriteableBitmap Process(WriteableBitmap bmp)
        {
            if (bmp == null)
            {
                return(null);
            }

            // Filter
            var skin   = _skinColorFilter.Process(bmp);
            var erode  = _erodeFilter.Process(skin);
            var dilate = _dilateFilter.Process(erode);

            dilate = _dilateFilter.Process(dilate);
            dilate = _dilateFilter.Process(dilate);

            // Segment
            var histogram = Histogram.FromWriteabelBitmap(dilate);

            _segmentator.Histogram          = histogram;
            _segmentator.ThresholdLuminance = histogram.Max * 0.1f;
            var foundSegments = _segmentator.Process(dilate);

            // Visualize
            _histogramViz.Histogram = histogram;
            _histogramViz.Visualize(dilate);

            var result = new WriteableBitmap(bmp.PixelWidth, bmp.PixelHeight);

            foreach (var s in foundSegments)
            {
                // Uses the segment's center and half width, height
                var c = s.Center;
                result.DrawEllipseCentered(c.X, c.Y, s.Width >> 1, s.Height >> 1, Colors.Red);
            }
            return(result);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Draws the different types of shapes.
        /// </summary>
        private void DrawStaticShapes(WriteableBitmap writeableBmp)
        {
            // Wrap updates in a GetContext call, to prevent invalidation and nested locking/unlocking during this block
            using (writeableBmp.GetBitmapContext())
            {
                // Init some size vars
                int w    = writeableBmp.PixelWidth - 2;
                int h    = writeableBmp.PixelHeight - 2;
                int w3rd = w / 3;
                int h3rd = h / 3;
                int w6th = w3rd >> 1;
                int h6th = h3rd >> 1;

                // Clear
                writeableBmp.Clear();

                // Draw some points
                for (int i = 0; i < 200; i++)
                {
                    writeableBmp.SetPixel(rand.Next(w3rd), rand.Next(h3rd), GetRandomColor());
                }

                // Draw Standard shapes
                writeableBmp.DrawLine(rand.Next(w3rd, w3rd * 2), rand.Next(h3rd), rand.Next(w3rd, w3rd * 2), rand.Next(h3rd),
                                      GetRandomColor());
                writeableBmp.DrawTriangle(rand.Next(w3rd * 2, w - w6th), rand.Next(h6th), rand.Next(w3rd * 2, w),
                                          rand.Next(h6th, h3rd), rand.Next(w - w6th, w), rand.Next(h3rd),
                                          GetRandomColor());

                writeableBmp.DrawQuad(rand.Next(0, w6th), rand.Next(h3rd, h3rd + h6th), rand.Next(w6th, w3rd),
                                      rand.Next(h3rd, h3rd + h6th), rand.Next(w6th, w3rd),
                                      rand.Next(h3rd + h6th, 2 * h3rd), rand.Next(0, w6th), rand.Next(h3rd + h6th, 2 * h3rd),
                                      GetRandomColor());
                writeableBmp.DrawRectangle(rand.Next(w3rd, w3rd + w6th), rand.Next(h3rd, h3rd + h6th),
                                           rand.Next(w3rd + w6th, w3rd * 2), rand.Next(h3rd + h6th, 2 * h3rd),
                                           GetRandomColor());

                // Random polyline
                int[] p = new int[rand.Next(7, 10) * 2];
                for (int j = 0; j < p.Length; j += 2)
                {
                    p[j]     = rand.Next(w3rd * 2, w);
                    p[j + 1] = rand.Next(h3rd, 2 * h3rd);
                }
                writeableBmp.DrawPolyline(p, GetRandomColor());

                // Random closed polyline
                p = new int[rand.Next(6, 9) * 2];
                for (int j = 0; j < p.Length - 2; j += 2)
                {
                    p[j]     = rand.Next(w3rd);
                    p[j + 1] = rand.Next(2 * h3rd, h);
                }
                p[p.Length - 2] = p[0];
                p[p.Length - 1] = p[1];
                writeableBmp.DrawPolyline(p, GetRandomColor());

                // Ellipses
                writeableBmp.DrawEllipse(rand.Next(w3rd, w3rd + w6th), rand.Next(h3rd * 2, h - h6th),
                                         rand.Next(w3rd + w6th, w3rd * 2), rand.Next(h - h6th, h), GetRandomColor());
                writeableBmp.DrawEllipseCentered(w - w6th, h - h6th, w6th >> 1, h6th >> 1, GetRandomColor());


                // Draw Grid
                writeableBmp.DrawLine(0, h3rd, w, h3rd, Colors.Black);
                writeableBmp.DrawLine(0, 2 * h3rd, w, 2 * h3rd, Colors.Black);
                writeableBmp.DrawLine(w3rd, 0, w3rd, h, Colors.Black);
                writeableBmp.DrawLine(2 * w3rd, 0, 2 * w3rd, h, Colors.Black);

                // Invalidates on exit of using block
            }
        }
Ejemplo n.º 15
0
 public void DrawEllipse(double x0, double y0, double radiusX, double radiusY, DicomColor color)
 {
     _bitmap.DrawEllipseCentered(transxi(x0), transyi(y0), transxi(radiusX / 2), transyi(radiusY / 2), DicomColorConverter.FromDicomColor(color));
 }
        /// <summary>
        /// A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf
        /// Uses a different parameter representation than DrawEllipse().
        /// </summary>
        /// <param name="bmp">The WriteableBitmap.</param>
        /// <param name="xc">The x-coordinate of the ellipses center.</param>
        /// <param name="yc">The y-coordinate of the ellipses center.</param>
        /// <param name="xr">The radius of the ellipse in x-direction.</param>
        /// <param name="yr">The radius of the ellipse in y-direction.</param>
        /// <param name="color">The color for the line.</param>
        public static void DrawEllipseCentered(this WriteableBitmap bmp, int xc, int yc, int xr, int yr, Color color)
        {
            var col = ConvertColor(color);

            bmp.DrawEllipseCentered(xc, yc, xr, yr, col);
        }
Ejemplo n.º 17
0
 public void PaintHollowCircle(WriteableBitmap bmp, Point position, int size, Color color)
 {
     bmp.DrawEllipseCentered((int)position.X, (int)position.Y, size, size, color);
 }
Ejemplo n.º 18
0
        public void Draw(WriteableBitmap bitmap)
        {
            bitmap.Clear(Colors.White);
            double width     = bitmap.Width;
            double halfWidth = width / 2;

            width -= 1;
            double height = bitmap.Height;
            double uParam = P.FirstParamLimit;
            double vParam = P.SecondParamLimit;
            double sParam = Q.FirstParamLimit;
            double tParam = Q.SecondParamLimit;

            using (bitmap.GetBitmapContext())
            {
                if (QtestSet != null)
                {
                    var uStep = Q.FirstParamLimit / (QtestSet.GetLength(1) - 1.0);
                    var vStep = Q.SecondParamLimit / (QtestSet.GetLength(0) - 1.0);


                    for (int i = 0; i < QtestSet.GetLength(1); i++)
                    {
                        for (int j = 0; j < QtestSet.GetLength(0); j++)
                        {
                            bitmap.DrawEllipseCentered((int)(i * uStep / sParam * (halfWidth - 3) + halfWidth), (int)(j * vStep / tParam * height), 1, 1, QtestSet[j, i] ? Colors.LightGray : Colors.LightBlue);
                        }
                    }
                }

                if (pPolygon != null)
                {
                    var minSize = System.Math.Min(P.FirstParamLimit, P.SecondParamLimit) * 0.8;
                    for (int i = 0; i < pPolygon.Count - 1 + (cyclic ? 1 : 0); i++)
                    {
                        var item1 = pPolygon[i];
                        var item2 = pPolygon[(i + 1) % pPolygon.Count];
                        if (System.Math.Abs(item1.X - item2.X) < minSize && System.Math.Abs(item1.Y - item2.Y) < minSize)
                        {
                            bitmap.DrawLineDDA((int)(item1.X / uParam * halfWidth), (int)(item1.Y / vParam * height), (int)(item2.X / uParam * halfWidth), (int)(item2.Y / vParam * height), Colors.BlueViolet);
                        }
                    }
                }

                if (IsIntersectableP)
                {
                    if (pPolygonBoundary != null)
                    {
                        foreach (var tuple in pPolygonBoundary)
                        {
                            bitmap.DrawLineDDA((int)(tuple.Item1.X / uParam * halfWidth), (int)(tuple.Item1.Y / vParam * height), (int)(tuple.Item2.X / uParam * halfWidth), (int)(tuple.Item2.Y / vParam * height), Colors.BlueViolet);
                        }
                    }
                }

                if (qPolygon != null)
                {
                    var minSize = System.Math.Min(Q.FirstParamLimit, Q.SecondParamLimit) * 0.8;
                    for (int i = 0; i < qPolygon.Count - 1 + (cyclic ? 1 : 0); i++)
                    {
                        var item1 = qPolygon[i];
                        var item2 = qPolygon[(i + 1) % qPolygon.Count];
                        if (System.Math.Abs(item1.X - item2.X) < minSize && System.Math.Abs(item1.Y - item2.Y) < minSize)
                        {
                            bitmap.DrawLineDDA((int)(item1.X / sParam * (halfWidth - 3) + halfWidth), (int)(item1.Y / tParam * height), (int)(item2.X / sParam * (halfWidth - 3) + halfWidth), (int)(item2.Y / tParam * height), Colors.DarkViolet);
                        }
                    }
                }

                if (IsIntersectableQ)
                {
                    if (qPolygonBoundary != null)
                    {
                        foreach (var tuple in qPolygonBoundary)
                        {
                            bitmap.DrawLineDDA((int)(tuple.Item1.X / sParam * (halfWidth - 3) + halfWidth), (int)(tuple.Item1.Y / tParam * height), (int)(tuple.Item2.X / sParam * (halfWidth - 3) + halfWidth), (int)(tuple.Item2.Y / tParam * height), Colors.DarkViolet);
                        }
                    }
                }

                //if (PtestSet != null)
                //{
                //	var uStep = P.FirstParamLimit / (PtestSet.GetLength(1) - 1.0);
                //	var vStep = P.SecondParamLimit / (PtestSet.GetLength(0) - 1.0);


                //	for (int i = 0; i < PtestSet.GetLength(1); i++)
                //		for (int j = 0; j < PtestSet.GetLength(0); j++)
                //		{
                //			bitmap.DrawEllipseCentered((int)(i * uStep / uParam * halfWidth), (int)(j * vStep / vParam * height), 1, 1, PtestSet[j, i] ? Colors.Green : Colors.Red);
                //		}
                //}
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf
 /// It uses a different parameter representation than DrawEllipse().
 /// </summary>
 /// <param name="bmp">The WriteableBitmap.</param>
 /// <param name="xc">The x-coordinate of the ellipses center.</param>
 /// <param name="yc">The y-coordinate of the ellipses center.</param>
 /// <param name="xr">The radius of the ellipse in x-direction.</param>
 /// <param name="yr">The radius of the ellipse in y-direction.</param>
 /// <param name="color">The color for the line.</param>
 public static void DrawEllipseCentered(this WriteableBitmap bmp, int xc, int yc, int xr, int yr, Color color)
 {
     bmp.DrawEllipseCentered(xc, yc, xr, yr, (color.A << 24) | (color.R << 16) | (color.G << 8) | color.B);
 }
Ejemplo n.º 20
0
        private void ViewPort_Loaded(object sender, RoutedEventArgs e)
        {
            width  = (int)this.ViewPortContainer.ActualWidth;
            height = (int)this.ViewPortContainer.ActualHeight;

            frame           = BitmapFactory.New(width, height);
            ViewPort.Source = frame;
            List <Branch> Branches = new List <Branch>();
            Branch        bottom   = new Branch((width / 2), height, 0, 50, 200);

            Branches.Add(bottom);

            frame.DrawLine(bottom.posX, bottom.posY, bottom.posX, height - bottom.length, Branch.color);
            bottom.setEndPoint(bottom.posX, height - bottom.length);
            //System.Diagnostics.Debug.WriteLine(Math.Sin(60.0* Math.PI / 180));
            //System.Diagnostics.Debug.WriteLine(bottom.posX+ " " + bottom.posY + " " + bottom.posX + " " + (bottom.posY + bottom.length));
            int           counter = 0;
            int           branchesCount;
            List <Branch> newBranches;
            int           numToRemove;
            int           index;

            while (Branches.Count > 0 && counter < 4)
            {
                branchesCount = Branches.Count;
                newBranches   = new List <Branch>();
                if (branchesCount > 4)
                {
                    index       = 0;
                    numToRemove = (branchesCount / 2);
                    for (int i = 0; i <= numToRemove; i++)
                    {
                        index = new Random().Next(0, (branchesCount - 1));
                        for (int x = 0; x < 6; x++)
                        {
                            frame.DrawEllipseCentered(Branches.ElementAt(index).posX, Branches.ElementAt(index).posY, x, x, Colors.Green);
                        }
                        Branches.RemoveAt(index);
                        branchesCount--;
                    }
                }

                foreach (var b in Branches)
                {
                    for (int i = 0; i < (branchesCount * 2); i++)
                    {
                        newBranches.Add(new Branch(b.posX, b.posY));
                    }
                }

                Branches      = newBranches;
                branchesCount = Branches.Count;


                foreach (var b in Branches)
                {
                    int oldX = b.posX;
                    int oldY = b.posY;

                    b.setEndPoint();

                    int newX = b.posX;
                    int newY = b.posY;

                    frame.DrawLine(oldX, oldY, newX, newY, Branch.color);
                }



                counter++;
            }
            index = 0;
            foreach (var b in Branches)
            {
                for (int i = 0; i < 6; i++)
                {
                    frame.DrawEllipseCentered(Branches.ElementAt(index).posX, Branches.ElementAt(index).posY, i, i, Colors.Green);
                }
                index++;
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Draws circles that decrease in size to build a flower that is animated
        /// </summary>
        private void DrawEllipsesFlower(WriteableBitmap writeableBmp)
        {
            if (writeableBmp == null)
            {
                return;
            }

            // Init some size vars
            int w = writeableBmp.PixelWidth - 2;
            int h = writeableBmp.PixelHeight - 2;

            // Wrap updates in a GetContext call, to prevent invalidation and nested locking/unlocking during this block
            using (writeableBmp.GetBitmapContext())
            {
                // Increment frame counter
                if (++frameCounter >= int.MaxValue || frameCounter < 1)
                {
                    frameCounter = 1;
                }
                double s = Math.Sin(frameCounter * 0.01);
                if (s < 0)
                {
                    s *= -1;
                }

                // Clear
                writeableBmp.Clear();

                // Draw center circle
                int xc = w >> 1;
                int yc = h >> 1;
                // Animate base size with sine
                int r0 = (int)((w + h) * 0.07 * s) + 10;
                System.Windows.Media.Imaging.Color color_brown = System.Windows.Media.Imaging.Color.FromArgb(
                    255, System.Drawing.Color.Brown.R, System.Drawing.Color.Brown.G, System.Drawing.Color.Brown.B);

                writeableBmp.DrawEllipseCentered(xc, yc, r0, r0, color_brown);

                // Draw outer circles
                int dec    = (int)((w + h) * 0.0045f);
                int r      = (int)((w + h) * 0.025f);
                int offset = r0 + r;
                for (int i = 1; i < 6 && r > 1; i++)
                {
                    for (double f = 1; f < 7; f += 0.7)
                    {
                        // Calc postion based on unit circle
                        int xc2 = (int)(Math.Sin(frameCounter * 0.002 * i + f) * offset + xc);
                        int yc2 = (int)(Math.Cos(frameCounter * 0.002 * i + f) * offset + yc);
                        int col = (int)(0xFFFF0000 | (uint)(0x1A * i) << 8 | (uint)(0x20 * f));
                        writeableBmp.DrawEllipseCentered(xc2, yc2, r, r, col);
                    }
                    // Next ring
                    offset += r;
                    r      -= dec;
                    offset += r;
                }

                // Invalidates on exit of using block
            }
        }