Advertisement
Adytzu04

FractalWinForm

Oct 30th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Fractals
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.            
  23.         }
  24.  
  25.         //Code for MandelbrotFractal()
  26.         public void MandelbrotFractal()
  27.         {
  28.             int c, i, j, w = pictureBox1.Width + pictureBox2.Width, h = pictureBox1.Height, m = 50;
  29.  
  30.             Bitmap b = new Bitmap(w, h);
  31.  
  32.             for (i = 0; i < w; i++)
  33.             {
  34.                 for (j = 0; j < h; j++)
  35.                 {
  36.                     double x0 = 4.0 * (i - w / 2) / w - 1;  //w-1 sets where on screen it's placed according to width
  37.                     double y0 = 4.0 * (j - h / 2) / h;
  38.                     double x = 0.0, y = 0.0;
  39.                     for (c = 0; x * x + y * y <= 4.0 && c < m; c++)
  40.                     {
  41.                         var t = x * x - y * y + x0;
  42.                         y = 2.0 * x * y + y0; x = t;
  43.                     }
  44.                     //int v = c == m ? 255 : c * 10 % 255;
  45.                     int v;
  46.                     if (c == m)
  47.                         v = 255; //interior color
  48.                     else
  49.                         v = c * 10 % 255; //exterior color
  50.                     b.SetPixel(i, j, Color.FromArgb(v, v, v));
  51.  
  52.                 }
  53.             }
  54.             pictureBox1.Image = b;
  55.         }
  56.  
  57.         private void button1_Click(object sender, EventArgs e)
  58.         {
  59.             Form1.ActiveForm.Close();
  60.         }
  61.  
  62.         private void button2_Click(object sender, EventArgs e)
  63.         {
  64.             MandelbrotFractal();
  65.         }
  66.  
  67.         private void pictureBox1_MouseEnter(object sender, EventArgs e)
  68.         {
  69.            
  70.         }
  71.         //
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement