need code for drawing this square

6atafrak

New member
Joined
Apr 1, 2021
Messages
2
Programming Experience
Beginner
Hey guys, I need help this is code for the triangle from photo
Screenshot (2742).png


C#:
protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen p = new Pen(Color.Blue, 2);
          
            int n = 3, m = 30;
            //1st
            int x1 = 100, y1 = 500, side = 500;
            int x2 = x1 + side, y2 = y1;
            int h = (int)(side * Math.Sqrt(3) / 2);
            int x3 = (x1 + x2) / 2, y3 = y1 - h;
            g.DrawLine(p, x1, y1, x2, y2);
            g.DrawLine(p, x2, y2, x3, y3);
            g.DrawLine(p, x3, y3, x1, y1);
            //others
            for (int i = 1; i <= 80; i++)
            {
                int x = x1, y = y1;
                x1 = (n * x1 + m * x2) / (n + m);
                y1 = (n * y1 + m * y2) / (n + m);
                x2 = (n * x2 + m * x3) / (n + m);
                y2 = (n * y2 + m * y3) / (n + m);
                x3 = (n * x3 + m * x) / (n + m);
                y3 = (n * y3 + m * y) / (n + m);
                g.DrawLine(p, x1, y1, x2, y2);
                g.DrawLine(p, x2, y2, x3, y3);
                g.DrawLine(p, x3, y3, x1, y1);
            }

But I need code for drawing this square :
Screenshot (2744).png
 

Attachments

  • image_2021-04-01_145114.png
    image_2021-04-01_145114.png
    72.8 KB · Views: 21
Last edited by a moderator:
And that's what the main problem... You shouldn't have had to find the code. You should have written it yourself. Copying and pasting code doesn't teach you the programming concepts you need to learn.

The drawing is not hard. I was doing those moire patterns in BASIC when I was in 10 years old and I figured it out myself without even knowing about algebra and linear equations back then. It was just a matter of stepping the line end points.
 
Back
Top Bottom