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

              
                body{margin:0;}
canvas{display: block;}
              
            
!

JS

              
                /* 
Cells - for Dress of Life
Vivian Wong
Professor Adam Tindale, Kate Hartman, Haru Ji
DIGF 2004 - Atelier I
Wednesday December 6, 2017

Inspired by Casey Reas
Modification of experiment 3 P5.js animating elements.

Blue circles represent cells that populate an organism.
Cells are an integral part of life and evolution.

Form: Circle
Behaviour 1: Wander by a random walk from center of canvas
Behaviour 2: If leaving one edge of the canvas, appear at the other edge of the canvas, except for bottom edge

E1 = F1 + B1 + B2

Rule:
Fill canvas with instances of Element 1.

References:
http://genekogan.com/code/p5js-perlin-noise/
https://jiharu.github.io/atelier/caseyR.html
https://www.openprocessing.org/sketch/460133
https://www.openprocessing.org/sketch/428145
*/

let elements = [];  // elements array for cells

function setup() {
  canvas = createCanvas(windowWidth, windowHeight);
  background(0);    // start with black background
  noStroke();       // remove stroke
  noFill();         // remove fill
  
 // create for loop for 200 elements
  for (let i = 0; i < 200; i++) {
    // create elements array, start element position at center of canvas
    elements[i] = {
      x: width/2,        
      y: height/2,  
      r: random(3, 20),
      s: random(-10, 10),
      sp: random(0.2,0.8)
    };
  }
}

function draw() {
  background(0, 4);   // fade in black background
  
  // for loop to create array of elements
  for (let i = 0; i < elements.length; i++) {
    let e = elements[i];
    
    // set variable c as colour based on rgba variables
    c = color(10*noise(50, 70), 20*random(60,70), random(200, 250), 100); // cyan colour
    fill(c);
    // draw elements on canvas
    ellipse(e.x, e.y, e.r);

    // wander by a random walk multiplied by speed variable
    e.x += random(-e.s, e.s) * e.sp;
    e.y += random(-e.s, e.s) * e.sp;

    // if top, bottom, left, or right edge is touched, element goes to opposite side of canvas
    if (e.x < 0) {
      e.x += width;
    }
    if (e.x > width) {
      e.x -= width;
    }
    if (e.y < 0) {
      e.y += height;
    }
    if (e.y > height) {
      e.y -= height;
    }
  }

              
            
!
999px

Console