public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { if (FAP == null) { throw new ArgumentNullException("FAP не содержить значения!"); } if (!IsCompatible(FAP)) { throw new ArgumentException("Переданный FractalAssociationParameters не совместим с данной цветовой моделью, используйте другую цветовую модель!"); } if (FAP.FractalType != FractalType._2DStandartIterationTypeWithCloudPoints) { throw new ArgumentException("Данный фрактал не имеет трёхмерную матрицу FractalCloudPoint!"); } int width = FAP.Width, height = FAP.Height; Bitmap Result = new Bitmap(width, height); Graphics g = Graphics.FromImage(Result); g.FillRectangle(Brushes.Black, 0, 0, width, height); g.Dispose(); FractalCloudPoints fcps = (FractalCloudPoints)FAP.GetUniqueParameter(); FractalCloudPoint[][][] fcp_matrix = (FractalCloudPoint[][][])fcps.fractalCloudPoint; Color using_color; Random rand = new Random(); for (int _x = 0; _x < fcp_matrix.Length; _x++) { for (int _y = 0; _y < fcp_matrix[0].Length; _y++) { if (fcp_matrix[_x][_y].Length < fcps.MaxAmmountAtTrace) { continue; } using_color = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256)); for (int i = 0; i < fcp_matrix[_x][_y].Length; i++) { if (fcp_matrix[_x][_y][i].AbcissLocation < 0 || fcp_matrix[_x][_y][i].OrdinateLocation < 0 || fcp_matrix[_x][_y][i].AbcissLocation >= width || fcp_matrix[_x][_y][i].OrdinateLocation >= height) { continue; } Result.SetPixel(fcp_matrix[_x][_y][i].AbcissLocation, fcp_matrix[_x][_y][i].OrdinateLocation, using_color); } } } return(Result); }
protected override _2DFractal._2DFractalHelper m_create_fractal_double_version(int width, int height) { _2DFractalHelper fractal_helper = new _2DFractalHelper(this, width, height); Action <object> act = (abc) => { _m_create_part_of_fractal((AbcissOrdinateHandler)abc, fractal_helper); }; AbcissOrdinateHandler[] p_aoh = fractal_helper.CreateDataForParallelWork(f_number_of_using_threads_for_parallel); Task[] ts = new Task[f_number_of_using_threads_for_parallel]; FractalCloudPoints fcps = new FractalCloudPoints(_max_ammount_at_trace, new FractalCloudPoint[width / _abciss_step_length + (width % _abciss_step_length != 0?1:0)][][]); fractal_helper.GiveUnique(fcps); fractal_helper.GiveUnique(new RadianMatrix(width)); for (int i = 0; i < ts.Length; i++) { ts[i] = new Task(act, p_aoh[i]); ts[i].Start(); } for (int i = 0; i < ts.Length; i++) { ts[i].Wait(); } fcps.Clear(); return(fractal_helper); }
protected override void _m_create_part_of_fractal(_2DFractal.AbcissOrdinateHandler p_aoh, _2DFractal._2DFractalHelper fractal_helper) { ulong max_iter = f_iterations_count, iterations; ulong[][] iter_matrix = fractal_helper.CommonMatrix; double[][] Ratio_matrix = fractal_helper.GetRatioMatrix(), radian_matrix = ((RadianMatrix)fractal_helper.GetUnique(typeof(RadianMatrix))).Matrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point, dist, pdist = 0D, abciss_start = _2df_get_double_abciss_start(), abciss_interval_length = _2df_get_double_abciss_interval_length(), ordinate_start = _2df_get_double_ordinate_start(), ordinate_interval_length = _2df_get_double_ordinate_interval_length(); FractalCloudPoints fcps = (FractalCloudPoints)fractal_helper.GetUnique(); FractalCloudPoint[][][] fcp_matrix = fcps.fractalCloudPoint; int percent_length = fractal_helper.PercentLength, current_percent_state = percent_length; List <FractalCloudPoint> fcp_list = new List <FractalCloudPoint>(); FractalCloudPoint fcp; int fcp_height = ordinate_points.Length / _ordinate_step_length + (ordinate_points.Length % _ordinate_step_length != 0 ? 1 : 0); Complex z = new Complex(), z0 = new Complex(), last_valid_z = new Complex(); for (; p_aoh.abciss < p_aoh.end_of_abciss; p_aoh.abciss++) { abciss_point = abciss_points[p_aoh.abciss]; radian_matrix[p_aoh.abciss] = new double[ordinate_points.Length]; if (p_aoh.abciss % _abciss_step_length == 0) { fcp_matrix[p_aoh.abciss / _abciss_step_length] = new FractalCloudPoint[fcp_height][]; } for (; p_aoh.ordinate < p_aoh.end_of_ordinate; p_aoh.ordinate++) { iterations = 0; dist = 0D; z0.Real = abciss_point; z0.Imagine = ordinate_points[p_aoh.ordinate]; z.Real = z0.Real; z.Imagine = z0.Imagine; if (((p_aoh.abciss % _abciss_step_length) == 0) && ((p_aoh.ordinate % _ordinate_step_length) == 0)) { fcp_list.Clear(); for (; iterations < (ulong)_max_ammount_at_trace && dist <= 4D; iterations++) { pdist = dist; last_valid_z.Real = z.Real; last_valid_z.Imagine = z.Imagine; z.tsqr(); z.Real += z0.Real; z.Imagine += z0.Imagine; dist = (z.Real * z.Real + z.Imagine * z.Imagine); fcp.AbcissLocation = (int)((z.Real - abciss_start) / abciss_interval_length); fcp.OrdinateLocation = (int)((z.Imagine - ordinate_start) / ordinate_interval_length); fcp_list.Add(fcp); } fcp_matrix[p_aoh.abciss / _abciss_step_length][p_aoh.ordinate / _ordinate_step_length] = fcp_list.ToArray(); } for (; iterations < max_iter && dist <= 4D; iterations++) { pdist = dist; last_valid_z.Real = z.Real; last_valid_z.Imagine = z.Imagine; z.tsqr(); z.Real += z0.Real; z.Imagine += z0.Imagine; dist = (z.Real * z.Real + z.Imagine * z.Imagine); } Ratio_matrix[p_aoh.abciss][p_aoh.ordinate] = pdist; iter_matrix[p_aoh.abciss][p_aoh.ordinate] = iterations; radian_matrix[p_aoh.abciss][p_aoh.ordinate] = Math.Atan2(last_valid_z.Imagine, last_valid_z.Real); } p_aoh.ordinate = 0; if ((--current_percent_state) == 0) { current_percent_state = percent_length; f_new_percent_in_parallel_activate(); } } }