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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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;
  padding: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: black;
}

              
            
!

JS

              
                //click mouse to start
//press key to reset to worm-like entity
let kitty; //class picked song name
let playBool = false;
let sArray = []; //array of dancing circles
let spectrum;
let waves;
let fft;
let t = 0;
let n = 200;
function preload() {
  userStartAudio();
  //track created on soundtrap w/loops to test code
  kitty = loadSound("https://assets.codepen.io/4559259/pendulum.mp3");
}
function setup() {
  sArray = [];
  createCanvas(windowWidth, windowHeight);
  background(100);
  kitty.amp(0.4); //how loud?
  fft = new p5.FFT(); //creates sound array analyze
  spectrum = fft.analyze();
  for (let i = 0; i < spectrum.length; i++) {
    sArray.push(new dots(i));
  }
}

function draw() {
  translate(width / 2, height / 2);
  if (playBool) {
    t += 0.001;

    if (!kitty.isPlaying()) {
      kitty.play();
    }
  } else {
    kitty.pause();
  }
  rotate(t);
  background(200 + 255 * cos(t), 255 + 255 * cos(t), 255 + 255 * cos(t), 10);
  soundProcess();
}

function soundProcess() {
  spectrum = fft.analyze();
  waves = fft.waveform();
  for (let i = 0; i < spectrum.length; i += 10) {
    sArray[i].display(spectrum[i] / 10, waves[i]);
  }
}

class dots {
  constructor(i) {
    this.L = i / 10 + width / 10;
    this.theta = PI;
    this.x = this.L * sin(this.theta);
    this.y = this.L * cos(this.theta);
    this.t = 0;
  }
  display(dt, w) {
    this.t += 0.0001 + abs(w / 20 + dt / 5000);
    this.theta = TWO_PI * 2 * sin(this.t);
    this.x =
      (this.L * sin(this.theta * sin(this.t)) * sin(this.theta + this.y / 5)) /
        2 +
      (this.L / 2) * sin(this.theta + this.x / 100);
    this.y = this.L * cos(this.theta) + (this.L / 3) * cos(this.theta);
    fill(
      255 * sin(t / 2),
      355 * sin(t / 2) - this.y,
      355 * sin(t / 2) - this.x
    );
    circle(this.x, this.y, 10 + dt);
    strokeWeight(0.1);
    stroke(
      255 * sin(t) + 50,
      355 * sin(t) - this.y + 100,
      355 * sin(t) - this.x + 100,
      10
    );
    let f = width / 2;

    for (let k = 0; k < n; k++) {
      line(
        this.x,
        this.y,
        -f * sin(t + (k * PI * 2) / n),
        -f * cos(t + (k * PI * 2) / n)
      );
    }
    noStroke();
  }
}
function mousePressed() {
  playBool = !playBool;
}
function keyPressed() {
  kitty.stop();
  setup();
  draw();
}

              
            
!
999px

Console