Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Numerics;
- namespace ConsoleApp1
- {
- class ImageProcessor
- {
- private int height;
- private int width;
- private double xRadius;
- private double yRadius;
- private double xInterval;
- private double yInterval;
- private double xStart;
- private double yStart;
- private double magMax;
- private ColourCalculator calculator;
- public ImageProcessor(int width, int height, double xRadius, double yRadius, double magMax = -1, double xStart = 0, double yStart = 0)
- {
- this.height = height;
- this.width = width;
- this.xRadius = xRadius;
- this.yRadius = yRadius;
- this.calculator = new ColourCalculator(xRadius, yRadius);
- this.xInterval = (2*(double)xRadius) / (double)width;
- this.yInterval = (2*(double)yRadius) / (double)height;
- this.xStart = xStart;
- this.yStart = yStart;
- this.magMax = magMax;
- }
- public void DrawIterative(Equation equation, string filepath, bool BW = true)
- {
- Bitmap map = new Bitmap(width, height);
- double x = xRadius + xStart;
- double y = yRadius + yStart;
- Color[,] rawData = new Color[width,height];
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- try
- {
- map.SetPixel(i, j, calculator.CalculateColor(equation.ComputeIterate(new Complex(x, y)), equation.itMax, BW));
- }
- catch (DivideByZeroException)
- {
- map.SetPixel(i, j, Color.White);
- }
- y -= yInterval;
- }
- y = yRadius;
- x -= xInterval;
- }
- map.Save(filepath);
- }
- public void DrawImage(Equation equation, string filepath, bool shade = false)
- {
- if (magMax < 0 && shade)
- {
- calculator.maxMag = CalculateMaxMag(equation);
- }
- else if (shade)
- {
- calculator.maxMag = magMax;
- }
- Bitmap map = new Bitmap(width, height);
- double x = xRadius + xStart;
- double y = yRadius + yStart;
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- try
- {
- map.SetPixel(i, j, calculator.CalculateColor(equation.Compute(new Complex(x, y)), shade));
- }
- catch (DivideByZeroException)
- {
- map.SetPixel(i, j, Color.White);
- }
- y -= yInterval;
- }
- y = yRadius + yStart;
- x -= xInterval;
- }
- map.Save(filepath);
- }
- private double CalculateMaxMag(Equation equation)
- {
- double average = 0;
- double max = 0;
- double x = xRadius;
- double y = yRadius;
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- try
- {
- double magnitude = equation.Compute(new Complex(x, y)).Magnitude;
- if (magnitude > max)
- {
- max = magnitude;
- }
- average += magnitude;
- }
- catch (DivideByZeroException)
- {
- }
- y -= yInterval;
- }
- y = yRadius;
- x -= xInterval;
- }
- average = average / (height * width);
- return average;
- }
- }
- }
Add Comment
Please, Sign In to add comment