public static int[] Lerp(int[] exposure, Properties p) { double[] temp = Auxiliary.NormalizeArray(exposure); _ = Parallel.For(0, temp.Length, i => { int r = (int)Auxiliary.Lerp((double)p.From.R, (double)p.To.R, temp[i]); int g = (int)Auxiliary.Lerp((double)p.From.G, (double)p.To.G, temp[i]); int b = (int)Auxiliary.Lerp((double)p.From.B, (double)p.To.B, temp[i]); exposure[i] = 255 << 24 | r << 16 | g << 8 | b << 0; }); return(exposure); }
//Returns an array of values between 0 and 1. //public static double[] NormalizeArray(int[] exposure, double[] normalized) //{ // int min = int.MaxValue; // int max = 0; // Parallel.For(0, exposure.Length, i => // { // if (exposure[i] < min) { min = exposure[i]; } // if (exposure[i] > max) { max = exposure[i]; } // }); // _ = Parallel.For(0, exposure.Length, i => // { // double norm = Auxiliary.Normalize(exposure[i], min, max); // normalized[i] = norm; // }); // return normalized; //} //INPUT: An array of doubles //OUTPUT: An array of doubles normalized between 0 and 1 public static double[] NormalizeArray(double[] arr) { double[] norm_arr = new double[arr.Length]; double min = 99999; double max = 0; Parallel.For(0, arr.Length, i => { if (arr[i] < min) { min = arr[i]; Console.WriteLine("min: " + min); } if (arr[i] > max) { max = arr[i]; Console.WriteLine("max: " + max); } }); _ = Parallel.For(0, norm_arr.Length, i => { double norm = Auxiliary.Normalize(arr[i], min, max); norm_arr[i] = norm; }); return(norm_arr); }
public static int[] Log10Color(int[] exposure, Properties p) { Console.WriteLine(p.TimeStamp + " - Colorizing using a Log_10 algorithm."); string temp = p.Highest.ToString(); int numZeroes = temp.Length - 1; _ = Parallel.For(0, exposure.Length, i => { if (exposure[i] > 0) { double mLog = Math.Log(exposure[i], 10) / numZeroes; //dividend is the number of zeroes in the highest value in the histogram int r = (int)Math.Clamp(Auxiliary.MapDouble(mLog, 0, 1, p.From.R, p.To.R), 0, 255); int g = (int)Math.Clamp(Auxiliary.MapDouble(mLog, 0, 1, p.From.G, p.To.G), 0, 255); int b = (int)Math.Clamp(Auxiliary.MapDouble(mLog, 0, 1, p.From.B, p.To.B), 0, 255); exposure[i] = 255 << 24 | r << 16 | g << 8 | b << 0; } else { exposure[i] = 255 << 24 | 0 << 16 | 0 << 8 | 0 << 0; } }); return(exposure); }
static void UI() { List <Fractal> fractals = new List <Fractal> { //new BarnsleyFern(), //new BarnsleyFernDistance(), new Buddhabrot(pixels, domain, properties), //new BuddhabrotDistance(), //new BurningShip(), new Julia(pixels, domain, properties) //new Mandelbrot(), //new MandelbrotDistance(), //new SerpinskiTriangle() }; StringBuilder sb = new StringBuilder(); sb.Append("Enter the first number that corresponds with the fractal of your choice:\n"); for (int i = 0; i < fractals.Count; i++) { sb.Append("\t" + i + ". " + fractals[i].name + "\n"); } sb.Append("\n"); sb.Append("Enter the second number that corresponds with the coloring algorithm of your choice:\n"); sb.Append("\t0. Draw the raw iterations as a monochrome brightness value.\n"); sb.Append("\t1. Linear interpolation between two color values.\n"); sb.Append("\t2. Interpolate between two colors using log-base-ten.\n"); Console.WriteLine(sb.ToString()); //string input = Console.ReadLine(); string input = "0 3"; string[] split = input.Split(' ', '\t'); int choose_fractal = Convert.ToInt32(split[0]); int choose_colorize = Convert.ToInt32(split[1]); properties.Name = fractals[choose_fractal].name; //Console.WriteLine(properties.TimeStamp + " - Began rendering " + properties.Name); //pixels = fractals[choose_fractal].Render(properties); //Auxiliary.Save(pixels, properties.Name); pixels = Auxiliary.Load(properties.Name); Console.WriteLine(properties.TimeStamp + " - Completed rendering " + properties.Name); switch (choose_colorize) { case 0: Console.WriteLine(properties.TimeStamp + " - Began Iterations."); pixels = Stylize.Iterations(pixels, properties); Console.WriteLine(properties.TimeStamp + " - Completed Iterations."); break; case 1: Console.WriteLine(properties.TimeStamp + " - Began Lerp."); pixels = Stylize.Lerp(pixels, properties); Console.WriteLine(properties.TimeStamp + " - Completed Lerp."); break; case 2: Console.WriteLine(properties.TimeStamp + " - Began Log10Color."); pixels = Stylize.Log10Color(pixels, properties); Console.WriteLine(properties.TimeStamp + " - Completed Log10Color."); break; case 3: Console.WriteLine(properties.TimeStamp + " - Began Ramp."); pixels = Stylize.Ramp(pixels, properties, 4); Console.WriteLine(properties.TimeStamp + " - Completed Ramp."); break; case 4: Console.WriteLine(properties.TimeStamp + " - Began Sine."); pixels = Stylize.Sine(pixels, properties); Console.WriteLine(properties.TimeStamp + " - Completed sine."); break; //case 5: // break; default: break; } }