예제 #1
0
        public virtual DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                dummy            = new DrawingShape(new TikzLine(new Shapes.ArrowLine(), null), ShapeState.START);
                previousMousePos = canvasEventArgs.Point;
            }
            else
            {
                Point  mousePos = canvasEventArgs.Point;
                Vector delta    = mousePos - previousMousePos;
                previousMousePos = mousePos;
                foreach (TikzShape s in shapes)
                {
                    Canvas.SetLeft(s.Shape, Canvas.GetLeft(s.Shape) + delta.X);
                    Canvas.SetTop(s.Shape, Canvas.GetTop(s.Shape) + delta.Y);
                }

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    dummy.ShapeState = ShapeState.FINISHED;
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    dummy.ShapeState = ShapeState.DRAWING;
                }
            }
            dummy.RemoveOnFinish = true;
            return(dummy);
        }
예제 #2
0
        public virtual DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                Rectangle rect = new Rectangle();
                rect.SetStyle(TikzStyle.SelectionStyle);
                current = new DrawingShape(new TikzRectangle(rect, null), ShapeState.START);
                current.RemoveOnFinish = true;
                firstPoint             = canvasEventArgs.Point;
            }
            else
            {
                current.TikzShape.Shape.Width  = Math.Abs(firstPoint.X - canvasEventArgs.Point.X);
                current.TikzShape.Shape.Height = Math.Abs(firstPoint.Y - canvasEventArgs.Point.Y);
                current.TikzShape.Shape.Margin = new Thickness(Math.Min(firstPoint.X, canvasEventArgs.Point.X), Math.Min(firstPoint.Y, canvasEventArgs.Point.Y), 0, 0);

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    current.ShapeState = ShapeState.FINISHED;
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    current.ShapeState = ShapeState.DRAWING;
                }
            }
            return(current);
        }
예제 #3
0
        void drawMode(
            bool status,
            Shape shape      = null,
            int modify_index = -1
            )
        {
            if (!status && index == -1)
            {
                shapes.Add(currentShape);
                if (shapes.Count == 1)
                {
                    listBox1_SelectedIndexChanged(null, null);
                }
                RefreshShapes();
            }
            else if (!status)
            {
                shapes[index] = currentShape;
                RefreshShapes();
            }

            splitContainer2.Panel1.Enabled = !status;

            index               = modify_index;
            drawing             = status;
            currentDrawingShape = shape == null ? DrawingShape.EMPTY : shape.shapeType;
            currentShape        = shape;
            UpdateLabel();
        }
예제 #4
0
        public DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                Ellipse ellipse = new Ellipse
                {
                    StrokeThickness = style.LineWidth.GetLineWidth(),
                };

                ellipse.SetStyle(style);
                current    = new DrawingShape(new TikzEllipse(ellipse, style), ShapeState.START);
                firstPoint = canvasEventArgs.Point;
            }
            else
            {
                double x = Math.Min(canvasEventArgs.Point.X, firstPoint.X);
                double y = Math.Min(canvasEventArgs.Point.Y, firstPoint.Y);

                double w = Math.Max(canvasEventArgs.Point.X, firstPoint.X) - x;
                double h = Math.Max(canvasEventArgs.Point.Y, firstPoint.Y) - y;

                if (canvasEventArgs.ModKey)
                {
                    if (canvasEventArgs.Point.X > firstPoint.X)
                    {
                        w = h;
                    }
                    else if (canvasEventArgs.Point.Y > firstPoint.Y)
                    {
                        h = w;
                    }
                    else
                    {
                        double b = Math.Min(firstPoint.X - canvasEventArgs.Point.X, firstPoint.Y - canvasEventArgs.Point.Y);
                        w = b;
                        h = b;
                        x = firstPoint.X - b;
                        y = firstPoint.Y - b;
                    }
                }

                Canvas.SetLeft(current.TikzShape.Shape, x);
                Canvas.SetTop(current.TikzShape.Shape, y);

                current.TikzShape.Shape.Width  = w;
                current.TikzShape.Shape.Height = h;

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    current.ShapeState = ShapeState.FINISHED;
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    current.ShapeState = ShapeState.DRAWING;
                }
            }
            return(current);
        }
예제 #5
0
        public virtual DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                Rectangle rect = new Rectangle();
                rect.SetStyle(style);
                current = new DrawingShape(new TikzRectangle(rect, style), ShapeState.START);

                firstPoint = canvasEventArgs.Point;
            }
            else
            {
                double x = Math.Min(canvasEventArgs.Point.X, firstPoint.X);
                double y = Math.Min(canvasEventArgs.Point.Y, firstPoint.Y);

                double w = Math.Max(canvasEventArgs.Point.X, firstPoint.X) - x;
                double h = Math.Max(canvasEventArgs.Point.Y, firstPoint.Y) - y;

                if (canvasEventArgs.ModKey)
                {
                    if (canvasEventArgs.Point.X > firstPoint.X)
                    {
                        w = h;
                    }
                    else if (canvasEventArgs.Point.Y > firstPoint.Y)
                    {
                        h = w;
                    }
                    else
                    {
                        double b = Math.Min(firstPoint.X - canvasEventArgs.Point.X, firstPoint.Y - canvasEventArgs.Point.Y);
                        w = b;
                        h = b;
                        x = firstPoint.X - b;
                        y = firstPoint.Y - b;
                    }
                }

                Canvas.SetLeft(current.TikzShape.Shape, x);
                Canvas.SetTop(current.TikzShape.Shape, y);

                current.TikzShape.Shape.Width  = w;
                current.TikzShape.Shape.Height = h;

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    current.ShapeState = ShapeState.FINISHED;
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    current.ShapeState = ShapeState.DRAWING;
                }
            }
            return(current);
        }
예제 #6
0
        public void Reset()
        {
            click = 0;

            current = null;

            secondPointSelected = false;
            thirdPointSelected  = false;

            bezier = null;
            figure = null;
            path   = null;
            pf     = null;
        }
예제 #7
0
        public DrawingShape GetShape(CanvasEventArgs canvasEventArgs)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                x1 = canvasEventArgs.X;
                y1 = canvasEventArgs.Y;

                current = new DrawingShape(
                    new Line
                {
                    Stroke          = StrokeColor,
                    X1              = x1,
                    X2              = x1,
                    Y1              = y1,
                    Y2              = y1,
                    StrokeThickness = DEF_STROKE_THICKNESS
                }, ShapeState.START);
            }
            else
            {
                if (current.Shape is not Line l)
                {
                    throw new Exception("Shape-Tool type mismatch, tool type: LineTool, expected shape type Line");
                }

                l.X2 = canvasEventArgs.X;
                l.Y2 = canvasEventArgs.Y;

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    current.ShapeState = ShapeState.FINISHED;
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    current.ShapeState = ShapeState.DRAWING;
                }
            }

            return(current);
        }
예제 #8
0
        public DrawingShape GetShape(CanvasEventArgs canvasEventArgs)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                current = new DrawingShape(
                    new Ellipse
                {
                    Stroke          = StrokeColor,
                    StrokeThickness = DEF_STROKE_THICKNESS,
                },
                    ShapeState.START
                    );

                x1 = canvasEventArgs.X;
                y1 = canvasEventArgs.Y;
            }
            else
            {
                UpdateCurrent(canvasEventArgs);
            }
            return(current);
        }
예제 #9
0
        public ICollection <Shape> ConvertMany(string data)
        {
            List <LocalShapeData> canvasShapesData = JsonSerializer.Deserialize <List <LocalShapeData> >(data);
            List <Shape>          shapes           = new List <Shape>(canvasShapesData.Count);
            ITool currentTool;

            foreach (LocalShapeData shapeData in canvasShapesData)
            {
                currentTool = toolNameToolMap[shapeData.ToolName];

                foreach (CanvasEventArgs canvasEventArgs in shapeData.KeyPoints)
                {
                    DrawingShape r = currentTool.GetShape(canvasEventArgs);

                    if (r.ShapeState == ShapeState.FINISHED)
                    {
                        shapes.Add(r.Shape);
                    }
                }
            }
            return(shapes);
        }
예제 #10
0
        void clipMode(bool status, Shape shape, int modify_index = -1)
        {
            if (!status && shapes[index].shapeType == DrawingShape.POLY)
            {
                ClippedPolygon cpoly = new ClippedPolygon((Polygon)shapes[index]);
                cpoly.SetBoundingRect((Rectangle)currentShape);
                shapes[index] = cpoly;
                RefreshShapes();
            }
            else if (!status && shapes[index].shapeType == DrawingShape.CPOLY)
            {
                ((ClippedPolygon)shapes[index]).SetBoundingRect((Rectangle)currentShape);
                RefreshShapes();
            }

            splitContainer2.Panel1.Enabled = !status;

            index    = modify_index;
            clipping = status;

            currentDrawingShape = shape == null ? DrawingShape.EMPTY : shape.shapeType;
            currentShape        = shape;
            UpdateLabel();
        }
예제 #11
0
        public ICollection <TikzShape> ConvertMany(string data)
        {
            SaveData         d      = JsonSerializer.Deserialize <SaveData>(data);
            List <TikzShape> result = new List <TikzShape>();
            ITool            currentTool;

            foreach (LocalShapeData shapeData in d.localShapeData)
            {
                currentTool = toolNameToolMap[shapeData.ToolName];
                foreach (CanvasEventArgs canvasEventArgs in shapeData.KeyPoints)
                {
                    DrawingShape r = currentTool.GetShape(canvasEventArgs, shapeData.Style);

                    if (r.ShapeState == ShapeState.FINISHED)
                    {
                        result.Add(r.TikzShape);
                    }
                }
            }

            foreach (SvgData raw in d.svgRawData)
            {
                List <TikzShape> c = SVGParser.Parse(raw.data);
                foreach (TikzShape s in c)
                {
                    Canvas.SetLeft(s.Shape, raw.translate.X);
                    Canvas.SetTop(s.Shape, raw.translate.Y);
                    s.TikzStyle = raw.style;
                    s.Shape.SetStyle(raw.style);
                }

                result.AddRange(c);
            }

            return(result);
        }
예제 #12
0
 public void Reset()
 {
     firstPoint = null;
     current    = null;
 }
예제 #13
0
 public void Reset()
 {
     current = null;
 }
 private void ChooseReferenceLine_Button_Click(object sender, RoutedEventArgs e)
 {
     _currentShape = DrawingShape.ReferenceLine;
     UpdateButtonUI((Button)sender);
 }
예제 #15
0
        public DrawingShape GetShape(CanvasEventArgs a, TikzStyle style)
        {
            if (click == 0) // first click, draw a straight line
            {
                if (a.MouseState == MouseState.DOWN)
                {
                    //FIXME: small bug here, sometimes when a user clicks for the first time long line appears for a split second, noticeable but should not influence performance

                    firstPoint = a.Point;

                    bezier = new BezierSegment()
                    {
                        Point3 = a.Point.GetSystemPoint()
                    };
                    figure = new PathFigure();
                    figure.Segments.Add(bezier);
                    path = new ArrowPath();

                    path.SetStyle(style);
                    path.Margin = ShapeUtils.GetMargin(firstPoint.X, firstPoint.Y);

                    pf        = new PathFigure[] { figure };
                    path.Data = new PathGeometry(pf);

                    current = new DrawingShape(
                        new TikzBezier(path, style),
                        ShapeState.START
                        );
                }
                else if (a.MouseState == MouseState.MOVE)
                {
                    bezier.Point3 = GetPointWithoutMargin(firstPoint, a.Point);
                }
                else
                {
                    bezier.Point3 = GetPointWithoutMargin(firstPoint, a.Point);
                    click++;
                }

                return(current);
            }
            else if (click == 1) // second click, select first control point
            {
                if (a.MouseState == MouseState.DOWN)
                {
                    secondPointSelected = true;
                    bezier.Point1       = GetPointWithoutMargin(firstPoint, a.Point);
                }
                else if (a.MouseState == MouseState.MOVE)
                {
                    if (secondPointSelected)
                    {
                        bezier.Point1 = GetPointWithoutMargin(firstPoint, a.Point);
                    }
                }
                else
                {
                    bezier.Point1 = GetPointWithoutMargin(firstPoint, a.Point);
                    click++;
                }

                return(current);
            }
            else if (click == 2) // third click, select second control point
            {
                if (a.MouseState == MouseState.DOWN)
                {
                    thirdPointSelected = true;
                    bezier.Point2      = GetPointWithoutMargin(firstPoint, a.Point);
                }
                else if (a.MouseState == MouseState.MOVE)
                {
                    if (thirdPointSelected)
                    {
                        bezier.Point2 = GetPointWithoutMargin(firstPoint, a.Point);
                    }
                }
                else
                {
                    bezier.Point2      = GetPointWithoutMargin(firstPoint, a.Point);
                    current.ShapeState = ShapeState.FINISHED;
                    click = 0;
                    secondPointSelected = thirdPointSelected = false;
                }

                Canvas.SetLeft(current.TikzShape.Shape, 0);
                Canvas.SetTop(current.TikzShape.Shape, 0);

                return(current);
            }
            else
            {
                throw new Exception("Sth went wrong, bezier line should be drawn in 3 clicks");
            }
        }
예제 #16
0
    //private static void DrawValuesCube(Bitmap bitmap, List<long> values, Color color)
    //{
    //    using (Graphics graphics = Graphics.FromImage(bitmap))
    //    {
    //        if (graphics != null)
    //        {
    //            graphics.Clear(Color.Black); // set background
    //            int count = values.Count;
    //            int width = (int)Math.Round(Math.Pow(count + 1, 1.0D / 3.0D));
    //            int height = width;
    //            int layers = width;

    //            if (values != null)
    //            {
    //                double normalizer = 1.0D;
    //                long max_value = long.MinValue;
    //                foreach (long value in values)
    //                {
    //                    if (max_value < value)
    //                    {
    //                        max_value = value;
    //                    }
    //                }
    //                if (max_value > 0L)
    //                {
    //                    normalizer = (255.0 / max_value);
    //                }

    //                if (graphics != null)
    //                {
    //                    graphics.Clear(Color.Black); // set background
    //                    for (int n = 0; n < layers; n++)
    //                    {
    //                        for (int i = 0; i < (width * height); i++)
    //                        {
    //                            int dx = 1;
    //                            int dy = 1;
    //                            int x_shift = (bitmap.Width - dx * width) / 2;
    //                            int y_shift = (bitmap.Height - dy * height) / 2;

    //                            // draw point at new location in color shaded by numerology value
    //                            int r = (int)((values[n * (width * height) + i] * normalizer) * (color.R / 255.0));
    //                            int g = (int)((values[n * (width * height) + i] * normalizer) * (color.G / 255.0));
    //                            int b = (int)((values[n * (width * height) + i] * normalizer) * (color.B / 255.0));
    //                            Color value_color = Color.FromArgb(r, g, b);
    //                            using (SolidBrush brush = new SolidBrush(value_color))
    //                            {
    //                                graphics.FillRectangle(brush, new Rectangle(x_shift + (i % width) * dx, y_shift + (i / width) * dy, dx, dy));
    //                            }
    //                        }

    //                        // wait before drawing next layer
    //                        Thread.Sleep(100);
    //                    }
    //                }
    //            }
    //        }
    //    }
    //}

    public static void DrawValues(Bitmap bitmap, List <long> values, Color color1, Color color2, Color color3, DrawingShape shape)
    {
        if (values != null)
        {
            int count = values.Count;

            int width  = 0;
            int height = 0;

            switch (shape)
            {
            case DrawingShape.Spiral:
            {
                DrawValuesSpiral(bitmap, values, color1, color2);
                return;
            }

            case DrawingShape.SquareSpiral:
            {
                DrawValuesSquareSpiral(bitmap, values, color1, color2);
                return;
            }

            case DrawingShape.Square:
            case DrawingShape.Cube:
            {
                width  = (int)Math.Round(Math.Sqrt(count + 1));
                height = width;
            }
            break;

            case DrawingShape.HGoldenRect:
            case DrawingShape.HGoldenCube:
            {
                width  = (int)Math.Round(Math.Sqrt((count * Numbers.PHI) + 1));
                height = (int)Math.Round(Math.Sqrt((count / Numbers.PHI) + 1));
            }
            break;

            case DrawingShape.VGoldenRect:
            case DrawingShape.VGoldenCube:
            {
                width  = (int)Math.Round(Math.Sqrt((count / Numbers.PHI) + 1));
                height = (int)Math.Round(Math.Sqrt((count * Numbers.PHI) + 1));
            }
            break;
            }

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                if (graphics != null)
                {
                    graphics.Clear(Color.Black); // set background
                    for (int i = 0; i < count; i++)
                    {
                        int dx      = 1;
                        int dy      = 1;
                        int x_shift = (bitmap.Width - dx * width) / 2;
                        int y_shift = (bitmap.Height - dy * height) / 2;

                        Color value_color = Color.Black;
                        if (values[i] == 3)
                        {
                            value_color = color3;
                        }
                        else if (values[i] == 2)
                        {
                            value_color = color2;
                        }
                        else if (values[i] == 1)
                        {
                            value_color = color1;
                        }
                        else if (values[i] == 0)
                        {
                            value_color = Color.Black;
                        }
                        else
                        {
                            continue;
                        }

                        using (SolidBrush brush = new SolidBrush(value_color))
                        {
                            graphics.FillRectangle(brush, new Rectangle(x_shift + (i % width) * dx, y_shift + (i / width) * dy, dx, dy));
                        }
                    }
                }
            }
        }
    }
예제 #17
0
    public static void DrawValues(Bitmap bitmap, List <long> values, Color color, DrawingShape shape)
    {
        if (values != null)
        {
            int count = values.Count;

            int width  = 0;
            int height = 0;

            switch (shape)
            {
            case DrawingShape.Spiral:
            {
                DrawValuesSpiral(bitmap, values, color);
                return;
            }

            case DrawingShape.SquareSpiral:
            {
                DrawValuesSquareSpiral(bitmap, values, color);
                return;
            }

            case DrawingShape.Square:
            case DrawingShape.Cube:
            {
                width  = (int)Math.Round(Math.Sqrt(count + 1));
                height = width;
            }
            break;

            case DrawingShape.HGoldenRect:
            case DrawingShape.HGoldenCube:
            {
                width  = (int)Math.Round(Math.Sqrt((count * Numbers.PHI) + 1));
                height = (int)Math.Round(Math.Sqrt((count / Numbers.PHI) + 1));
            }
            break;

            case DrawingShape.VGoldenRect:
            case DrawingShape.VGoldenCube:
            {
                width  = (int)Math.Round(Math.Sqrt((count / Numbers.PHI) + 1));
                height = (int)Math.Round(Math.Sqrt((count * Numbers.PHI) + 1));
            }
            break;
            }

            double normalizer = 1.0D;
            long   max_value  = long.MinValue;
            foreach (long value in values)
            {
                if (max_value < value)
                {
                    max_value = value;
                }
            }
            if (max_value > 0L)
            {
                normalizer = (255.0 / max_value);
            }

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                if (graphics != null)
                {
                    int dx      = 1;
                    int dy      = 1;
                    int x_shift = (bitmap.Width - dx * width) / 2;
                    int y_shift = (bitmap.Height - dy * height) / 2;

                    graphics.Clear(Color.Black); // set background
                    for (int i = 0; i < count; i++)
                    {
                        // draw point at new location in color shaded by numerology value
                        int   r           = (int)((values[i] * normalizer) * (color.R / 255.0));
                        int   g           = (int)((values[i] * normalizer) * (color.G / 255.0));
                        int   b           = (int)((values[i] * normalizer) * (color.B / 255.0));
                        Color value_color = Color.FromArgb(r, g, b);
                        using (SolidBrush brush = new SolidBrush(value_color))
                        {
                            graphics.FillRectangle(brush, new Rectangle(x_shift + (i % width) * dx, y_shift + (i / width) * dy, dx, dy));
                        }
                    }
                }
            }
        }
    }
예제 #18
0
        public DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                firstPoint = canvasEventArgs.Point;
                ArrowLine line = new ArrowLine
                {
                    X1 = firstPoint.X,
                    X2 = firstPoint.X,
                    Y1 = firstPoint.Y,
                    Y2 = firstPoint.Y,
                };

                line.SetStyle(style);
                current = new DrawingShape(new TikzLine(line, style), ShapeState.START);
            }
            else
            {
                if (current.TikzShape.Shape is not ArrowLine l)
                {
                    throw new Exception("Shape-Tool type mismatch, tool type: LineTool, expected shape type Line");
                }

                l.X2 = canvasEventArgs.Point.X;
                l.Y2 = canvasEventArgs.Point.Y;

                if (canvasEventArgs.ModKey)
                {
                    //Snap mode, from start to one of axis contraints
                    //Axis constraints are divided by 45deg angles

                    //Get angle between start point and mouse pointer
                    //origin Axis X
                    double angle = Math.Atan2(l.Y2 - l.Y1, l.X2 - l.X1); //rads

                    //Determine constraint axis based on angle between X axis and current line
                    //22.5 -> pi/8

                    //X AXIS -> 0
                    //45 -> PI/4
                    //90 -> PI/2
                    //135 -> PI/2 + PI/4 = 3PI/4
                    //180 -> PI
                    //180 -> -PI
                    //225 -> -3PI/4
                    //270 -> -PI/2
                    //360 -> 0

                    double snapAngle = Math.Ceiling(angle / (Math.PI / 8.0)) * (Math.PI / 8.0);
                    //calculate new points based on snapAngle

                    double maxDim = Math.Max(Math.Abs(l.X2 - l.X1), Math.Abs(l.Y2 - l.Y1));
                    l.X2 = l.X1 + Math.Cos(snapAngle) * maxDim;
                    l.Y2 = l.Y1 + Math.Sin(snapAngle) * maxDim;
                }

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    current.ShapeState = ShapeState.FINISHED;
                    Canvas.SetLeft(l, 0);
                    Canvas.SetTop(l, 0);
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    current.ShapeState = ShapeState.DRAWING;
                }
            }

            return(current);
        }
예제 #19
0
 private void GotoPreviousShape()
 {
     switch (m_drawing_shape)
     {
         case DrawingShape.Spiral:
             {
                 // short circuit to cube directly for now
                 m_drawing_shape = DrawingShape.Cube;
                 if (File.Exists("Images/cube.png"))
                 {
                     ChangeDrawingShapeLabel.Image = new Bitmap("Images/cube.png");
                 }
                 //m_drawing_shape = DrawingShape.VGoldenCube;
                 //if (File.Exists("Images/vgoldencube.png"))
                 //{
                 //    ChangeDrawingShapeLabel.Image = new Bitmap("Images/vgoldencube.png");
                 //}
             }
             break;
         case DrawingShape.SquareSpiral:
             {
                 m_drawing_shape = DrawingShape.Spiral;
                 if (File.Exists("Images/spiral.png"))
                 {
                     ChangeDrawingShapeLabel.Image = new Bitmap("Images/spiral.png");
                 }
             }
             break;
         case DrawingShape.Square:
             {
                 m_drawing_shape = DrawingShape.SquareSpiral;
                 if (File.Exists("Images/squarespiral.png"))
                 {
                     ChangeDrawingShapeLabel.Image = new Bitmap("Images/squarespiral.png");
                 }
             }
             break;
         case DrawingShape.HGoldenRect:
             {
                 m_drawing_shape = DrawingShape.Square;
                 if (File.Exists("Images/square.png"))
                 {
                     ChangeDrawingShapeLabel.Image = new Bitmap("Images/square.png");
                 }
             }
             break;
         case DrawingShape.VGoldenRect:
             {
                 m_drawing_shape = DrawingShape.HGoldenRect;
                 if (File.Exists("Images/hgoldenrect.png"))
                 {
                     ChangeDrawingShapeLabel.Image = new Bitmap("Images/hgoldenrect.png");
                 }
             }
             break;
         case DrawingShape.Cube:
             {
                 m_drawing_shape = DrawingShape.VGoldenRect;
                 if (File.Exists("Images/vgoldenrect.png"))
                 {
                     ChangeDrawingShapeLabel.Image = new Bitmap("Images/vgoldenrect.png");
                 }
             }
             break;
         case DrawingShape.HGoldenCube:
             {
                 m_drawing_shape = DrawingShape.Cube;
                 if (File.Exists("Images/cube.png"))
                 {
                     ChangeDrawingShapeLabel.Image = new Bitmap("Images/cube.png");
                 }
             }
             break;
         case DrawingShape.VGoldenCube:
             {
                 m_drawing_shape = DrawingShape.HGoldenRect;
                 if (File.Exists("Images/hgoldencube.png"))
                 {
                     ChangeDrawingShapeLabel.Image = new Bitmap("Images/hgoldencube.png");
                 }
             }
             break;
     }
 }
예제 #20
0
    public static void DrawPoints(Bitmap bitmap, List <long> values, Dictionary <long, Color> colors, DrawingShape shape)
    {
        if (values != null)
        {
            int count = values.Count;

            int width  = 1;
            int height = 1;

            switch (shape)
            {
            case DrawingShape.Lines:
            {
                width  = (int)Math.Round(Math.Sqrt(count + 1));
                height = width;
            }
            break;

            case DrawingShape.Spiral:
            {
                DrawPointsSpiral(bitmap, values, colors);
                return;
            }

            case DrawingShape.SquareSpiral:
            {
                DrawPointsSquareSpiral(bitmap, values, colors);
                return;
            }

            case DrawingShape.Square:
            case DrawingShape.Cube:
            {
                width  = (int)Math.Round(Math.Sqrt(count + 1));
                height = width;
            }
            break;

            case DrawingShape.HGoldenRect:
            {
                width  = (int)Math.Round(Math.Sqrt((count * Numbers.PHI) + 1));
                height = (int)Math.Round(Math.Sqrt((count / Numbers.PHI) + 1));
            }
            break;

            case DrawingShape.VGoldenRect:
            {
                width  = (int)Math.Round(Math.Sqrt((count / Numbers.PHI) + 1));
                height = (int)Math.Round(Math.Sqrt((count * Numbers.PHI) + 1));
            }
            break;
            }

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                if (graphics != null)
                {
                    graphics.Clear(Color.Black); // set background
                    for (int i = 0; i < count; i++)
                    {
                        int dx      = 1;
                        int dy      = 1;
                        int x_shift = (bitmap.Width - dx * width) / 2;
                        int y_shift = (bitmap.Height - dy * height) / 2;

                        Color color = Color.Black;
                        if (colors.ContainsKey(values[i]))
                        {
                            color = colors[values[i]];
                        }

                        using (SolidBrush brush = new SolidBrush(color))
                        {
                            graphics.FillRectangle(brush, new Rectangle(x_shift + (i % width) * dx, y_shift + (i / width) * dy, dx, dy));
                        }
                    }
                }
            }
        }
    }