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 koch
- {
- public partial class Form1 : Form
- {
- Graphics g;
- int count = 0;
- double distance;
- double distanceKis;
- PointF Kpont;
- PointF Lpont;
- PointF Mpont;
- public Form1()
- {
- InitializeComponent();
- g = CreateGraphics();
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- }
- public void Koch(PointF Apont, PointF Bpont)
- {
- distance = Math.Sqrt(Math.Pow(Bpont.X - Apont.X, 2) + Math.Pow(Bpont.Y - Apont.Y, 2));
- if (distanceKis < 10)
- {
- distanceKis = Math.Sqrt(3) / 2 * distance;
- // Első harmadoló
- Kpont = new PointF((2 * Apont.X + Bpont.X) / 3, (2 * Apont.Y + Bpont.Y) / 3);
- // Második harmadoló
- Lpont = new PointF((Apont.X + 2 * Bpont.X) / 3, (Apont.Y + 2 * Bpont.Y) / 3);
- // Bűűűvös pont
- Mpont = new PointF(Apont.X + (3 / 2) * (Kpont.X - Apont.X) + (float)distanceKis * (Apont.Y - Kpont.Y), Apont.Y + (3 / 2) * (Kpont.Y - Apont.Y) + (float)distanceKis * (Kpont.X - Apont.X));
- Koch(Apont, Kpont);
- Koch(Kpont, Mpont);
- Koch(Mpont, Lpont);
- Koch(Lpont, Bpont);
- }
- else
- {
- g.DrawLine(new Pen(Color.Blue), Apont, Bpont);
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Koch(new PointF(100, 20), new PointF(500, 20));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment