private List <Point> GetTrianglePoints()
        {
            Int32            sideA            = (Int32)SideALength.Value;
            Int32            sideB            = (Int32)SideBLength.Value;
            Int32            sideC            = (Int32)SideCLength.Value;
            Double           interval         = (Double)Interval.Value;
            DrawingDirection drawingDirection = GetDrawingDirection();

            if (!Triangle.IsExist(sideA, sideB, sideC))
            {
                MessageBox.Show(
                    text: @"A triangle with such sides does not exist.",
                    caption: @"Error"
                    );

                return(null);
            }

            var triangleCoordinateCalculator = new TriangleCoordinateCalculator();
            var triangle = triangleCoordinateCalculator.Calculate(sideA, sideB, sideC, PictureBox.Width, PictureBox.Height);

            var pointsBuilder = new PointsBuilder();
            var points        = pointsBuilder.Build(triangle.ToPolygon(), interval, drawingDirection);

            return(points);
        }
Пример #2
0
        public List <Point> Build(Polygon polygon, Double interval, DrawingDirection direction)
        {
            List <Point> points = polygon.Vertices.Select(v => new Point(v)).ToList();
            List <Point> basis  = polygon.Vertices.Select(v => new Point(v)).ToList();

            switch (direction)
            {
            case DrawingDirection.Clockwise:
                break;

            case DrawingDirection.Anticlockwise:
                points.Reverse();
                basis.Reverse();
                break;

            default:
                throw new ArgumentException($"{nameof(DrawingDirection)}.{direction} is not supported");
            }

            points.Add(new Point(points[0]));

            Int32 recalculatedIndex = 1;
            Int32 nextIndex         = GetNextIndex(recalculatedIndex, basis.Count);

            while (Point.SegmentLength(basis[recalculatedIndex], basis[nextIndex]) - interval > 1e-2)
            {
                Point newPoint = CalculateNewPoint(basis[recalculatedIndex], basis[nextIndex], interval);
                points.Add(new Point(newPoint));
                basis[recalculatedIndex] = new Point(newPoint);
                recalculatedIndex        = nextIndex;
                nextIndex = GetNextIndex(recalculatedIndex, basis.Count);
            }

            return(points);
        }
Пример #3
0
        public override void CopyFrom(DxfHandledObject from, CloneContext cloneContext)
        {
            base.CopyFrom(from, cloneContext);
            DxfMText dxfMtext = (DxfMText)from;

            this.string_1              = dxfMtext.string_1;
            this.Style                 = Class906.GetTextStyle(cloneContext, dxfMtext.Style);
            this.point3D_0             = dxfMtext.point3D_0;
            this.double_1              = dxfMtext.double_1;
            this.double_2              = dxfMtext.double_2;
            this.double_3              = dxfMtext.double_3;
            this.attachmentPoint_0     = dxfMtext.attachmentPoint_0;
            this.drawingDirection_0    = dxfMtext.drawingDirection_0;
            this.vector3D_0            = dxfMtext.vector3D_0;
            this.vector3D_1            = dxfMtext.vector3D_1;
            this.lineSpacingStyle_0    = dxfMtext.lineSpacingStyle_0;
            this.double_4              = dxfMtext.double_4;
            this.backgroundFillFlags_0 = dxfMtext.backgroundFillFlags_0;
            if (dxfMtext.backgroundFillInfo_0 == null)
            {
                this.backgroundFillInfo_0 = (BackgroundFillInfo)null;
            }
            else
            {
                this.backgroundFillInfo_0 = dxfMtext.backgroundFillInfo_0.Clone(cloneContext);
            }
        }
Пример #4
0
 override public void DrawArrow(int x, int y, int size, DrawingDirection direction, BasicColor color) {
     BasicTypeSerializer.Put(Context,(byte)Command.DrawArrow);
     BasicTypeSerializer.Put(Context,(ushort)x);
     BasicTypeSerializer.Put(Context,(ushort)y);
     BasicTypeSerializer.Put(Context,(ushort)size);
     BasicTypeSerializer.Put(Context,(ushort)direction);
     BasicTypeSerializer.Put(Context,(ushort)color);
 }
Пример #5
0
 override public void DrawArrow(int x, int y, int size, DrawingDirection direction, BasicColor color)
 {
     BasicTypeSerializer.Put(Context, (byte)Command.DrawArrow);
     BasicTypeSerializer.Put(Context, (ushort)x);
     BasicTypeSerializer.Put(Context, (ushort)y);
     BasicTypeSerializer.Put(Context, (ushort)size);
     BasicTypeSerializer.Put(Context, (ushort)direction);
     BasicTypeSerializer.Put(Context, (ushort)color);
 }
Пример #6
0
 public void DrawArrow(int x, int y, int size, DrawingDirection direction, ushort color) {
     BasicTypeSerializer.Put(SendContext,(byte)Command.DrawArrow);
     BasicTypeSerializer.Put(SendContext,(ushort)x);
     BasicTypeSerializer.Put(SendContext,(ushort)y);
     BasicTypeSerializer.Put(SendContext,(ushort)size);
     BasicTypeSerializer.Put(SendContext,(ushort)direction);
     BasicTypeSerializer.Put(SendContext,(ushort)color);
     SendContext.CheckHighWatermark();
 }
Пример #7
0
        private void DrawButton_Click(Object sender, EventArgs e)
        {
            Int32            sideA            = (Int32)SideALength.Value;
            Int32            sideB            = (Int32)SideBLength.Value;
            Int32            sideC            = (Int32)SideCLength.Value;
            Double           interval         = (Double)Interval.Value;
            DrawingDirection drawingDirection = GetDrawingDirection();

            if (!Triangle.IsExist(sideA, sideB, sideC))
            {
                MessageBox.Show(
                    text: @"A triangle with such sides does not exist.",
                    caption: @"Error"
                    );

                return;
            }

            var triangleCoordinateCalculator = new TriangleCoordinateCalculator();
            var triangle = triangleCoordinateCalculator.Calculate(sideA, sideB, sideC, PictureBox.Width, PictureBox.Height);

            var pointsBuilder = new PointsBuilder();
            var points        = pointsBuilder.Build(triangle.ToPolygon(), interval, drawingDirection);

            using (var graphic = PictureBox.CreateGraphics())
            {
                graphic.Clear(Color.White);

                Pen pen = new Pen(Color.Blue, 1.0f);

                graphic.DrawLines(
                    pen,
                    points.Select(p => new PointF((float)p.X, (float)p.Y)).ToArray()
                    );
            }
        }
Пример #8
0
 public Game(string[] clues, string secretWord, Difficulty difficulty, DrawingMode drawingMode, DrawingDirection drawingDirection, GameImage image)
 {
     this.clues            = clues;
     this.secretWord       = secretWord;
     this.difficulty       = difficulty;
     this.drawingMode      = drawingMode;
     this.drawingDirection = drawingDirection;
     this.image            = image;
 }
Пример #9
0
    public static void GeneratePrimeSquareSpiralBitmaps(Color color1, Color color2)
    {
        using (Bitmap bitmap = new Bitmap(WIDTH, HEIGHT, PixelFormat.Format24bppRgb))
        {
            if (bitmap != null)
            {
                // initialize first step
                int x = (WIDTH / 2) - 1;
                int y = (HEIGHT / 2);
                DrawingDirection direction = DrawingDirection.Right;
                int steps           = 1;
                int remaining_steps = steps;

                Color color = Color.Black;
                int   max   = WIDTH * HEIGHT;
                int   count = 0;
                for (int i = 0; i < max; i++)
                {
                    if (Numbers.IsAdditivePrime(i + 1))
                    {
                        color = color2;
                    }
                    else if (Numbers.IsNonAdditivePrime(i + 1))
                    {
                        color = color1;
                    }
                    else
                    {
                        color = Color.Black;
                    }
                    count += (color != Color.Black) ? 1 : 0;

                    bitmap.SetPixel(x, y, color);

                    // has direction finished?
                    if (remaining_steps == 0)
                    {
                        // change direction
                        switch (direction)
                        {
                        case DrawingDirection.Right: { direction = DrawingDirection.Up; } break;

                        case DrawingDirection.Up: { direction = DrawingDirection.Left; steps++; } break;

                        case DrawingDirection.Left: { direction = DrawingDirection.Down; } break;

                        case DrawingDirection.Down: { direction = DrawingDirection.Right; steps++; } break;
                        }
                        remaining_steps = steps;
                    }

                    // move one step in current direction
                    switch (direction)
                    {
                    case DrawingDirection.Right: x += 1; break;

                    case DrawingDirection.Up: y -= 1; break;

                    case DrawingDirection.Left: x -= 1; break;

                    case DrawingDirection.Down: y += 1; break;
                    }

                    // one step done
                    remaining_steps--;
                }

                String filename = String.Format("PrimeSquareSpiral_{0:000}x{1:000}_{2:0000}.bmp", WIDTH, HEIGHT, count);
                SaveDrawing(filename, bitmap);
            }
        }
    }
Пример #10
0
    private static void DrawPointsSquareSpiral(Bitmap bitmap, List <long> values, Dictionary <long, Color> colors)
    {
        using (Graphics graphics = Graphics.FromImage(bitmap))
        {
            if (graphics != null)
            {
                graphics.Clear(Color.Black); // set background
                int count   = values.Count;
                int width   = (int)(Math.Sqrt(count) + 1);
                int height  = width;
                int dx      = 1;
                int dy      = 1;
                int x_shift = (bitmap.Width - dx * width) / 2;
                int y_shift = (bitmap.Height - dy * height) / 2;
                int x       = (bitmap.Width - x_shift) / 2;
                int y       = (bitmap.Height - y_shift) / 2;

                DrawingDirection direction = DrawingDirection.Right;
                int steps = 1;
                int steps_in_directoin = steps;

                if (values != null)
                {
                    for (int i = 0; i < count; i++)
                    {
                        Color color = Color.Black;
                        if (colors.ContainsKey(values[i]))
                        {
                            color = colors[values[i]];
                        }

                        using (SolidBrush brush = new SolidBrush(color))
                        {
                            graphics.FillRectangle(brush, x, y, dx, dy);
                        }

                        // has direction finished?
                        if (steps == 0)
                        {
                            // change direction
                            switch (direction)
                            {
                            case DrawingDirection.Right: { direction = DrawingDirection.Up; } break;

                            case DrawingDirection.Up: { direction = DrawingDirection.Left; steps_in_directoin++; } break;

                            case DrawingDirection.Left: { direction = DrawingDirection.Down; } break;

                            case DrawingDirection.Down: { direction = DrawingDirection.Right; steps_in_directoin++; } break;
                            }
                            steps = steps_in_directoin;
                        }

                        // move one step in current direction
                        switch (direction)
                        {
                        case DrawingDirection.Right: x += dx; break;

                        case DrawingDirection.Up: y -= dy; break;

                        case DrawingDirection.Left: x -= dx; break;

                        case DrawingDirection.Down: y += dy; break;
                        }

                        // one step done
                        steps--;
                    }
                }
            }
        }
    }
Пример #11
0
    private static void DrawValuesSquareSpiral(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.Sqrt(count) + 1);
                int height  = width;
                int dx      = 1;
                int dy      = 1;
                int x_shift = (bitmap.Width - dx * width) / 2;
                int y_shift = (bitmap.Height - dy * height) / 2;
                int x       = (bitmap.Width - x_shift) / 2;
                int y       = (bitmap.Height - y_shift) / 2;

                DrawingDirection direction = DrawingDirection.Right;
                int steps = 1;
                int steps_in_directoin = steps;

                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);
                    }

                    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, x, y, dx, dy);
                        }

                        // has direction finished?
                        if (steps == 0)
                        {
                            // change direction
                            switch (direction)
                            {
                            case DrawingDirection.Right: { direction = DrawingDirection.Up; } break;

                            case DrawingDirection.Up: { direction = DrawingDirection.Left; steps_in_directoin++; } break;

                            case DrawingDirection.Left: { direction = DrawingDirection.Down; } break;

                            case DrawingDirection.Down: { direction = DrawingDirection.Right; steps_in_directoin++; } break;
                            }
                            steps = steps_in_directoin;
                        }

                        // move one step in current direction
                        switch (direction)
                        {
                        case DrawingDirection.Right: x += dx; break;

                        case DrawingDirection.Up: y -= dy; break;

                        case DrawingDirection.Left: x -= dx; break;

                        case DrawingDirection.Down: y += dy; break;
                        }

                        // one step done
                        steps--;
                    }
                }
            }
        }
    }
Пример #12
0
 // Draws a simple arrow of the specified width
 // x: X co-ordinate of the smallest point of the arrow
 // y: Y co-ordinate of the smallest point of the arrow
 // size: Total width/height of the arrow in pixels
 // direction: The direction that the arrow is pointing
 // color: Color used when drawing
 public virtual void DrawArrow(int x, int y, int size, DrawingDirection direction, BasicColor color)
 {
     DrawPixel(x, y, color);
     if (size == 1) {
         return;
     }
     var i = 0;
     switch (direction) {
         case DrawingDirection.Left:
             for (i = 1; i < size; i++) {
                 DrawLine(x + i, y - i, x + i, y + i, color);
             }
             break;
         case DrawingDirection.Right:
             for (i = 1; i < size; i++) {
                 DrawLine(x - i, y - i, x - i, y + i, color);
             }
             break;
         case DrawingDirection.Up:
             for (i = 1; i < size; i++) {
                 DrawLine(x - i, y + i, x + i, y + i, color);
             }
             break;
         case DrawingDirection.Down:
             for (i = 1; i < size; i++) {
                 DrawLine(x - i, y - i, x + i, y - i, color);
             }
             break;
         default:
             break;
     }
 }
Пример #13
0
    void CreateTriangleIndicesForCap(int point1, int point2, int point3, int startingIndex, ref int[] indices, DrawingDirection drawingDirection)
    {
        int originalPoint2 = point2;

        for (int i = 0; i < capResolution; i++)
        {
            //If final triangle of cap
            if (i == capResolution - 1)
            {
                point3 = originalPoint2;
            }
            indices[startingIndex] = point1;
            startingIndex++;
            switch (drawingDirection)
            {
            case DrawingDirection.Clockwise:
            {
                indices[startingIndex] = point2;
                startingIndex++;
                point2++;
                indices[startingIndex] = point3;
                startingIndex++;
                point3++;
                break;
            }

            case DrawingDirection.Counterclockwise:
            {
                indices[startingIndex] = point3;
                startingIndex++;
                point3++;
                indices[startingIndex] = point2;
                startingIndex++;
                point2++;
                break;
            }
            }
        }
    }
Пример #14
0
 public void DrawArrow(int x, int y, int size, DrawingDirection direction, ushort color)
 {
     BasicTypeSerializer.Put(SendContext,(byte)Command.DrawArrow);
     BasicTypeSerializer.Put(SendContext,(ushort)x);
     BasicTypeSerializer.Put(SendContext,(ushort)y);
     BasicTypeSerializer.Put(SendContext,(ushort)size);
     BasicTypeSerializer.Put(SendContext,(ushort)direction);
     BasicTypeSerializer.Put(SendContext,(ushort)color);
     SendContext.CheckHighWatermark();
 }
Пример #15
0
        internal static IList <Class908> smethod_1(
            string text,
            double width,
            double height,
            AttachmentPoint attachmentPoint,
            double lineSpacingFactor,
            LineSpacingStyle lineSpacingStyle,
            DxfTextStyle style,
            double widthFactor,
            Color color,
            DrawingDirection drawingDirection,
            short lineWeight,
            Matrix4D insertionTransformation,
            Class985 resultLayoutInfo,
            Enum24 whiteSpaceHandlingFlags)
        {
            Class1023[]      class1023Array = Class594.smethod_12(text, width, height, attachmentPoint, lineSpacingFactor, lineSpacingStyle, style, widthFactor, color, drawingDirection);
            Vector2D         zero           = Vector2D.Zero;
            IList <Class908> class908List   = (IList <Class908>) new List <Class908>();
            Bounds2D         bounds         = new Bounds2D();

            foreach (Class1023 class1023 in class1023Array)
            {
                class1023.imethod_0(ref zero, class1023.Settings.Height, whiteSpaceHandlingFlags);
                bounds.Update(class1023.GetBounds(whiteSpaceHandlingFlags, resultLayoutInfo));
            }
            double num1 = 0.0;
            double num2 = 0.0;

            if (bounds.Initialized)
            {
                switch (attachmentPoint)
                {
                case AttachmentPoint.TopLeft:
                    num1 = -bounds.Corner1.X;
                    num2 = -bounds.Corner2.Y;
                    break;

                case AttachmentPoint.TopCenter:
                    num1 = -bounds.Center.X;
                    num2 = -bounds.Corner2.Y;
                    break;

                case AttachmentPoint.TopRight:
                    num1 = -bounds.Corner2.X;
                    num2 = -bounds.Corner2.Y;
                    break;

                case AttachmentPoint.MiddleLeft:
                    num1 = -bounds.Corner1.X;
                    num2 = -bounds.Center.Y;
                    break;

                case AttachmentPoint.MiddleCenter:
                    num1 = -bounds.Center.X;
                    num2 = -bounds.Center.Y;
                    break;

                case AttachmentPoint.MiddleRight:
                    num1 = -bounds.Corner2.X;
                    num2 = -bounds.Center.Y;
                    break;

                case AttachmentPoint.BottomLeft:
                    num1 = -bounds.Corner1.X;
                    num2 = -bounds.Corner1.Y;
                    break;

                case AttachmentPoint.BottomCenter:
                    num1 = -bounds.Center.X;
                    num2 = -bounds.Corner1.Y;
                    break;

                case AttachmentPoint.BottomRight:
                    num1 = -bounds.Corner2.X;
                    num2 = -bounds.Corner1.Y;
                    break;
                }
            }
            if (width == 0.0)
            {
                num1 = 0.0;
            }
            Vector2D vector2D = new Vector2D(num1, num2);

            foreach (Class1023 class1023 in class1023Array)
            {
                class1023.Offset += vector2D;
                class1023.imethod_3((ICollection <Class908>)class908List, insertionTransformation, lineWeight);
            }
            if (resultLayoutInfo != null)
            {
                bounds.Move(num1, num2);
                resultLayoutInfo.Bounds.Update(bounds);
                if (resultLayoutInfo.FirstLineBounds != null)
                {
                    resultLayoutInfo.FirstLineBounds.Move(num1, num2);
                }
                if (resultLayoutInfo.LastLineBounds != null && resultLayoutInfo.LastLineBounds != resultLayoutInfo.FirstLineBounds)
                {
                    resultLayoutInfo.LastLineBounds.Move(num1, num2);
                }
            }
            return(class908List);
        }