Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Windows.Forms.DataVisualization.Charting;
- namespace jedenplusjeden
- {
- public partial class Form1 : Form
- {
- public double rozrzut = 10;
- public double wspp = 1.1;
- public int l_iteracji = 100;
- public double x = 0;
- public double y = 0;
- public Form1()
- {
- InitializeComponent();
- }
- public double ObliczY(double x)
- {
- return Math.Sin((double)x / 10) * Math.Sin((double)x / 200);
- }
- public void UstawXiY()
- {
- var random = new Random();
- x = random.Next(0, 100);
- y = ObliczY(x);
- }
- public void RysujLinie()
- {
- chart1.Series.Clear();
- var seria = new Series() { ChartType = SeriesChartType.Line };
- for (int x = 0; x < 101; x++)
- {
- var y = ObliczY(x);
- seria.Points.Add(new DataPoint(x, y));
- }
- chart1.Series.Add(seria);
- var seria2 = new Series() { ChartType = SeriesChartType.Point };
- chart1.Series.Add(seria2);
- }
- public void SzukajPunktu()
- {
- var random = new Random();
- var r = random.Next(Convert.ToInt32(rozrzut * -100), Convert.ToInt32(rozrzut * 100));
- var xPot = x + (double)r / 100;
- if (xPot > 100)
- {
- xPot -= rozrzut;
- }
- else if (xPot < 0)
- {
- xPot += rozrzut;
- }
- var yPot = ObliczY(xPot);
- if (yPot > y)
- {
- var point = new DataPoint(xPot, yPot) { Color = Color.Green };
- chart1.Series[1].Points.Add(point);
- rozrzut *= 1.1;
- x = xPot;
- y = yPot;
- }
- else
- {
- var point = new DataPoint(xPot, yPot) { Color = Color.Red };
- chart1.Series[1].Points.Add(point);
- rozrzut /= 1.1;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- SzukajPunktow();
- }
- public async void SzukajPunktow()
- {
- RysujLinie();
- UstawXiY();
- for (int i = 0; i < 100; i++)
- {
- await Task.Delay(1000);
- SzukajPunktu();
- textBox1.Text = "Krok: " + (i + 1) + ". x-" + x + " y-" + y + " rozrzut-" + rozrzut;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement