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 WindowsFormsApplication7
- {
- public partial class Form1 : Form
- {
- private int ile_iteracji, scaling;
- double xr0,yr0, rszer, rwys;
- public Form1()
- {
- InitializeComponent();
- ile_iteracji = 10;
- scaling = 2;
- xr0 = -0.5;
- yr0 = 0.0;
- rszer = 3.0;
- rwys = 3.0;
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Close();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Rysuj();
- }
- private double Manderbrot(double a, double b)
- {
- const double inf = 3.0;
- double x = 0, y = 0, xx;
- int i;
- for(i = 0; i < ile_iteracji; i++)
- {
- xx = x * x - y * y + a;
- if (xx < -inf || xx > inf)
- break;
- y = 2 * x * y + b;
- if (y < -inf || y > inf)
- break;
- x = xx;
- }
- if (i == ile_iteracji)
- return 0;
- else
- return (double)i / (double)ile_iteracji;
- }
- private void Rysuj()
- {
- int eszer = pictureBox1.Width;
- int ewys = pictureBox1.Height;
- int xe0 = 0, ye0 = 0;
- double a, b, v;
- int r, g, bb;
- pictureBox1.Image = new Bitmap(eszer, ewys);
- Bitmap bmp = (Bitmap)pictureBox1.Image;
- Skala s = new Skala(xe0, ye0, eszer, ewys, xr0, yr0, rszer, rwys);
- for (int xe = xe0; xe < eszer; xe++)
- {
- a = s.daj_real_x(xe);
- for (int ye = ye0; ye < ewys; ye++)
- {
- b = s.daj_real_y(ye);
- v = Manderbrot(a, b);
- r = Convert.ToInt32(v * 100);
- g = Convert.ToInt32(v * 200);
- bb = Convert.ToInt32(v * 250);
- bmp.SetPixel(xe, ye, Color.FromArgb(r,g,bb));
- }
- }
- }
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
- scaling = Convert.ToInt32(textBox2.Text);
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- ile_iteracji = Convert.ToInt32(textBox1.Text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment