Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                
// fractal tree algorithm leared from Daniel Shiffman's tutorial: 
// https://www.youtube.com/watch?v=0jjeOYMjmDU
// a generative animation of tree/roots
var le;
var nois;
var n;
var e1;

var x1, y1;
var perlin1;

function setup() {
  createCanvas(800, 1000);
  background(0); 
  //set the initial length of the branch
  le=10;

  //set the start point of the line 
  e1=0;


}

function draw() {
n=random(30,50);
//stroke colour is changing along with the frameCount
stroke(frameCount%255);
strokeWeight(0.1);
fill(250);

//set the x and y position  of the tree
x1=400;
y1=120;

//a line made by moving ellipse showing up firstly, from the top of the screen
ellipse(x1,e1+=1,1);

//if the line achieves the y1 position, then start this tree animation
  if(e1>y1){
    e1=y1; 
    push();
    branchLines(le,x1,y1);
    pop();
   
   }
 
 //the length of each branch is increasing, as if they are growing
  le+=0.1;


}

// the fractal tree function len: how long each branch supposed to be
//x, y: the position of the branch
function branchLines(len,x,y) {
 
  translate(x,y);
  //draw a line as the first branch (first generation)
   line(0,0,0, le);

  if(len>n){
  //translate the position of this branch 
   translate(0,n*1.2);
   //use push and pop function to make sure the rotation  function only applied on the branch we want
    push();
  //rotate PI/30 degree as the new branch on the left side(the second generation)
    rotate(PI/30);
  //call the branch function inside itself, so the animation could generate by itself again and again
  //shrink the length of this new branch 
    branchLines(len*0.8);
    pop();

   //rotate -PI/30 degree as the new branch on the right side (also the second generation) 
    push();
    rotate(-PI/30);
    //shrink the length of this new branch
    branchLines(len*0.8);
    pop();

}

}



              
            
!
999px

Console