public Bitmap CalcMandelbrotBmp(int width, int height, double offsetX, double offsetY, double zoomFactor, int iterations, int colorshift, int colorrange) { var result = Mandelbrot.CalcGPU(width, height, offsetX, offsetY, zoomFactor, iterations); var mandelbrot = Helpers.BitmapConverter(result, width, height, colorshift, colorrange, iterations); return(mandelbrot); }
static void Main() { Mandelbrot scherm; scherm = new Mandelbrot(); double result = Mandelgetal(0.4, 0.4); Application.Run(scherm); }
public static void Main() { // Draw a mandelbrot set using a Canvas var mandelbrot = Mandelbrot.Generate(32, 32); Render(mandelbrot, "Mandelbrot"); // Draw an image using CanvasImage powered by ImageSharp. // This requires the "Spectre.Console.ImageSharp" NuGet package. var image = new CanvasImage("cake.png"); image.BilinearResampler(); image.MaxWidth(16); Render(image, "Image from file (16 wide)"); // Draw image again, but without render width image.NoMaxWidth(); image.Mutate(ctx => ctx.Grayscale().Rotate(-45).EntropyCrop()); Render(image, "Image from file (fit, greyscale, rotated)"); // Draw image again, but load from embedded resource rather than file using (var fileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Canvas.cake.png")) { Debug.Assert(fileStream != null); var embeddedImage = new CanvasImage(fileStream); embeddedImage.BilinearResampler(); embeddedImage.MaxWidth(16); Render(embeddedImage, "Image from embedded resource (16 wide)"); } }
public WriteableBitmap Render(int width, int height) { ImageRendererBase m = new Mandelbrot(); return(m.Render(new Complex(left, top), new Complex(right, bottom), width, height)); }
public MatrixValue Function(ScalarValue start, ScalarValue end, ScalarValue steps) { var s = steps.GetIntegerOrThrowException("steps", Name); var m = new Mandelbrot(); return(m.CalculateMatrix(start.Re, end.Re, start.Im, end.Im, s, s)); }
private async void GoMandelbrot(double x, double y, double width, int RESOLUTION, int ITERATIONS, ColorGradient colorGradient) { if (mandelbrot == null) { mandelbrot = new Mandelbrot(x, y, width, RESOLUTION, ITERATIONS); mandelbrot.ColorGradient = colorGradient; } else { mandelbrot.XCenter = x; mandelbrot.YCenter = y; mandelbrot.ImageWidth = width; mandelbrot.Resolution = RESOLUTION; mandelbrot.MaxIter = ITERATIONS; mandelbrot.ColorGradient = colorGradient; } //Bitmap bitmap = new Bitmap(RESOLUTION, RESOLUTION); mandelbrot.CalculateOpenCL(); try { Stopwatch stop = new Stopwatch(); stop.Start(); Bitmap canvas = mandelbrot.MakeBitmapOpenCL(Slider_Shift.Value, Convert.ToInt32(TextBox_IterCycle.Text)); stop.Stop(); //MessageBox.Show(stop.ElapsedMilliseconds.ToString()); fractalBitmap = canvas; FractalImage.Source = BitmapToImage(canvas); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public List <MemoryStream> DrawMandelbrot(int width, int height, List <List <double> > Scales, int numberOfIterations) { var watch = System.Diagnostics.Stopwatch.StartNew(); Console.WriteLine("I am drawing"); mandelbrot = new Mandelbrot(width, height); List <MemoryStream> images = new List <MemoryStream>(); Bitmap bitmap; double[] scale; MemoryStream stream = new MemoryStream(); for (int count = 0; count < Scales.Count; count++) { bitmap = new Bitmap(width, height); scale = Scales[count].ToArray(); Console.WriteLine("{0}, {1}", scale[0], scale[1]); Parallel.For(0, width, i => { Parallel.For(0, height, j => { //for (int i = 0; i < width; i++) //{ // for (int j = 0; j < height; j++) // { int result = mandelbrot.Calculate_mandelbrot(i, j, scale, numberOfIterations); lock (bitmap) { if (result > 0 && result < 333) { bitmap.SetPixel(i, j, Color.FromArgb(result & 255, 0, 0)); } else if (result >= 333 && result < 666) { bitmap.SetPixel(i, j, Color.FromArgb(0, result & 255, 0)); } else if (result >= 666 && result < 999) { bitmap.SetPixel(i, j, Color.FromArgb(0, 0, result & 255)); } else { bitmap.SetPixel(i, j, Color.FromArgb(0, 0, 0)); } } }); }); // } //} stream = new MemoryStream(); bitmap.Save(stream, ImageFormat.Jpeg); images.Add(stream); } watch.Stop(); timesOfExecution.Add(watch.Elapsed); return(images); }
public static void Main() { var settings = new Options(); var calculator = new Mandelbrot(settings); var drawer = new Drawer(settings, calculator); }
public void PrintMandelbrot(int width, int height, double offsetX, double offsetY, double zoomFactor, int iterations, int colorshift, int colorrange) { var result = Mandelbrot.CalcGPU(width, height, offsetX, offsetY, zoomFactor, iterations); var mandelbrot = Helpers.BitmapConverter(result, width, height, colorshift, colorrange, iterations); mandelbrot.RotateFlip(RotateFlipType.Rotate90FlipNone); printManager.PrintImage(mandelbrot); }
public MatrixValue Function(ScalarValue x0, ScalarValue xn, ScalarValue y0, ScalarValue yn, ScalarValue xsteps, ScalarValue ysteps) { var xs = xsteps.GetIntegerOrThrowException("xsteps", Name); var ys = ysteps.GetIntegerOrThrowException("ysteps", Name); var m = new Mandelbrot(); return(m.CalculateMatrix(x0.Re, xn.Re, y0.Re, yn.Re, xs, ys)); }
public MatrixValue Function(ScalarValue x0, ScalarValue xn, ScalarValue y0, ScalarValue yn) { var m = new Mandelbrot(); var xsteps = (Int32)Math.Abs(Math.Ceiling((xn.Re - x0.Re) / 0.1)); var ysteps = (Int32)Math.Abs(Math.Ceiling((yn.Re - y0.Re) / 0.1)); return(m.CalculateMatrix(x0.Re, xn.Re, y0.Re, yn.Re, xsteps, ysteps)); }
public static void TestTwo() { Console.WriteLine("【Mandelbrot,数学公式,以及m[1,3]这种格式】"); Mandelbrot m = new Mandelbrot(3); Console.WriteLine(m[1, 3].ToString()); Console.WriteLine(m[0.001, 0.02].ToString()); Console.WriteLine(m[3, 3].ToString()); }
// EVIP: simple, good old event handler. No command pattern. private void Button_Click(object sender, RoutedEventArgs e) { // EVIP: ImageRendererBase allows alternate // implementations for testing purposes ImageRendererBase renderer = new Mandelbrot(); //ImageRendererBase renderer = new TestGridImageRenderer(); Image.Source = renderer.RenderDefault(); }
public static void TestBlackAndWhite() { Bitmap bitmap = Mandelbrot.GetBitmap(useDistanceColorCoding: false); // Pixel outside the Mandelbrot set should be white. Assert.AreEqual(bitmap.GetPixel(0, 0), Color.FromArgb(255, 255, 255, 255)); // Pixel inside the Mandelbrot set should be black. Assert.AreEqual(bitmap.GetPixel(400, 300), Color.FromArgb(255, 0, 0, 0)); }
public void TestGetSteps(double start, double end, int steps, double[] expected) { var actual = new List <double>(Mandelbrot.GetSteps(start, steps, (end - start) / steps)).ToArray(); Assert.Equal(expected.Length, actual.Length); for (int i = 0; i < expected.Length; i++) { Assert.Equal(expected[i], actual[i], 5); } }
public static void TestColorCoded() { Bitmap bitmap = Mandelbrot.GetBitmap(useDistanceColorCoding: true); // Pixel distant to the Mandelbrot set should be red. Assert.AreEqual(bitmap.GetPixel(0, 0), Color.FromArgb(255, 255, 0, 0)); // Pixel inside the Mandelbrot set should be black. Assert.AreEqual(bitmap.GetPixel(400, 300), Color.FromArgb(255, 0, 0, 0)); }
private static void SampleThree() { var generator = new Mandelbrot(256); var item = generator[0, 0]; Console.WriteLine(item); item = generator[5, 5]; Console.WriteLine(item); item = generator[0.30, 0.0001]; Console.WriteLine(item); }
private void DrawMandelbrot(Graphics g) { Mandelbrot mFrac = new Mandelbrot(Domain); if (SimpleMFracRB.Checked) { mFrac.Draw(img); } else { nwM.Update(g); } }
public async Task <object> Post(FractalCreateModel fractalCreate) { var mandelbrot = new Mandelbrot(); return(await Task.FromResult( mandelbrot.CalculateArea( fractalCreate.Iterations, fractalCreate.BottomLeftX, fractalCreate.BottomLeftY, fractalCreate.TopRightX, fractalCreate.TopRightY, fractalCreate.Steps, fractalCreate.Steps) )); }
public void BasicTest() { // Arrange var m = new Mandelbrot(); // Act var area = m.CalculateArea(50, 0.0, 0.0, 1.0, 1.0, 50, 50); // Assert Assert.Equal(50, area.Count); foreach (var row in area) { Assert.Equal(50, row.Count); } }
private void button_go_Click(object sender, EventArgs e) { if (timer1.Enabled) { timer1.Enabled = !timer1.Enabled; showAnimationButton.Text = "Start"; showAnimationButton.Enabled = false; } mandelbrot = new Mandelbrot(pictureBox.Width, pictureBox.Height); connectionManager = new ConnectionManager(); server_info_textBox.Text = "Connected: " + connectionManager.getNumberOfServers(); //var watch = System.Diagnostics.Stopwatch.StartNew(); pictureBox.Image = mandelbrot.DrawMandelbrot(0, Convert.ToInt32(numericUpDownIterations.Value)); //watch.Stop(); //Console.WriteLine(watch.Elapsed); }
public void TestCalculateArea() { // Arrange var iterations = 1000; var bottomLeftX = 0.0; var bottomLeftY = 0.0; var topRightX = 1.0; var topRightY = 1.0; var stepX = 10; var stepY = 10; //Act var result = Mandelbrot.CalculateArea(iterations, bottomLeftX, bottomLeftY, topRightX, topRightY, stepX, stepY); // Assert Assert.Equal(10, result.Count); Assert.Equal(10, result[0].Count); }
private void Draw() { performanceLogger.Start(Settings.selectedFractalType, Settings.selectedDrawingMode); Fractal fractal = null; switch (Settings.selectedFractalType) { case FractalType.Mandelbrot: fractal = new Mandelbrot(colorBuffer, Settings.renderWidth, Settings.renderHeight, Settings.maxIterations); break; case FractalType.Julia: fractal = new Julia(colorBuffer, Settings.renderWidth, Settings.renderHeight, Settings.maxIterations); break; default: throw new Exception("Nieprawidłowy typ fraktala: " + Settings.selectedFractalType); } switch (Settings.selectedDrawingMode) { case DrawingMode.CpuSingle: fractal.DrawOnSingleThread(offsetX, offsetY, zoom); break; case DrawingMode.CpuMulti: fractal.DrawOnMultipleThreads(offsetX, offsetY, zoom); break; case DrawingMode.Gpu: fractal.DrawOnGpu(offsetX, offsetY, zoom); break; default: throw new Exception("Nieprawidłowy typ rysowania: " + Settings.selectedDrawingMode); } performanceLogger.Stop(CountTotalIterations()); UpdateBitmap(); UpdateTransformationText(); }
void OnGUI() { GUILayout.BeginHorizontal(); if (GUILayout.Button("render")) { Color[] cols = new Color[xSize * ySize]; Mandelbrot.maxIter = 150; for (int y = 0; y < ySize; y++) { int off = y * xSize; for (int x = 0; x < xSize; x++) { float v = (float)Mandelbrot.Calc(-3d + (double)x * 4 / (xSize), -1.5d + (double)y * 3 / (ySize)) / 10; var i1 = Mathf.Clamp(Mathf.FloorToInt(v), 0, colors.Length - 1); var i2 = Mathf.Clamp(Mathf.CeilToInt(v), 0, colors.Length - 1); cols[off + x] = Color.Lerp(colors[i1], colors[i2], v - i1); } } tex.SetPixels(cols); tex.Apply(); Mandelbrot.maxIter = 30000; } GUILayout.Label("point: (" + pos.x.ToString("0.00000") + " + " + pos.y.ToString("0.00000") + "*i) interations: " + iterations); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); /* * Mandelbrot.startR = GUILayout.HorizontalSlider((float)Mandelbrot.startR,-1,1); * Mandelbrot.startI = GUILayout.HorizontalSlider((float)Mandelbrot.startI,-1,1); */ GUILayout.EndHorizontal(); Rect r = new Rect(10, 50, xSize, ySize); GUI.DrawTexture(r, tex); GUI.BeginGroup(r); Event e = Event.current; if (e.type == EventType.MouseDrag || e.type == EventType.MouseDown) { pos = e.mousePosition; pos.x = pos.x * 4 / xSize - 3; pos.y = pos.y * 3 / ySize - 1.5f; iterations = Mandelbrot.Calc(pos.x, pos.y); } GUI.EndGroup(); if (Event.current.type == EventType.Repaint) { r.y = Screen.height - r.yMax; GL.Viewport(r); GL.LoadPixelMatrix(-3, 1, 1.5f, -1.5f); Vector2 old = pos; GL.Begin(GL.LINES); m.SetPass(0); GL.Color(Color.blue); GL.Vertex3(-3, 0, 0); GL.Vertex3(1, 0, 0); GL.Vertex3(0, -1, 0); GL.Vertex3(0, 1, 0); GL.Color(Color.red); foreach (var p in Mandelbrot.CalcPoints(pos.x, pos.y)) { GL.Vertex(old); GL.Vertex(p); old = p; } GL.End(); } }
static void Main(string[] args) { Console.WriteLine(string.Join(" ", args)); Console.WriteLine("Environment Version: {0}", Environment.Version.ToString()); Fractal fractal = new Fractal(); foreach (string a in args) { switch (a) { case "animate": int upper = 900; for (int i = 0; i < upper; i++) { double zoom = Helper.Map(i, 0, upper, 1, 5); //centered on (-0.54,0.0) //fractal = new Glynn(W, H, i,0,0).Init(-0.79 + zoom, -0.29 - zoom, -0.25 + zoom, 0.25 - zoom);//focuses on the top tree //fractal = new Glynn(W, H, HIGHEST, zoom, 1).Init(-0.8, 1.4, -1.2, 1.2);//focuses on all the trees double x0 = Helper.Map(i, 0, upper, -2, 1.225); double x1 = Helper.Map(i, 0, upper, 2, 1.325); double y0 = Helper.Map(i, 0, upper, -2, -0.05); double y1 = Helper.Map(i, 0, upper, 2, 0.05); fractal = new Glynn(W, H, HIGHEST, zoom, 1).Init(x0, x1, y0, y1); fractal.Render().DistanceMapped(); //DistanceHSV(); fractal.SaveImage(i.ToString("D5")); } break; case "buddhabrot": fractal = new Buddhabrot(W, H, 0, 1000, HIGHEST) //.Init(-2, 2, -2, 2); .Init(-1.9, 1.9, -2.1, 1.7); break; case "glynn": fractal = new Glynn(W, H, HIGHEST, 0, 0) //.Init(0.066, 0.42, -0.6677, -0.323); .Init(1, -1, -1, 1); //.InitPoint(-0.539, 0, 0.2, 0.2);//r, i, width, height break; case "julia": fractal = new Julia(W, H, HIGHEST) //.Init(-0.39, -0.7, 0.19, -0.12); .Init(-0.8, 0.8, -0.8, 0.8); break; case "load": fractal.LoadSettings("settings.json").LoadDistance("distance.dat").LoadExposure("exposure.dat"); break; case "logisticmap": fractal = new LogisticMap(W, H, HIGHEST) .Init(0, 0, 0, 0); break; case "mandelbrot": fractal = new Mandelbrot(W, H, 3000, HIGHEST).Init(-1, 1, -1, 1); break; case "render": fractal.Render(); break; case "shade": fractal. //DistanceBinned(); //DistanceHSV(); //DistanceMapped(); //Exponential(2); //ExposureBinned(); //ExposureHSV(); //HexColor(); LogBaseHighest(); //Mapped(); //SmoothStep(); break; case "save": fractal.SaveSettings("settings.json").SaveDistance("distance.dat").SaveExposure("exposure.dat"); break; case "draw": fractal.Draw(); break; case "/?": Console.WriteLine(String.Format("{0,5}", "Options:")); Console.WriteLine(String.Format("{0,-10} {1,-40}", "/?", "Display this help message")); Console.WriteLine(String.Format("{0,-10} {1,-40}", "buddhabrot", "Renders a fractal based on the Buddhabrot set")); Console.WriteLine(String.Format("{0,-10} {1,-40}", "glynn", "Renders a fractal based on the Glynn Set")); Console.WriteLine(String.Format("{0,-10} {1,-40}", "julia", "Renders a fractal based on the Julia Set")); Console.WriteLine(String.Format("{0,-10} {1,-40}", "mandelbrot", "Renders a fractal based on the Mandelbrot Set")); break; } } }
public TrajectoryMandelbrotView(Mandelbrot engine, Trajectory trajectory, int screenWidth, int screenHeight) { this.engine = engine; this.trajectory = trajectory; this.screenHeight = screenHeight; this.screenWidth = screenWidth; updateState(); }
public static void MaxStepIsZeroOrNegative_ThrowsArgumentOutOfRangeException() { Assert.Throws <ArgumentOutOfRangeException>(() => Mandelbrot.GetBitmap(maxStep: -1)); }
public static void Main(string[] args) { Mandelbrot test = new Mandelbrot(-2.1, 0.5, -1.1, 1.1, 80, 44); test.GenerateField(); }
public static void BitmapHeightIsZeroOrNegative_ThrowsArgumentOutOfRangeException() { Assert.Throws <ArgumentOutOfRangeException>(() => Mandelbrot.GetBitmap(bitmapHeight: 0)); }
public Form1() { InitializeComponent(); #region Fractal classes constructors HarterDragon = new Harter_Dragon(); MinkovskySquare = new Minkovsky_Square(); SquareCutted = new Square_Hole(); KochCurve = new Koch_Curve(); SerpinskyCarpet = new Serpinsky_Carpet(); Fern = new ISF_Fern(); Cobweb = new ISF_Cobweb(); Dragon = new ISF_Dragon(); Star = new ISF_Star(); Spiral = new ISF_Spiral(); WindFern = new ISF_WindFern(); JuliaSet = new Julia(); ManSet = new Mandelbrot(); #endregion #region Image Processing init Gray = new Grayscale(); BlurPicture = new Blur(); Border = new Borders(); openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Images (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif|All files(*.*)|*.*"; loadf = false; #endregion #region Fractal variables init loaded = false; depth_counter = 0; iterations = 1000; jmiterations = 100; rec = 0.11; imc = -0.66; minx = -1.5; maxx = 1.5; miny = -1.5; maxy = 1.5; s_fractal = false; i_fractal = false; j_fractal = false; m_fractal = false; w_fractal = false; w2_fractal = false; details = 800; scale = 1; #endregion #region Vector Fields init Surface = new Grid(); openFileDialog2 = new OpenFileDialog(); openFileDialog2.Filter = "(*.txt; *.res)|*.txt;*.res|All files(*.*)|*.*"; drawv = false; y_offset = 0; z_offset = 0; x_rotated = 0; y_rotated = 0; constant = 1; timevalue = 0; LightONF = true; InvNorm = false; #endregion Fractal_GL_window.InitializeContexts(); VectorFields.InitializeContexts(); }
public MainWindowController() { Mandelbrot.CompileKernel(); }
public Drawer(Options settings, Mandelbrot calculator) { this.Settings = settings; this.Calculator = calculator; // the actual canvas element var canvas = new HTMLCanvasElement(); canvas.Width = 900; canvas.Height = 500; DrawButton = new HTMLButtonElement { InnerHTML = "Draw the Mandelbrot fractal", OnClick = (ev) => { StartDraw(canvas); } }; DrawButton.SetAttribute("style", "font-size:18px;height: 60px; width:95%; border: 2px solid black; cursor: pointer"); // Iteration controls RadiusElement = GetInputNumberElement(null, this.Settings.MaxRadius, 3, 0.5); IterationCountElement = GetInputNumberElement(null, this.Settings.MaxIterations, 4, 100, 0, 100000); // Color controls ColorMapCheckbox = GetCheckboxElement(this.Settings.UseColorMap); ColorScaleElement = GetInputNumberElement(ColorMapCheckbox, this.Settings.ColorScale, 5, 1000); ColorOffsetElement = GetInputNumberElement(ColorMapCheckbox, this.Settings.ColorOffset, 4, 10); // Julia sets JuliaSetCheckbox = GetCheckboxElement(this.Settings.UseJuliaSet); JuliaImElement = GetInputNumberElement(JuliaSetCheckbox, this.Settings.JuliaSetParameter.Im, 5, 0.005, null); JuliaReElement = GetInputNumberElement(JuliaSetCheckbox, this.Settings.JuliaSetParameter.Re, 5, 0.005, null); // Viewport controls XMinElement = GetInputNumberElement(null, this.Settings.XMin, 5, 0.005, -5.0); XMaxElement = GetInputNumberElement(null, this.Settings.XMax, 5, 0.005, 0.0); YMinElement = GetInputNumberElement(null, this.Settings.YMin, 5, 0.005, -5.0); YMaxElement = GetInputNumberElement(null, this.Settings.YMax, 5, 0.005, 0.0); var paramsColumn = new HTMLTableDataCellElement(); var canvasColumn = new HTMLTableDataCellElement(); paramsColumn.SetAttribute("valign", "top"); canvasColumn.SetAttribute("valign", "top"); canvasColumn.AppendChild(canvas); var layoutRow = new HTMLTableRowElement(); layoutRow.AppendChildren(paramsColumn, canvasColumn); var layout = new HTMLTableElement(); var paramsTable = new HTMLTableElement(); paramsTable.AppendChildren( Row(Label("XMin: "), XMinElement), Row(Label("XMax: "), XMaxElement), Row(Label("YMin: "), YMinElement), Row(Label("YMax: "), YMaxElement), Row(Label("Escape radius: "), RadiusElement), Row(Label("Iteration count: "), IterationCountElement), Row(Label("Use color map: "), ColorMapCheckbox), Row(Label("Color scale: "), ColorScaleElement), Row(Label("Color offset: "), ColorOffsetElement), Row(Label("Use Julia set: "), JuliaSetCheckbox), Row(Label("Im: "), JuliaImElement), Row(Label("Re: "), JuliaReElement), Row(new HTMLHRElement(), 2), Row(DrawButton, 2) ); paramsColumn.AppendChild(paramsTable); layout.AppendChild(layoutRow); Document.Body.AppendChild(layout); }
public void TestCalculatePoint(int iterations, double x, double y, int expected) { var actual = Mandelbrot.CalculatePoint(iterations, x, y); Assert.Equal(expected, actual); }