<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #mandelbrot - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23mandelbrot</link>
      <pubDate>Sun, 08 Aug 2021 19:54:57 +0000</pubDate>
         <description>Tagged with #mandelbrot - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23mandelbrot/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How do you redraw over this pixel array?</title>
      <link>https://forum.processing.org/two/discussion/28123/how-do-you-redraw-over-this-pixel-array</link>
      <pubDate>Sat, 22 Sep 2018 11:30:43 +0000</pubDate>
      <dc:creator>ProsExplorer</dc:creator>
      <guid isPermaLink="false">28123@/two/discussions</guid>
      <description><![CDATA[<p>Hello again,
I'm trying to redraw over this 2D pixel array of this program.</p>

<pre><code>// main setup settings
int dimy = 800;            // screen width 1681
int dimx = 850;            //screen height 1019
int bailout = 2000;         // number of iterations before bail
int plots = 171294;        // number of plots to execute per frame (x30 = plots per second) 171294
//zoom/magnification
float magx = 4.0; // default 3.0, smaller means more zoom
float magy = magx*(dimy/float(dimx));
//pan
float panx = 0.3; //default is 0.5
float pany = 0.0; //default is 0.0
//brightness multiplier
float brt = 1.0; // brightness factor

// 2D array to hold exposure values
int[] exposure = new int[dimx*dimy];

// maximum exposure value
int maxexposure;           

int time = 0;
int exposures = 0;

 float Ex = 2;

 float x, y;
 float x0, y0;

boolean drawing; 

int sgn(float value) {            //if signus is needed sgn(x)=x/abs(x) = 1, 0 or -1
 if (value &lt; 0) {return -1;}
 if (value &gt; 0) {return 1;}
 return 0;
}
float cosh(float value1) {
 return 0.5*(exp(value1)+exp(-value1));
}
float sinh(float value2) {
 return 0.5*(exp(value2)-exp(-value2));
}
float arg(float axis1, float axis2) {
 if (axis2==0) {return PI;}
 else {return -atan(axis1/axis2)+PI*sgn(axis2)*0.5;}
}
float spharg(float axisa, float axisb, float axisc) {
 return acos(axisc/sqrt(sq(axisa)+sq(axisb)+sq(axisc)));
}
void setup() {
 // set up drawing area
 size(800,850,P3D);
}
void draw() {
 plotPlots();
 time++;
 if (time%1==0) { //every second
   findMaxExposure();
   // Infinitely Looping, nested boolean iteration(x0,y0,DrawIt)
   renderBrot();
 }
}
void plotPlots() {

 // iterate through some plots
 for (int n=0;n&lt;plots;n++) {
   // Choose a random point in same range
   x = random(-2.0,2.0);
   y = random(-2.0,2.0);
   x0 = random(-2.0,2.0);
   y0 = random(-2.0,2.0);

   if (iterate(x,y,false)) {
    //Pauses Boolean, (d=pause, D=start)
     if (Ex &gt; 1){
       iterate(x,y,true);
       exposures++;
      }
      if (Ex &lt; 2){
       iterate(x,y,false);
      }
   }

 }
}
void renderBrot() {
 colorMode(RGB,1.0);
 // draw to screen
 for (int i=0;i&lt;dimx;i++) {
   for (int j=0;j&lt;dimy;j++) {
     float ramp = brt * exposure[i*dimy+j] / maxexposure;
     // blow out ultra bright regions
     if (ramp &gt; 1)  {
       ramp = 1;
     }
     //shading formulae
     color c = color(pow(sin(ramp),0.4),pow(ramp,0.75),pow(ramp,2.5)); // sunset
     set(j,i,c);
   }
 }
} 
//   Iterate the Mandelbrot and return TRUE if the point exits
//   Also handle the drawing of the exit points
boolean iterate(float x0, float y0, boolean drawIt) {
 float x = 0.0;
 float y = 0.0;
 //float t = random(0,1);
 //float r = random(0,1);  

 //x0 = 0.0;
 //y0 = 0.0;

 float xnew, ynew;
 int ix,iy;

 for (int i=0;i&lt;bailout;i++) {

   // Display iterations before false DrawIt boolean
   //if (i&gt;0){
   //println(i);
   // }

   //set your costum formula here...
   //example:
   //default Mandelbrot
   xnew = x * x - y * y + x0;
   ynew = 2 * x * y + y0;

// Draws pixel to screen -
// Based on if drawIt boolean is true, and iterations[i] &gt; 3

  // Defines and Draws Pixels in 2D Exposure Array
  // Draws pixel when iteration[i] &gt; 3 within current boolean cycle of xnew, ynew values
  if (drawIt &amp;&amp; (i &gt; 3)) {

     ix = int(dimx*(panx+xnew+magx/2.0)/magx);
     iy = int(dimy*(pany+ynew+magy/2.0)/magy);

     //Defines points (ix,iy) within screen ranges
     if (ix &gt;= 0 &amp;&amp; iy &gt;= 0 &amp;&amp; ix &lt; dimx &amp;&amp; iy &lt; dimy) {
       // rotate and expose point
       exposure[ix*dimy+iy]++;
   }
 }

   if ((xnew*xnew + ynew*ynew) &gt; 4) {
     // escapes
     return true;
   }
   x = xnew;
   y = ynew;
 }
 // does not escape
 return false;
}
void findMaxExposure() {
 // assume no exposure
 maxexposure=0;
 // find the largest density value
 for (int i=0;i&lt;dimy;i++) {
   for (int j=0;j&lt;dimx;j++) {
     maxexposure = max(maxexposure,exposure[i*dimx+j]);
   }
 }
} 
 void keyPressed(){

    //Return Iterate(x0,y0,DrawIt) False in Plot  
    if (key == 'r') {
     Ex = 1;
    }
    //Return Iterate(x0,y0,DrawIt) True in Plot  
    if (key == 'R') {
     Ex = 2;
    }
}
</code></pre>

<p>I've studied and tested many pixel array programs recently, but don't understand it enough to figure it out the exact method. I know the pixel array exposure[] is a 2D array within the looping, nested boolean iterate(x0,y0,drawIt) and that the pixel array output is derived from the specific code:</p>

<pre><code>    // Draws pixel to screen -
    // Based on if drawIt boolean is true, and iterations[i] &gt; 3

      // Defines and Draws Pixels in 2D Exposure Array
      // Draws pixel when iteration[i] &gt; 3 within current boolean cycle of xnew, ynew values
      if (drawIt &amp;&amp; (i &gt; 3)) {

         ix = int(dimx*(panx+xnew+magx/2.0)/magx);
         iy = int(dimy*(pany+ynew+magy/2.0)/magy);

         //Defines points (ix,iy) within screen ranges
         if (ix &gt;= 0 &amp;&amp; iy &gt;= 0 &amp;&amp; ix &lt; dimx &amp;&amp; iy &lt; dimy) {
           // rotate and expose point
           exposure[ix*dimy+iy]++;
       }
     }
</code></pre>

<p>It's not a boolean true/false issue as the entire program is written in an infinite loop of nested booleans drawing, iterate(x0,y0,drawIt) and when halted either in the drawing section or the plotPlots() section the pixel array remains intact upon continuation of the program (as demonstrated with Keypressed 'r', 'R'). The program is well threaded into itself with it's booleans and I have no reason to change that fact.</p>

<p>How would I go about updating the entire pixel array in this program to a single color (black) upon key press? Blanking out the canvas and the program continuing it's constant pixel drawing process of exposure points on screen again without the old pixels.</p>
]]></description>
   </item>
   <item>
      <title>Inconsistant download of image</title>
      <link>https://forum.processing.org/two/discussion/25783/inconsistant-download-of-image</link>
      <pubDate>Tue, 02 Jan 2018 09:05:42 +0000</pubDate>
      <dc:creator>OhNoFlowNo</dc:creator>
      <guid isPermaLink="false">25783@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm calculating the mandelbrot set and would like to download i high resolution image. This is done by calculating a large image (the global img variable), assigning it to the downloadImage variable for storage and issuing a download. All this is working as intended, however the download doesn't always work. Especially when I try to render a large image with 5000 pixels in width the download sometimes does not start. Chrome recognizes that a download has been issued and shows the green wave like animation on the menu bar but the download window never appears. Since the download sometimes works fine and sometimes not, I have not been able to locate the problem so far.</p>

<p>Any imput is appreciated as I am stuck.</p>

<p>EDIT: The download happens in the function downloadImage()</p>

<pre><code>var ratio;
var mapSize;
var centerX;
var centerY;
var renderSpeed = 20;
var currentLine = 0;
var img;
var downloadImage;
var calcTime;
var downloadButton;

function setup() {

  mapSize = 2;
  centerX = -1;
  centerY = 0;

  setupCanvas();

  downloadButton = createButton('Download');
  downloadButton.position(5, 85);
  downloadButton.mousePressed(downloadImage);

  noLoop();
}

function setupCanvas()
{
  resizeCanvas(window.innerWidth, window.innerHeight);
  ratio = window.innerWidth / window.innerHeight;
  pixelDensity(1); // Enables fine rendering for HDPI screens
  loadPixels(); // Enables pixels[]
  updateMandelbrotSet(window.innerWidth, window.innerHeight, true);
  updateText();
}

function windowResized() {
  setupCanvas();
}

function downloadImage()
{
  updateMandelbrotSet(window.innerWidth, window.innerHeight, true);
  updateMandelbrotSet(5000, 5000 / ratio, false);
  downloadImage = img;
  //downloadImage.save('Mandelbrot','png');  
  updateText();

  var mimeType = 'image/png';
  var downloadMime = 'image/octet-stream';
  var imageData = downloadImage.canvas.toDataURL(mimeType);
  var extension = 'png';
  var filename = 'Mandelbrot';
  imageData = imageData.replace(mimeType, downloadMime);

  //Make the browser download the file
  p5.prototype.downloadFile(imageData, filename, extension);

}

function updateText() {fill(255, 255, 255, 255);
  text('Calculation time: ' + calcTime + ' ms', 5, 15);
  text('CenterX: ' + centerX, 5, 35);
  text('CenterY: ' + centerY, 5, 55);
  text('Size: ' + mapSize, 5, 75);
}

function updateMandelbrotSet(xWidth, yWidth, update) {
  var start = millis();
  img = createImage(xWidth, yWidth);
  img.loadPixels();
  for (var x = 0; x &lt; xWidth; x++) {
    for (var y = 0; y &lt; yWidth; y++) {

      var reOrg = map(x, 0, xWidth, centerX - mapSize * ratio, centerX + mapSize * ratio)
      var imOrg = map(y, 0, yWidth, centerY - mapSize, centerY + mapSize)
      var re = reOrg;
      var im = imOrg

      var nMax = 99; // Iteration count (precision)
      var n = 0;
      var z = 0;

      while (n &lt; nMax) {
        var reNew = re * re - im * im;
        var imNew = 2 * re * im;
        re = reNew + reOrg;
        im = imNew + imOrg;

        if (re * re + im * im &gt; 4)
        {
          break;
        }

        n++;
      }

      var pix = (x + y * xWidth) * 4;
      if (n == nMax) {
        img.pixels[pix + 0] = 0;
        img.pixels[pix + 1] = 0;
        img.pixels[pix + 2] = 0;
        img.pixels[pix + 3] = 255;
      } else {
        img.pixels[pix + 0] = ((n - 33)/33) * 255;
        img.pixels[pix + 1] = ((n - 66)/33) * 255;
        img.pixels[pix + 2] = ((n - 0)/33) * 255;
        img.pixels[pix + 3] = 255;
      }
    }
  }
  img.updatePixels();

  if (update)
  {
    image(img, 0, 0);
  }

  var end = millis();
  calcTime = end - start;
  console.log("This took: " + calcTime + "ms.")
}

function mouseWheel(event) {
  if (event.delta &lt; 0) {
    if (mapSize &gt; 5e-16) {
      x = map(mouseX, 0, window.innerWidth, centerX - mapSize * ratio, centerX + mapSize * ratio)
      centerX = centerX + (x - centerX) * 0.3;
      y = map(mouseY, 0, window.innerHeight, centerY - mapSize, centerY + mapSize)
      centerY = centerY + (y - centerY) * 0.3;
      mapSize = mapSize * 0.7; 
    }
  } else {
    x = map(mouseX, 0, window.innerWidth, centerX - mapSize * ratio, centerX + mapSize * ratio)
    centerX = centerX - (x - centerX) * 0.3;
    y = map(mouseY, 0, window.innerHeight, centerY - mapSize, centerY + mapSize)
    centerY = centerY - (y - centerY) * 0.3;
    mapSize = mapSize / 0.7; 
  }

  updateMandelbrotSet(window.innerWidth, window.innerHeight, true);
  updateText();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>I'm having trouble making the Mandelbrot set</title>
      <link>https://forum.processing.org/two/discussion/25406/i-m-having-trouble-making-the-mandelbrot-set</link>
      <pubDate>Wed, 06 Dec 2017 01:23:29 +0000</pubDate>
      <dc:creator>kellen</dc:creator>
      <guid isPermaLink="false">25406@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm new to programming and I'm trying to make the Mandelbrot set. I am trying to make a nestled loop for the x and y values of the window (corresponding to a and b for the complex number input a + bi ). I want it to create a function for each one that performs the function z^2 + c and changes the color of the point it draws based on how long it took z to get to infinity (16).</p>

<pre><code>int maxIterations = 50;
float infinity = 16;

void setup(){
size(720,720);
background(0);

  for(int x = 0; x &lt; width; x++){
    for(int y = 0; y&lt;height; y++){

float a = (x-360)/180;
float b = (y-360)/180;   
float c = a + b*sqrt(-1);                 
cSet( c , 0 , 0 , x ,y);            
    }
  }
}

void cSet(float c, float z, int iterations, int x, int y){ 

if(iterations &lt; maxIterations &amp;&amp; z &lt; infinity){  
cSet( c , pow(z,2) + c , iterations + 1 , x , y);    
  }

if(z &gt; infinity){
stroke(iterations*5);
point(x,y); 
  }

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Zoom fractal mandelbrot</title>
      <link>https://forum.processing.org/two/discussion/24018/zoom-fractal-mandelbrot</link>
      <pubDate>Mon, 04 Sep 2017 09:23:05 +0000</pubDate>
      <dc:creator>tarikjabiri</dc:creator>
      <guid isPermaLink="false">24018@/two/discussions</guid>
      <description><![CDATA[<p>Hi every body,
I want to make a zoom in the fractal mandelbrot but i dont know how to make it.
I am using loadpixels and it cant let me do that.
I want an idea how to do that a simple guide or tuto in the internet.</p>

<p>Thank you in advance.</p>
]]></description>
   </item>
   <item>
      <title>2d, mandelbrot, sketch adapted to use doubles, now doesn't work</title>
      <link>https://forum.processing.org/two/discussion/22209/2d-mandelbrot-sketch-adapted-to-use-doubles-now-doesn-t-work</link>
      <pubDate>Tue, 25 Apr 2017 21:41:48 +0000</pubDate>
      <dc:creator>nnenov</dc:creator>
      <guid isPermaLink="false">22209@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I made this mandelbrot renderer with the help of a friend, you can see it works fine: 
click to move/zoom
<a href="https://www.dropbox.com/s/u6vql2ccmw1binb/mb2D_06.7z?dl=0" target="_blank" rel="nofollow">https://www.dropbox.com/s/u6vql2ccmw1binb/mb2D_06.7z?dl=0</a></p>

<p>I then noticed the loss off precision when zoomed in, so today I tried to convert whatever I had to, to double precision.
I made my own 2D vector class which processes double pres. values, but now everything is whacked.
I can draw the circle, but when I run mandelbrot function it just makes a white screen..
here is the attempted adapted code:
<a href="https://www.dropbox.com/s/8i37kmuefdbfwj0/mb2D_08.7z?dl=0" target="_blank" rel="nofollow">https://www.dropbox.com/s/8i37kmuefdbfwj0/mb2D_08.7z?dl=0</a></p>

<p>in its current state when you run it you will see a circle, my last attempt at debugging before I gave up.. for today. if anyone would mind having a look it would be really helpful. Thank you.</p>
]]></description>
   </item>
   <item>
      <title>Instance mode namespace</title>
      <link>https://forum.processing.org/two/discussion/16496/instance-mode-namespace</link>
      <pubDate>Sun, 08 May 2016 19:29:00 +0000</pubDate>
      <dc:creator>geo</dc:creator>
      <guid isPermaLink="false">16496@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,
i have a file called main.js that is written in instance mode and, in the same folder, a mandelbrot.js file that contains a function object in wich i use the color() function. The problem is that i cant access the p5 namespace from the mandelbrot.js file so i get an error.</p>

<p><a href="http://pastebin.com/PMjJw31t" target="_blank" rel="nofollow">http://pastebin.com/PMjJw31t</a></p>
]]></description>
   </item>
   </channel>
</rss>