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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              %p 
  Click to refresh and press any key to toggle explosions.
            
          
!

CSS

            
              html,
body {
  margin: 0px;
  overflow: hidden;
  background: rgb(4, 4, 4);
}

p {
  position: absolute;
  text-align: center;
  width: 100%;
  bottom: 20px;
  line-height: 20px;

  color: rgba(100, 100, 100);
  font-family: Helvetica;

  text-shadow: 0px 0px 5px black;
}

a {
  transition: 0.5s;
  text-decoration: none;
}

/* unvisited link */
a:link {
  color: rgb(220, 220, 220);
}

/* visited link */
a:visited {
  color: rgb(150, 150, 150);
}

/* mouse over link */
a:hover {
  color: white;
}

/* selected link */
a:active {
  color: white;
}
            
          
!

JS

            
              let props = {n: 100, scale: 30, speedx: 0.05, speedy: 0.05, explodetime: 100}

let points = [];
let existing = [];

let fadetime = 0;

let pressed = false;

function setup() {
  createCanvas(windowWidth, windowHeight);
  
  colorMode(HSB, 1.0);
  background(0.05);
  stroke(1);
  strokeWeight(5);
    
  points.push(new ExpandingPoint(0, 0, 0, 0, 0));
  points[0].expand();
  
  
  // datGUI setup
  let gui = new dat.GUI();

  gui
    .add(props, 'n', 50, 1000)
    .step(1)
    .name("Number of points");

  gui
    .add(props, 'scale', 10, 100)
    .name("Point seperation");
 
  gui
    .add(props, 'explodetime', 25, 500)
    .name("Max explode time");
  
  gui
    .add(props, "speedx", 0.01, 0.2)
    .name("x speed");
  
  gui
    .add(props, "speedy", 0.01, 0.2)
    .name("y speed");
}

function draw() {
  translate(width / 2, height / 2);
  
  if (props.n - points.length < 3)
    background(0.05, 0.075);
  
  let completed = true;
  for (let i = 0; i < points.length; i++) {
    const p = points[i];
    
    p.step();
    p.draw();
    
    if (!p.completed) completed = false;
  }
    
  if (completed && !pressed) {
    points = [];
    existing = [];
    points.push(new ExpandingPoint(0, 0, 0, 0, 0));
    points[0].expand();
  }
}

function keyPressed() {
  pressed = !pressed;
}

function mousePressed() {
  background(0.05);
  points = [];
  existing = [];
  points.push(new ExpandingPoint(0, 0, 0, 0, 0));
  points[0].expand();
}

class ExpandingPoint {
  constructor(x, y, tx, ty, parenthue) {
    
    // Initial position
    this.ix = x;
    this.iy = y;
    
    // Current position
    this.x = x;
    this.y = y;
    
    // Target position
    this.tx = tx;
    this.ty = ty;
    
    this.expaned = false;
    
    this.time = 0;
    existing.push([this.tx, this.ty]);
    
    this.exploding = floor(random(props.explodetime));
    
    this.hue = parenthue + random(0.1);
    
    this.completed = false;
  }
  
  step() {
    this.x = lerp(this.x, this.tx, props.speedx);
    this.y = lerp(this.y, this.ty, props.speedy);
    
    if (this.time == this.exploding) {
      this.expand();
    }
    
    this.time++;
  }
  
  draw() {
    stroke(this.hue, 0.8, 1, constrain(1 - this.time / 50, 0, 1));
    strokeWeight(this.time / 10);
    point(this.x, this.y);
  }
  
  expand() {    
    let current = [this.x, this.y];
    
    let targets = [[this.tx, this.ty + props.scale],
                  [this.tx, this.ty - props.scale],
                  [this.tx + props.scale, this.ty],
                  [this.tx - props.scale, this.ty]];
    
    for (const target of targets) {
      let repeat = false;
      for (const exist of existing) {
        if (exist[0] == target[0] && exist[1] == target[1])
          repeat = true;
      }
      
      if (repeat) continue;
      
      if (points.length < props.n)
        points.push(new ExpandingPoint(...current, ...target, this.hue));
    }
    
    this.completed = true;
  }
}
            
          
!
999px

Console