<?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 #fractal - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23fractal</link>
      <pubDate>Sun, 08 Aug 2021 19:58:18 +0000</pubDate>
         <description>Tagged with #fractal - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23fractal/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How to progressively draw a fractal tree</title>
      <link>https://forum.processing.org/two/discussion/28105/how-to-progressively-draw-a-fractal-tree</link>
      <pubDate>Mon, 27 Aug 2018 09:35:39 +0000</pubDate>
      <dc:creator>Emanuele</dc:creator>
      <guid isPermaLink="false">28105@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, I need to do a school project and I want to build a fractal tree that progressively "grows" using the mouse. how can I do it? this is the code I built:</p>

<pre><code>void setup() 
{

        fullScreen();

 }

int levelsMin = 0;
    int levelsMax = 6;
    float initialLength = 235;

    float angleMin = PI/17;
    float angleMax = PI/10;

    int pointColor = color(27, 25, 9);

   void draw() {


        background(color(245,247,232));
        stroke(88, 50, 0);
        strokeWeight(7);

        float currentAngle = map (mouseX, 0, width, angleMin, angleMax); //mouse control of the branch angle
        int currentLevels = (int)map (mouseY, height,0, levelsMin, levelsMax); //mouse control of the generations count

        pushMatrix(); //save the world transformation matrix
        translate (width/2, height); //move the origin to the middle / bottom
       albero (currentLevels, initialLength, currentAngle); //draw first two branches - stems
        popMatrix(); //return to the world coordinate system
    }

    void albero (int levels, float length, float angle){
        if (levels&gt;0){  //check if there are any levels left to render
            //destra
            pushMatrix();           //save current transformation matrix
            rotate (angle);         //rotate new matrix to make it point to the right
            line (0,0,0,-length);   //draw line "upwards"
            pushMatrix();           //save current (e.g. new) matrix
            translate(0,-length);   //move the origin to the branch end
            scale (0.85f);          //scale down. fun fact - it scales down also the stroke weight!
           albero (levels-1, length, angle);  //call the recursive function again
            popMatrix();            //return to the matrix of the current line
            popMatrix();            //return to the original matrix
            //second branch - the same story
            pushMatrix();
            rotate (-angle/1.7);
            line (0,0,0,-length);
            pushMatrix();
            translate(0,-length);
            scale (0.85f);
            albero (levels-1, length, angle);
            popMatrix();
            popMatrix();


        }

    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Interactive fractal tree</title>
      <link>https://forum.processing.org/two/discussion/26813/interactive-fractal-tree</link>
      <pubDate>Tue, 13 Mar 2018 20:50:55 +0000</pubDate>
      <dc:creator>BjarkePedersen</dc:creator>
      <guid isPermaLink="false">26813@/two/discussions</guid>
      <description><![CDATA[<p>Yes, it's just a regular old fractal tree. But it's pretty :)</p>

<p>Try dragging it with your mouse</p>

<pre><code>int iterations = 14;
int treeSize = floor(pow(2, iterations)-1);
Branch[] tree = new Branch[treeSize];

float t, t2, colorT;

float angle = 45;
float startangle;
float startererangle = angle;

float wind = 1;
float startwind = wind;
float tempWind;

float r, g, b;
boolean mouseBegin = true;
PVector startMouse;
float tempAngle;

float friction = 0.98; // 0.95 for original
float tension = 0.03;  // 0.1 for original

PGraphics pg;

int noiseSeed1, noiseSeed2, noiseSeed3;

int cursorCount = 0;

void setup () {
  fill(0);
  //size(800, 800, P2D);
  fullScreen(OPENGL);
  pixelDensity(displayDensity());
  smooth(8);
  pg = createGraphics(width, height);

  for (int i=1; i&lt;treeSize; i++) {
    tree[i] = new Branch(new PVector(0,0),new PVector(0,0));
  }
  seed();
  plant();

  noiseSeed1 = day() + hour() + minute() + second();
  noiseSeed2 = int(noiseSeed1 * 1.41421356237);
  noiseSeed3 = int(noiseSeed2 * 3.14159265358);

}

void seed() {
  PVector dir = new PVector(0, -300);
  dir.rotate(rad(wind));

  PVector a = new PVector(width/2, height-100) ;
  PVector b = new PVector(width/2+dir.x, height+dir.y-100);
  tree[0] = new Branch(a, b);
}


void plant() {
  seed();

  for (int i=1; i&lt;treeSize; i++) {
    int n = floor((i-1)/2);
    if (i % 2 == 0) {
      tree[n].branch(-1, tree[i]);
    } else {
      tree[n].branch(1, tree[i]);
    }
  }
}

void physics() {
  wind = startwind*(cos(t))*-1;
  startwind *= friction;
  noiseSeed(1337);
  startwind += map(noise(t/51-100), 0, 1, -0.2, 0.2);
  t -= tension;

  angle = startererangle + startangle*(cos(t2));
  startangle *= friction;
  noiseSeed(42);
  startangle += map(noise(t2/50), 0, 1, -0.2, 0.2);
  t2 -= tension;
}

PVector prevMouse, mouse;

void mouse(){
  // Hide / show cursor
  prevMouse = mouse!=null ? mouse : new PVector(mouseX, mouseY);
  mouse = new PVector(mouseX, mouseY);
  cursorCount ++;
  if (mouse.x != prevMouse.x || mousePressed) {cursorCount = 0; cursor();};
  if (cursorCount &gt; 20) noCursor();

  if (!mousePressed) {
      physics();
      mouseBegin = true;
    } else {
      if (mouseBegin == true) {
        startMouse = new PVector(mouseX, mouseY);
        tempWind = wind;
        tempAngle = angle;
        mouseBegin = false;
      }
      wind = tempWind + map(mouseX-startMouse.x, -width, width, deg(-1), deg(1));
      startwind = abs(wind);
      t = abs((wind/abs(wind)+1)*PI/2);

      angle = abs(tempAngle + map(mouseY-startMouse.y, -height, height, deg(-1), deg(1)))+0.01;
      startangle = startererangle-angle;
      t2 = abs(((angle/abs(angle)+1))*PI/2);
    }
}

void draw() {
  //println(frameRate);
  mouse();
  plant();

  noiseSeed(noiseSeed1);
  float r = map(noise(colorT/50), 0, 1, 0, 255);
  noiseSeed(noiseSeed2);
  float g = map(noise(colorT/75), 0, 1, 0, 255);
  noiseSeed(noiseSeed3);
  float b = map(noise(colorT/100), 0, 1, 0, 255);
  colorT--;


  // Start drawing image
  background(25);

  stroke(r, g, b);
  fill(r, g, b);
  rect(width/2-20, height-100, 40, 20, 3, 3, 40, 40);

  int level = 1;

  for (int i=0; i&lt;treeSize; i++) {
    if ((i % (pow(2, level)-1)) == 0) {
      //if (level &gt; 6) strokeWeight(1);
      strokeWeight((iterations-level)/2);

      noiseSeed(noiseSeed1);
      r = map(noise(colorT/50+level*0.2), 0, 1, 0, 255);
      noiseSeed(noiseSeed2);
      g = map(noise(colorT/75+level*0.2), 0, 1, 0, 255);
      noiseSeed(noiseSeed3);
      b = map(noise(colorT/100+level*0.2), 0, 1, 0, 255);

      stroke(r, g, b);

      level++;
    }
    tree[i].show();
  }
}

public class Branch {
  PVector begin;
  PVector end;
  float rand;
  boolean finished = false;
  float rotation = 0;

  public Branch(PVector begin, PVector end) {
    this.begin = begin;
    this.end = end;
  }

  public void show() {
    line(this.begin.x, this.begin.y, this.end.x, this.end.y);
  }

  public void branch(int direction, Branch targetBranch) {
    PVector dir = new PVector(this.end.x-this.begin.x, this.end.y-this.begin.y);
    dir.rotate(rad(direction*angle+wind));
    dir.mult(0.6667);
    PVector newEnd = new PVector(this.end.x+dir.x, this.end.y+dir.y);
    targetBranch.begin = this.end;
    targetBranch.end = newEnd;
  }
}

static float rad(float deg) {
  return deg*PI/180;
}

static float deg(float rad) {
  return rad*180/PI;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Using React with p5.js (ES6+ support)</title>
      <link>https://forum.processing.org/two/discussion/26322/using-react-with-p5-js-es6-support</link>
      <pubDate>Mon, 12 Feb 2018 20:54:24 +0000</pubDate>
      <dc:creator>atoro</dc:creator>
      <guid isPermaLink="false">26322@/two/discussions</guid>
      <description><![CDATA[<p><img src="https://forum.processing.org/two/uploads/imageupload/868/CURLOSY55G8G.png" alt="screeshot" title="screeshot" /></p>

<p>Check the <strong>online</strong> version <a rel="nofollow" href="http://fractal-tree-simulator.surge.sh/">here: http://fractal-tree-simulator.surge.sh/</a><br />
<strong>Source code</strong> is available <a rel="nofollow" href="https://github.com/atorov/fractal-tree-simulator">here: https://github.com/atorov/fractal-tree-simulator</a></p>

<h2>Using React with p5.js</h2>

<p>This project demonstrates the possibility of combining React, Bootstrap, p5.js and other modern technologies.<br />
<strong>React</strong> is one of the most popular JavaScript libraries for creating single page applications.<br />
<strong>Bootstrap</strong> is an open source toolkit for developing with HTML, CSS, and JS.</p>

<p>The basic idea is that the p5.js sketch is wrapped in a React component. The data that comes into the sketch is passed on to this component as props. Callbacks are used to return information back from the sketch to the application.</p>

<h3>ES6+ Support</h3>

<p>This project supports a superset of the latest JavaScript standard. In addition to <strong>ES6 syntax</strong> features, it also supports:<br />
  - Exponentiation Operator (ES2016).<br />
  - Async/await (ES2017).<br />
  - Object Rest/Spread Properties (stage 3 proposal).<br />
  - Dynamic import() (stage 3 proposal)<br />
  - Class Fields and Static Properties (part of stage 3 proposal).<br />
  -- JSX and Flow syntax.<br />
  - Syntax Highlighting and Displaying Lint Output in the Editor<br />
  - Тhe most popular editors should be covered and your editor should report the linting warnings.<br />
  - Code Splitting - allows you to split your code into small chunks which you can then load on demand. Supports code splitting via dynamic import().<br /></p>

<h3>Adding a Router and Redux</h3>

<p>React Router is the most popular option. Redux is a predictable state container for JavaScript apps. React Router and Redux can easily be added to the project.</p>

<h3>Running Tests</h3>

<p>Jest is a Node-based runner. While Jest provides browser globals such as window thanks to jsdom, they are only approximations of the real browser behavior. Jest is intended to be used for unit tests of your logic and your components rather than the DOM quirks.</p>

<h3>p5.js sketch</h3>

<ul>
<li>p5.Graphics for creating a graphics buffer;<br /></li>
<li>p5.Vector for describing a two dimensional vectors;<br /></li>
<li>p5.noise() - Perlin noise random sequence generator that produces a more natural ordered, harmonic succession of numbers compared to the standard random() function;<br /></li>
<li>p5.colorMode() - both RGB and HSB color spaces;<br /></li>
<li>p5.translate() and p5.rotate() matrix transformations, etc.<br /></li>
</ul>
]]></description>
   </item>
   <item>
      <title>¿Why is my screen slowing down, is there any way to avoid this?</title>
      <link>https://forum.processing.org/two/discussion/25340/why-is-my-screen-slowing-down-is-there-any-way-to-avoid-this</link>
      <pubDate>Sat, 02 Dec 2017 19:35:24 +0000</pubDate>
      <dc:creator>Sefiro10</dc:creator>
      <guid isPermaLink="false">25340@/two/discussions</guid>
      <description><![CDATA[<p>Here´s my code. It´s a simple-animated-3D fractal.
The screen, slow down while it´s running. how can I avoid that?
Here´s my code.</p>

<pre><code>float i=1;
void setup() {
  fullScreen(P3D);
}

void draw() {
  background(255);
  drawCircle(width/2, height/2, i++/50);
}

void drawCircle(float x, float y, float radius) {
  stroke(0);
  noFill();
  ellipse(x, y, radius, radius);
  pushMatrix();  
  translate(x, y);
  rotate(i++/50000);
  box(radius);
  popMatrix();
  if (radius &gt; 2) {
    drawCircle(x + radius/2, y, radius/2);
    drawCircle(x - radius/2, y, radius/2);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Sierpinski triangle/gasket</title>
      <link>https://forum.processing.org/two/discussion/24315/sierpinski-triangle-gasket</link>
      <pubDate>Fri, 29 Sep 2017 22:36:22 +0000</pubDate>
      <dc:creator>siribiriz</dc:creator>
      <guid isPermaLink="false">24315@/two/discussions</guid>
      <description><![CDATA[<p>Greetings</p>

<p>I hope some one can point me in the right direction. I am attempting to recreate this fractal using a <a rel="nofollow" href="https://books.google.com/books?id=exnWM_ZHK0MC&amp;pg=PA178#v=onepage&amp;q&amp;f=false">game of chaos</a> with a random die roll. Would someone who has better knowledge of PVectors please elaborate on where my code is failing? I also would appreciate constructive critique on how to better approach this problem?</p>

<pre><code>PVector pA, pB, pC, cPos, nPos;
int goal=100000;

void setup() {
  size(800,800);
  background(50);
  pA = new PVector(width/2, 100);
  pB = new PVector(100,700);
  pC = new PVector(700,700);
  cPos = new PVector();
  nPos = new PVector();
  fill(255,0,0);
  ellipse (pA.x, pA.y, 10, 10);
  fill(0,255,0);
  ellipse (pB.x, pB.y, 10, 10);
  fill(0,0,255);
  ellipse (pC.x, pC.y, 10, 10);

  fill(220);
  translate(width/2,height/2);
  for (int i=0; i&lt;=goal; i++){
    int x = int(random(1,7));

    if (x&lt;3) {
      nPos = PVector.sub(pA,cPos);
      nPos.div(2);
      ellipse (nPos.x, nPos.y, 10, 10);
    }else if ((x&gt;2) &amp;&amp; (x&lt;5)){
      nPos = PVector.sub(pB,cPos);
      nPos.div(2);
      ellipse (nPos.x, nPos.y, 10, 10);
    }else if ((x&gt;4) &amp;&amp; (x&lt;7)){
      nPos = PVector.sub(pC,cPos);
      nPos.div(2);
      ellipse (nPos.x, nPos.y, 10, 10);
    }

    cPos=nPos;
  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Fractal zoom</title>
      <link>https://forum.processing.org/two/discussion/23712/fractal-zoom</link>
      <pubDate>Sat, 05 Aug 2017 04:26:13 +0000</pubDate>
      <dc:creator>Aurelian24</dc:creator>
      <guid isPermaLink="false">23712@/two/discussions</guid>
      <description><![CDATA[<p>So i´ve just started with fractals watching shiffman nature of code videos, and im very interesting in developing fractals with infinite zoom but i´ve haven´t figured it out,i´ve already tryd with scale and zoom in z, but with no succes.</p>

<p>this is my try :</p>

<pre><code>float zoom;
float zoomspeed;
float zoomacel;
float size;

int counter;
void setup() {

  size(600, 600, P3D);
  zoomspeed = 1;
  zoomacel = 0;
  size = 100;
}

void draw() {
  background(255);
  zoomspeed +=zoomacel;
  zoom += zoomspeed;

  translate(0, 0, zoom);
  fill(0);
  drawcircle(width/2,height/2,600);


  fill(255, 0, 0);

}

void drawcircle(float x,float y,float size) {


  fill(255);
  ellipse(x, y, size, size);
  fill(0);
  ellipse(x, y, size*0.90, size*0.90);

  if (size &gt; 0.1) {
    counter++;
    size*=0.75;
    drawcircle(x,y,size);
    //println("SIZE :", size);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Chaos game</title>
      <link>https://forum.processing.org/two/discussion/22434/chaos-game</link>
      <pubDate>Sun, 07 May 2017 10:17:26 +0000</pubDate>
      <dc:creator>noahbuddy</dc:creator>
      <guid isPermaLink="false">22434@/two/discussions</guid>
      <description><![CDATA[<p>After I saw the chaos game video from Numberphile, I recreated it that evening but spent much longer playing around with it. I am placing a basic version here thinking someone else may enjoy.
* Edited with suggestions from <a href="/two/profile/jeremydouglass">@jeremydouglass</a></p>

<pre><code>int N = 3; // Number of control points
int MAX_DIST = 60;
int MANY_TIMES = 2000;
float DIV = 2.0; // You can change the rules for drawing the pattern

// Control points
float[] px = new float[N];
float[] py = new float[N];

// The moving point, draws the pattern
float selx = 0;
float sely = 0;

boolean held = false;
int nearest = -1;

void setup()
{
  size(800,600,P2D);

  // Initial points, anywhere you like
  px[0] = width/4;
  py[0] = height/4;
  px[1] = width - (width/4);
  py[1] = height/4;
  px[2] = width - (width/4);
  py[2] = height - (height/4);

  noFill();
  frameRate(60);
  background(0);
}

void mouseMoved()
{
  float neardist = width + height;
  for (int i=0; i&lt;N; i++)
  {
    float nd = dist(px[i],py[i], mouseX,mouseY);
    if (nd &lt; neardist)
    {
      nearest = i;
      neardist = nd;
    }
  }
  if (MAX_DIST &lt; neardist)
  {
    nearest = -1;
  }
}

void mousePressed()
{
  if (-1 != nearest)
  {
    held = true;
  }
}
void mouseReleased()
{
  held = false;
}

void draw()
{
  // This section allows you to move the control points
  if (held)
  {
    px[nearest] = constrain(mouseX,0,width);
    py[nearest] = constrain(mouseY,0,height);
    background(0);
  }
  // Still not to the pattern code

  // Show control points
  for (int i=0; i&lt;N; i++)
  {
    if (i == nearest)
    {
      stroke(0,255,0);
    }
    else
    {
      stroke(0,0,255);
    }
    ellipse( px[i],py[i], MAX_DIST,MAX_DIST );
  }

  stroke(255);
  for (int i=0; i&lt;MANY_TIMES; i++) // Draw many points
  {
    // These are the lines that actually generate the pattern.
    int thistime = (int)random(N);
    float nx = ((px[thistime] - selx) / DIV) + selx;
    float ny = ((py[thistime] - sely) / DIV) + sely;
    selx = nx;
    sely = ny;
    // Yep, that is it.

    point( nx, ny );
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Julia Set with Quaternions</title>
      <link>https://forum.processing.org/two/discussion/16016/julia-set-with-quaternions</link>
      <pubDate>Thu, 14 Apr 2016 10:03:37 +0000</pubDate>
      <dc:creator>MrGonao</dc:creator>
      <guid isPermaLink="false">16016@/two/discussions</guid>
      <description><![CDATA[<p>Hello. Fractals have been what I enjoy programming the most.  This last time I've done some work with Julia Sets and quaternions. 
For those who don't know what Julia sets are they are some sort of iterative function using complex numbers, I will leave a like to the wiki page here: <a href="https://en.wikipedia.org/wiki/Julia_set" target="_blank" rel="nofollow">https://en.wikipedia.org/wiki/Julia_set</a></p>

<p>For those who don't know what Quaternions are they are sort of complex number, but with 4 dimensions instead of 2, and here is the link if you want to do some reading : <a href="https://en.wikipedia.org/wiki/Quaternion" target="_blank" rel="nofollow">https://en.wikipedia.org/wiki/Quaternion</a></p>

<p>To explain my work: I use the normal f(z)=z^2+c to iterate over z, but instead of it being a complex number now it is a quaternion, which gives me a 4d object instead of a 2d one that you normally get using the normal julia iteration. Next I fix the w coordinate and the z coordinate, having now a 2d slice of the 4d object. With the "a" and "d" keys you can slide along the z axis, but not the w. C also has 4 coordinates, let's call them a,b,c,d, and the values are displaying along side de drawing. You can change them by moving the mouse to the top, the bottom or the sides, and pressing. You can see how it works easily, basically the top changes the a coordinate, the bottom changes b, right changes c and left changes d.</p>

<p>If anyone has some ideas on how to draw the set straight to 3d and wants to discuss some maths I would gladly appreciate it; any improvements on my code are also welcome.</p>

<p>I leave the code here: <a href="http://pastebin.com/E532V1GJ" target="_blank" rel="nofollow">http://pastebin.com/E532V1GJ</a></p>

<p>Have a nice day and thanks for your time.</p>
]]></description>
   </item>
   <item>
      <title>Designing fractals</title>
      <link>https://forum.processing.org/two/discussion/12413/designing-fractals</link>
      <pubDate>Sat, 05 Sep 2015 18:20:42 +0000</pubDate>
      <dc:creator>pacoruiz</dc:creator>
      <guid isPermaLink="false">12413@/two/discussions</guid>
      <description><![CDATA[<p>Hi. Im trying to make sketches to design fractals. There are several ways to draw one, but all of them are based on transformations. I´ve made one to generate sierspinsky triangle, and it works. Ive change the parameters to make a Barnsley Fern, and the result has nothing to do with it. I´ve taken the parameters from this page. <a rel="nofollow" href="http://www.home.aone.net.au/~byzantium/ferns/fractal.html">home.aone.net.au/~byzantium/ferns/fractal.html</a> . Im not drawing the central line.</p>

<p>This is the code for sierpinsky</p>

<pre><code>    class Forma{
      float[] x = new float[4];
      float[] y = new float [4];
      Forma(float x0, float x1, float x2, float x3, float y0, float y1, float y2, float y3){
        x[0]=x0;x[1]=x1;x[2]=x2;x[3]=x3; y[0]=y0;y[1]=y1;y[2]=y2;y[3]=y3;

      }

      void render(){
        quad(x[0]*escala,y[0]*escala,x[1]*escala,y[1]*escala,x[3]*escala,y[3]*escala,x[2]*escala,y[2]*escala);
      }
    }

    int n = 3; //número de transformaciones
    ArrayList formas= new ArrayList();
    int iterando = 0;
    int escala =300;


    void setup() {
      size(500, 500, P2D);
      background(250);
      formas.add ( new Forma(0.0, 1.0,0.0, 1.0, 0.0,0.0,1.0,1.0));
      noLoop();
    }
    int iterations = 4;
    float x=0.5;
    float y=0.5;
    color col = color(100, 50,255);
    int maxiterations = 1000000;

    void draw() {
    background(255);
    fill(255,100,100);
    for(int i = 0; i&lt;iterations;i++){
      itera();
      background(255);
    }
    render();


      /**for (int i = 0; i &lt; maxiterations; i++) {
        transform();
      }
      save ("sierpinski.jpg");
      */
    }
    void itera(){
      //println("iterando");
      float[] a = {0.5, 0.5, 0.5};
      float[] b = { 0, 0, 0};
      float[] c = { 0, 0,0};
      float[] d = { 0.5, 0.5,0.5};
      float[] e = { 0, 0.5, 0.25};
      float[] f = { 0,0,0.5};
      float[] x = new float[4];
      float[] y = new float [4];
      int total=formas.size();
     println("total="+total); 
      for(int i=0;i&lt;total;i++){
         Forma form = (Forma) formas.get(i);
         //println("forma cogida");
         for(int j=0;j&lt;4;j++){
             //println("x="+ form.x[j]);
             //println("y="+ form.y[j]);
           }
         for (int k = 0; k &lt; n; k++){
           //println("puntos");
           for (int j = 0; j &lt; 4; j++){
             x[j] = form.x[0]+a[k]*(form.x[j]-form.x[0]) + b[k] * (form.y[j]-form.y[0]) + e[k]*(form.x[1]-form.x[0]);;
             //println("x="+x[j]);
             y[j] = form.y[0]+c[k]*(form.x[j]-form.x[0]) + d[k] * (form.y[j]-form.y[0]) + f[k]*(form.y[3]-form.y[0]);
             //println("y="+y[j]);
           }
           formas.add ( new Forma(x[0],x[1],x[2],x[3],y[0],y[1],y[2],y[3]));
           println("creating "+x[0]+" "+x[1]+" "+x[2]+" "+x[3]+" "+y[0]+" "+y[1]+" "+y[2]+" "+y[3]);
           //quad(x[0]*escala,y[0]*escala,x[1]*escala,y[1]*escala,x[3]*escala,y[3]*escala,x[2]*escala,y[2]*escala);
         }


      }
      for(int i=total-1;i&gt;=0;i--){
       Forma form = (Forma) formas.get(i);
       println("erasing "+i);
       muestra(form);
       formas.remove(i);
      } 

      /**for(int i=0;i&lt;formas.size();i++){
         Forma form = (Forma) formas.get(i);

           println("forma"+i);
           for(int j=0;j&lt;4;j++){
             println("x="+ form.x[j]);
             println("y="+ form.y[j]);
           }

      }*/
    }
    void render(){
      for(int i=0;i&lt;formas.size();i++){
         Forma f = (Forma) formas.get(i);
         f.render();
      }
    }

    void muestra(Forma form){
      for(int j=0;j&lt;4;j++){
             println("x="+ form.x[j]);
             println("y="+ form.y[j]);
           }
    }
</code></pre>

<p>And this is the code for Barnsley</p>

<pre><code>class Forma{
  float[] x = new float[4];
  float[] y = new float [4];
  Forma(float x0, float x1, float x2, float x3, float y0, float y1, float y2, float y3){
    x[0]=x0;x[1]=x1;x[2]=x2;x[3]=x3; y[0]=y0;y[1]=y1;y[2]=y2;y[3]=y3;

  }

  void render(){
    quad(x[0]*escala+despl,y[0]*escala ,x[1]*escala + despl,y[1]*escala ,x[3]*escala + despl,y[3]*escala ,x[2]*escala + despl,y[2]*escala);
  }
}

int n = 3; //número de transformaciones
ArrayList formas= new ArrayList();
int iterando = 0;
int escala =200;
int despl =300;


void setup() {
  size(500, 500, P2D);
  background(250);
  formas.add ( new Forma(0.0, 1.0,0.0, 1.0, 0.0,0.0,1.0,1.0));
  noLoop();
}
int iterations = 8;
float x=0.5;
float y=0.5;
color col = color(100, 50,255);
int maxiterations = 1000000;

void draw() {
background(255);
fill(255,100,100);
for(int i = 0; i&lt;iterations;i++){
  itera();
  background(255);
}
render();


  /**for (int i = 0; i &lt; maxiterations; i++) {
    transform();
  }
  save ("sierpinski.jpg");
  */
}
void itera(){
  //println("iterando");
  float[] a = {0.85, 0.2, -0.15};
  float[] b = { 0.04, -0.26, 0.28};
  float[] c = { -0.04, 0.23,0.26};
  float[] d = { 0.85, 0.22,0.24};
  float[] e = { 0, 0, 0};
  float[] f = { 1.6,1.6,0.44};
  float[] x = new float[4];
  float[] y = new float [4];
  int total=formas.size();
 println("total="+total); 
  for(int i=0;i&lt;total;i++){
     Forma form = (Forma) formas.get(i);
     //println("forma cogida");
     for(int j=0;j&lt;4;j++){
         //println("x="+ form.x[j]);
         //println("y="+ form.y[j]);
       }
     for (int k = 0; k &lt; n; k++){
       //println("puntos");
       for (int j = 0; j &lt; 4; j++){
         x[j] = form.x[0]+a[k]*(form.x[j]-form.x[0]) + b[k] * (form.y[j]-form.y[0]) + e[k]*(form.x[1]-form.x[0]);;
         //println("x="+x[j]);
         y[j] = form.y[0]+c[k]*(form.x[j]-form.x[0]) + d[k] * (form.y[j]-form.y[0]) + f[k]*(form.y[3]-form.y[0]);
         //println("y="+y[j]);
       }
       formas.add ( new Forma(x[0],x[1],x[2],x[3],y[0],y[1],y[2],y[3]));
       println("creating "+x[0]+" "+x[1]+" "+x[2]+" "+x[3]+" "+y[0]+" "+y[1]+" "+y[2]+" "+y[3]);
       //quad(x[0]*escala,y[0]*escala,x[1]*escala,y[1]*escala,x[3]*escala,y[3]*escala,x[2]*escala,y[2]*escala);
     }


  }
  for(int i=total-1;i&gt;=0;i--){
   Forma form = (Forma) formas.get(i);
   println("erasing "+i);
   muestra(form);
   formas.remove(i);
  } 

  /**for(int i=0;i&lt;formas.size();i++){
     Forma form = (Forma) formas.get(i);

       println("forma"+i);
       for(int j=0;j&lt;4;j++){
         println("x="+ form.x[j]);
         println("y="+ form.y[j]);
       }

  }*/
}
void render(){
  for(int i=0;i&lt;formas.size();i++){
     Forma f = (Forma) formas.get(i);
     f.render();
  }
}

void muestra(Forma form){
  for(int j=0;j&lt;4;j++){
         println("x="+ form.x[j]);
         println("y="+ form.y[j]);
       }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Fractal tree blowing in the wind</title>
      <link>https://forum.processing.org/two/discussion/11409/fractal-tree-blowing-in-the-wind</link>
      <pubDate>Tue, 23 Jun 2015 06:58:11 +0000</pubDate>
      <dc:creator>nikolaj</dc:creator>
      <guid isPermaLink="false">11409@/two/discussions</guid>
      <description><![CDATA[<p>The mathematically perfect fractal tree, is being bend by the wind.</p>

<p>You can control the angle the wind is comming from, with the left/right arrow keys, and increase/decrease the strength with the up/down arrow keys, press space to hide/unhide wind speed and direction indicator.</p>

<p>Assumptions made:</p>

<ol>
<li><p>The wind is 100% consistant, (always comming from the same angle, with the same force).</p></li>
<li><p>Gravity doesn't effect the tree (or rather the effect can't be seen).</p></li>
<li><p>Shorter branches, are always thinner than longer branches, and therefor easier bend by the wind.</p></li>
<li><p>The effect of the 3. assumption, is so great, that the lever principle can be ignored.</p></li>
<li><p>The branches of the tree can be bend, without ever breaking.</p></li>
<li><p>When not effected by the wind, a branch will move back to its starting position .</p></li>
<li><p>The wind can come from all directions.</p></li>
</ol>

<p>Download code at Githup <a rel="nofollow" href="https://github.com/nikolajRoager/windyTree.git">https://github.com/nikolajRoager/windyTree.git</a></p>

<p><img src="http://forum.processing.org/two/uploads/imageupload/313/E3F3XQVQGKRX.png" alt="windy" title="windy" /></p>
]]></description>
   </item>
   </channel>
</rss>