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 hermit_gorbe
- {
- public partial class Form1 : Form
- {
- Graphics g;
- List<Point> points = new List<Point>();
- List<HermitPoints> hermits = new List<HermitPoints>();
- public Form1()
- {
- InitializeComponent();
- g = CreateGraphics();
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- MouseClick += new MouseEventHandler(Form1_MouseClick);
- }
- void Form1_MouseClick(object sender, MouseEventArgs e)
- {
- if (points.Count < 4)
- {
- points.Add(e.Location);
- DrawPoints();
- if (points.Count == 4)
- {
- hermits.Add(new HermitPoints(points[0], points[1], points[2], points[3]));
- for (int i = 0; i < 3; i++)
- {
- points.RemoveAt(0);
- }
- }
- }
- else
- {
- MessageBox.Show("4 pontot tehetsz!");
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (hermits.Count < 1)
- {
- MessageBox.Show("Legalább 4 pont kell a hermit görbéhez! Neked csak " + points.Count + " pontod van.");
- }
- else
- {
- Invalidate();
- Update();
- DrawPoints();
- DrawHermit();
- }
- }
- public void DrawHermit()
- {
- for (int i = 0; i < hermits.Count; i++)
- {
- for (float u = 0; u <= 1; u = u + 0.01f)
- {
- double x = CalculateHermit(hermits[i].Start.X, hermits[i].End.X, hermits[i].startDirection.X - hermits[i].Start.X, hermits[i].End.X - hermits[i].endDirection.X, u);
- double y = CalculateHermit(hermits[i].Start.Y, hermits[i].End.Y, hermits[i].startDirection.Y - hermits[i].Start.Y, hermits[i].End.Y - hermits[i].endDirection.Y, u);
- g.FillEllipse(Brushes.Black, Convert.ToInt32(x - 2), Convert.ToInt32(y - 2), 4, 4);
- }
- }
- points.Clear();
- hermits.Clear();
- }
- public double CalculateHermit(float a0, float a1, float a2, float a3, float u)
- {
- return (2 * Math.Pow(u, 3) - 3 * Math.Pow(u, 2) + 1) * a0 + (-2 * Math.Pow(u, 3) + 3 * Math.Pow(u, 2)) * a1 + (Math.Pow(u, 3) - 2 * Math.Pow(u, 2) + u) * a2 + (Math.Pow(u, 3) - Math.Pow(u, 2)) * a3;
- }
- public void DrawPoints()
- {
- foreach (var p in points)
- {
- g.DrawEllipse(Pens.Blue, p.X - 5, p.Y - 5, 10, 10);
- g.FillEllipse(Brushes.Red, p.X - 5, p.Y - 5, 10, 10);
- }
- foreach (var h in hermits)
- {
- // NINCS KÉSZ MÉG
- g.DrawEllipse(Pens.Blue, h.Start.X - 5, h.Start.Y - 5, 10, 10);
- g.FillEllipse(Brushes.Red, h.Start.X - 5, h.Start.Y - 5, 10, 10);
- g.DrawEllipse(Pens.Blue, h.Start.X - 5, h.Start.Y - 5, 10, 10); // startdirection
- g.FillEllipse(Brushes.Red, h.Start.X - 5, h.Start.Y - 5, 10, 10);
- g.DrawEllipse(Pens.Blue, h.Start.X - 5, h.Start.Y - 5, 10, 10); // enddirection
- g.FillEllipse(Brushes.Red, h.Start.X - 5, h.Start.Y - 5, 10, 10);
- g.DrawEllipse(Pens.Blue, h.Start.X - 5, h.Start.Y - 5, 10, 10);
- g.FillEllipse(Brushes.Red, h.Start.X - 5, h.Start.Y - 5, 10, 10); // end
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement