Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace sierpinski
- {
- public partial class Form1 : Form
- {
- Graphics g;
- Pen pen;
- PointF A, B, C;
- public Form1()
- {
- InitializeComponent();
- g = CreateGraphics();
- pen = new Pen(Color.Black);
- A = new PointF(500f, 200f);
- B = new PointF(250f, 400f);
- C = new PointF(550f, 500f);
- }
- public PointF Felez(PointF A, PointF B)
- {
- return new PointF((A.X + B.X) / 2, (A.Y + B.Y) / 2);
- }
- public double Tavolsag(PointF A, PointF B)
- {
- return Math.Sqrt((A.X - B.X) + (A.Y - B.Y));
- }
- public void Sierp(PointF A, PointF B, PointF C)
- {
- PointF AB = Felez(A, B);
- PointF AC = Felez(A, C);
- PointF BC = Felez(B, C);
- if (Tavolsag(A, B) >= 1)
- {
- Sierp(A, AB, AC);
- Sierp(B, BC, AB);
- Sierp(C, BC, AC);
- }
- if (Tavolsag(A, C) >= 1)
- {
- Sierp(A, AB, AC);
- Sierp(B, BC, AB);
- Sierp(C, BC, AC);
- }
- if (Tavolsag(B, C) >= 1)
- {
- Sierp(A, AB, AC);
- Sierp(B, BC, AB);
- Sierp(C, BC, AC);
- }
- else
- {
- //Kirajzolás
- var points = new PointF[] { A, B, C };
- g.DrawPolygon(pen, points);
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Sierp(A, B, C);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement