示例#1
0
        /// <summary>
        /// Calculate and generate the fractalpart pixels and store in pixels array
        /// </summary>
        private async void generateFractalPart(FractalPart part, FractalTemplate.FractalTemplate fractal, Action<FractalPart> callback)
        {
            part.imageArray = new byte[part.getWidth() * part.getHeight() * 4];
            //Call the calculat fractal method
            int[,] pixels = fractal.calculate(part);
            //Generate bitmap from pixeldata
            int x = 0;
            int y = 0;
            for (int i = 0; i < part.imageArray.Length; i += 4)
            {
                //BGRA format
                int R = 0, G = 0, B = 0;

                if (fractal.getColor().R != 0 && fractal.getColor().G != 0 && fractal.getColor().B != 0)
                {
                    R = pixels[x, y] % this.fractal.getColor().R;
                    G = pixels[x, y] % this.fractal.getColor().G;
                    B = pixels[x, y] % this.fractal.getColor().B;
                }
                else
                {
                    R = pixels[x, y];
                    G = pixels[x, y];
                    B = pixels[x, y];
                }

                part.imageArray[i] = Convert.ToByte(B); //blue
                part.imageArray[i + 1] = Convert.ToByte(G); //green
                part.imageArray[i + 2] = Convert.ToByte(R); //red
                part.imageArray[i + 3] = 255; // Alpha
                x++;
                if (x == part.getWidth())
                {
                    y++;
                    x = 0;
                }
            }

            //Callback to UI thread when generating is done, add to list and refresh current fractal parts on screen
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,  () =>
            {
                //callback to notify we are done
                callback(part);
            });

        }
示例#2
0
 /// <summary>
 /// Set current template to draw fractal parts with
 /// </summary>
 public void setTemplate(FractalTemplate.FractalTemplate fractal)
 {
     this.fractal = fractal;
 }