I am trying to figure out a way to zoom in on my Mandelbrot set on click. I have it so when I click it slightly zooms in but it doesn't move the Mandelbrot accordingly.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Numerics;
namespace Project_V2
{
public partial class FractalGen : Form
{
public double zoom = 2.4;
public FractalGen()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
zoom -= 0.3;
Mandelbrot();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
Mandelbrot();
}
private void timer1_Tick(object sender, EventArgs e)
{
}
private void Mandelbrot()
{
Bitmap bm = new Bitmap(pictureBox1.Width, pictureBox1.Height);
DateTime StartT = DateTime.Now;
for (int x = 0; x < pictureBox1.Width; x++)
{
for (int y = 0; y < pictureBox1.Height; y++)
{
double a = (double)(x - (pictureBox1.Width / 1.25)) / (double)(pictureBox1.Width / zoom);
double b = (double)(y - (pictureBox1.Height / 2)) / (double)(pictureBox1.Height / zoom);
Complex C = new Complex(a, b);
Complex Z = new Complex(0, 0);
int u = 0;
do
{
u++;
Z = Z * Z;
Z = Z + C;
double Mag = Complex.Abs(Z);
if (Mag > 2.0) break;
} while (u < 255);
Color rgbInside = Color.FromArgb(0, 0, 0);
Color rgbOutside = Color.FromArgb(u >= 127 ? 255 : 2 * u, u >= 127 ? (u - 127) : 0, 0);
bm.SetPixel(x, y, u < 255 ? rgbOutside : rgbInside);
}
}
pictureBox1.Image = bm;
DateTime EndT = DateTime.Now;
string Time = Convert.ToString((EndT - StartT).TotalSeconds);
textBox1.Text = "Time Taken: " + Time + " Seconds";
}
private void button1_Click_1(object sender, EventArgs e)
{
zoom = 2.4;
Mandelbrot();
}
private void button2_Click(object sender, EventArgs e)
{
saveFileDialog1.ShowDialog();
}
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
string name = saveFileDialog1.FileName;
pictureBox1.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png);
}
}
}
The current code divides the picturebox width and height by a value, but I want to have it so it zooms in on where I click. How could I scale the picturebox in relation to where I click?