private void DisplayNewBitmap(BitmapInfo bitmapInfo) { BmpMaker bmpMaker = new BmpMaker(bitmapInfo.PixelWidth, bitmapInfo.PixelHeight); int index = 0; for (int row = 0; row < bitmapInfo.PixelHeight; row++) { for (int col = 0; col < bitmapInfo.PixelWidth; col++) { int iterationCount = bitmapInfo.IterationCounts[index++]; if (iterationCount == -1) { bmpMaker.SetPixel(row, col, 0, 0, 0); } else { double proportion = (iterationCount / 32.0) % 1; if (proportion < 0.5) { bmpMaker.SetPixel(row, col, (int)(255 * (1 - 2 * proportion)), 0, (int)(255 * 2 * proportion)); } else { proportion = 2 * (proportion - 0.5); bmpMaker.SetPixel(row, col, 0, (int)(255 * proportion), (int)(255 * (1 - proportion))); } } } } image.Source = bmpMaker.Generate(); }
async void OnCalculateButtonClicked(object sender, EventArgs args) { // Configure the UI for a background process. calculateButton.IsEnabled = false; cancelButton.IsEnabled = true; cancelTokenSource = new CancellationTokenSource(); try { // Render the Mandelbrot set on a bitmap. BmpMaker bmpMaker = await CalculateMandelbrotAsync(progressReporter, cancelTokenSource.Token); image.Source = bmpMaker.Generate(); } catch (OperationCanceledException) { calculateButton.IsEnabled = true; progressBar.Progress = 0; } catch (Exception) { // Shouldn't occur in this case. } cancelButton.IsEnabled = false; }
public MandelbrotXFPage() { InitializeComponent(); mandelbrotViewModel = new MandelbrotViewModel(2.5, 2.5) { PixelWidth = 1000, PixelHeight = 1000, CurrentCenter = new Complex(GetProperty("CenterReal", -0.75), GetProperty("CenterImaginary", 0.0)), CurrentMagnification = GetProperty("Magnification", 1.0), TargetMagnification = GetProperty("Magnification", 1.0), Iterations = GetProperty("Iterations", 8), RealOffset = 0.5, ImaginaryOffset = 0.5 }; BindingContext = mandelbrotViewModel; mandelbrotViewModel.PropertyChanged += OnMandelbrotViewModelPropertyChanged; BmpMaker bmpMaker = new BmpMaker(120, 120); testImage.SizeChanged += (sender, args) => { pixelsPerUnit = bmpMaker.Width / testImage.Width; SetPixelWidthAndHeight(); }; testImage.Source = bmpMaker.Generate(); Device.StartTimer(TimeSpan.FromMilliseconds(100), () => { realCrossHair.Opacity -= 0.01f; imageCrossHair.Opacity -= 0.01f; return(true); }); }
async void OnCalculateButtonClicked(object sender, EventArgs e) { calculateButton.IsEnabled = false; BmpMaker bmpMaker = await CalculateMandelbrotAsync(progressReporter); image.Source = bmpMaker.Generate(); }
async void OnCalculateButtonClicked(object sender, EventArgs args) { // Configure the UI for a background process. calculateButton.IsEnabled = false; // Render the Mandelbrot set on a bitmap. BmpMaker bmpMaker = await CalculateMandelbrotAsync(progressReporter); image.Source = bmpMaker.Generate(); }
private async void OnCalculateButtonClicked(object sender, EventArgs e) { calculateButton.IsEnabled = false; activityIndicator.IsRunning = true; BmpMaker bmpMaker = new BmpMaker(pixelWidth, pixelHeight); await CalculateMandelbrotAsync(bmpMaker); image.Source = bmpMaker.Generate(); activityIndicator.IsRunning = false; }
async void OnCalculateButtonClicked(object sender, EventArgs args) { // Configure the UI for a background process. calculateButton.IsEnabled = false; activityIndicator.IsRunning = true; // Render the Mandelbrot set on a bitmap. BmpMaker bmpMaker = new BmpMaker(pixelWidth, pixelHeight); await CalculateMandelbrotAsync(bmpMaker); image.Source = bmpMaker.Generate(); // Configure the UI for the completed background process. activityIndicator.IsRunning = false; }
void DisplayNewBitmap(BitmapInfo bitmapInfo) { // Create the bitmap. BmpMaker bmpMaker = new BmpMaker(bitmapInfo.PixelWidth, bitmapInfo.PixelHeight); // Set the colors. int index = 0; for (int row = 0; row < bitmapInfo.PixelHeight; row++) { for (int col = 0; col < bitmapInfo.PixelWidth; col++) { int iterationCount = bitmapInfo.IterationCounts[index++]; // In the Mandelbrot set: Color black. if (iterationCount == -1) { bmpMaker.SetPixel(row, col, 0, 0, 0); } // Not in the Mandelbrot set: Pick a color based on count. else { double proportion = (iterationCount / 32.0) % 1; if (proportion < 0.5) { bmpMaker.SetPixel(row, col, (int)(255 * (1 - 2 * proportion)), 0, (int)(255 * 2 * proportion)); } else { proportion = 2 * (proportion - 0.5); bmpMaker.SetPixel(row, col, 0, (int)(255 * proportion), (int)(255 * (1 - proportion))); } } } } image.Source = bmpMaker.Generate(); }
public MandelbrotXFPage() { InitializeComponent(); // Instantiate ViewModel and get saved values. mandelbrotViewModel = new MandelbrotViewModel(2.5, 2.5) { PixelWidth = 1000, PixelHeight = 1000, CurrentCenter = new Complex(GetProperty("CenterReal", -0.75), GetProperty("CenterImaginary", 0.0)), CurrentMagnification = GetProperty("Magnification", 1.0), TargetMagnification = GetProperty("Magnification", 1.0), Iterations = GetProperty("Iterations", 8), RealOffset = 0.5, ImaginaryOffset = 0.5 }; // Set BindingContext on page. BindingContext = mandelbrotViewModel; // Set PropertyChanged handler on ViewModel for "manual" processing. mandelbrotViewModel.PropertyChanged += OnMandelbrotViewModelPropertyChanged; // Create test image to obtain pixels per device-independent unit. BmpMaker bmpMaker = new BmpMaker(120, 120); testImage.SizeChanged += (sender, args) => { pixelsPerUnit = bmpMaker.Width / testImage.Width; SetPixelWidthAndHeight(); }; testImage.Source = bmpMaker.Generate(); // Gradually reduce opacity of cross-hairs. Device.StartTimer(TimeSpan.FromMilliseconds(100), () => { realCrossHair.Opacity -= 0.01; imagCrossHair.Opacity -= 0.01; return(true); }); }
public DiyGradientBitmapPage() { InitializeComponent(); int rows = 128; int cols = 64; BmpMaker bmpMaker = new BmpMaker(cols, rows); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { bmpMaker.SetPixel(row, col, 2 * row, 0, 2 * (128 - row)); } } ImageSource imageSource = bmpMaker.Generate(); image.Source = imageSource; }
async void OnCalculateButtonClicked(object sender, EventArgs e) { calculateButton.IsEnabled = false; cancelButton.IsEnabled = true; cancelTokenSource = new CancellationTokenSource(); try { BmpMaker bmpMaker = await CalculateMandelbrotAsync(progressReporter, cancelTokenSource.Token); image.Source = bmpMaker.Generate(); } catch (OperationCanceledException) { calculateButton.IsEnabled = true; progressBar.Progress = 0; } catch (Exception) { } cancelButton.IsEnabled = false; }