A
A
ALmA113_032020-11-02 20:39:21
C++ / C#
ALmA113_03, 2020-11-02 20:39:21

How to implement repetition of shapes in the corners?

5fa042f756185562532219.png

Hello. I need to implement the drawing of a square with repeating squares at the corners.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void DrawRectangles(Graphics g, Pen pen, Point startPoint, Size size)
        {
            if (size.Width < 40 || size.Height < 40) return;
            startPoint.Offset(-size.Width / 2, -size.Height / 2);
            var rect = new Rectangle(startPoint, size);
            g.DrawRectangle(pen, rect);

            var newSize = new Size(size.Width / 2, size.Height / 2);
            var points = new List<Point>
            {
                startPoint,
                new Point(startPoint.X + size.Width, startPoint.Y),
                new Point(startPoint.X, startPoint.Y + size.Height),
                new Point(startPoint.X + size.Width, startPoint.Y + size.Height)
            };

            points.ForEach(pt =>
            {
                DrawRectangles(g, pen, pt, newSize);
            });
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            var pen = new Pen(Color.Black, 3);
            var startPoint = new Point(0, 0);
            startPoint.Offset(Width / 2, Height / 2);
            var size = new Size(Height / 2, Height / 2);
            DrawRectangles(e.Graphics, pen, startPoint, size);
        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {
                        Refresh();

        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
                Application.Exit();
        }
    }
}


Here is my code, the square is drawn, and there is also a drawing in the corners, but it is incorrect, i.e. here the drawing depends on the size that I set, if I set <150 It will not draw anything at all, but you need to set a sort of render counter. How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2020-11-03
@vabka

Orders are accepted on Habr Freelance

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question