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

              
                <div id="WebGL-output"></div>
<div id="Stats-output"></div>
              
            
!

CSS

              
                body {
  margin: 0;
  overflow: hidden;
  background : #270000;
}

/* p5.js canvas */

#defaultCanvas0 {
  display: none;
}
              
            
!

JS

              
                // global variables
var renderer;
var scene;
var camera;

var sphere, worldSphere;
var texture;
var canvas = document.getElementById('defaultCanvas0');

// init
function init() {

  // create a scene, that will hold all our elements such as objects, cameras and lights.
  scene = new THREE.Scene();

  // create a camera, which defines where we're looking at.
  camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);

  camera.position.z = 15;

  // create a render, sets the background color and the size
  renderer = new THREE.WebGLRenderer();
  renderer.setClearColor(0x270000, 1.0);
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.shadowMapEnabled = true;

  var directionalLightR = new THREE.DirectionalLight(0xff6633, 0.5);
  directionalLightR.position.set(1, 0, .25);
  scene.add(directionalLightR);

  var directionalLightL = new THREE.DirectionalLight(0xff6633, 0.5);
  directionalLightL.position.set(-1, 0, .25);
  scene.add(directionalLightL);

  var hemisphereLight = new THREE.HemisphereLight(0xD88D00, 0xD63600, 0.75);
  scene.add(hemisphereLight);

  // add the output of the renderer to the html element
  document.body.appendChild(renderer.domElement);

  var geometry = new THREE.SphereGeometry(3, 16, 16);

  texture = new THREE.Texture(canvas);

  var material = new THREE.MeshPhongMaterial({
    color: 0xffffff,
    map: texture,
    side: THREE.DoubleSide
  });
  sphere = new THREE.Mesh(geometry, material);

  sphere.position.set(0, 0, 0);
  sphere.rotation.y = -PI / 4 - 0.5;
  scene.add(sphere);

  // world sphere        
  var worldGeometry = new THREE.SphereGeometry(16, 12, 12);
  var worldMaterial = new THREE.MeshPhongMaterial({
    color: 0x863300,
    map: texture,
    side: THREE.DoubleSide
  });
  worldSphere = new THREE.Mesh(worldGeometry, worldMaterial);
  worldSphere.position.set(0, 0, 0);
  worldSphere.rotation.y = 2.5 * Math.PI;
  scene.add(worldSphere);

  // call the render function, after the first render, interval is determined
  // by requestAnimationFrame
  render();
}

function render() {

  // move camera pos left/right + back/forth to give slight rotate - using p5.js functions here
  camera.position.x = map(sin(frameCount * 0.01), -1, 1, 1.5, -1.5);
  camera.position.z = map(cos(frameCount * 0.01), -1, 1, 15, 12);

  // update texture anims
  texture.needsUpdate = true;

  // render using requestAnimationFrame
  requestAnimationFrame(render);
  renderer.render(scene, camera);
}

// resize
function handleResize() {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(window.innerWidth, window.innerHeight);
}

// start
window.onload = init;
// resize on window change
window.addEventListener('resize', handleResize, false);

// P5.js code to draw canvas animation

var blobs = [];

// constraints
var limitLeft = 0,
  limitRight = 0,
  limitTop = 0,
  limitBottom = 0;
var boxSize = 0;

function setup() {
  createCanvas(1024, 512, P2D);
  //blobs = new Blob[100];
  boxSize = 600;

  limitLeft = width / 2 - boxSize / 2,
    limitRight = width / 2 + boxSize / 2,
    limitTop = height / 2 - boxSize / 2,
    limitBottom = height / 2 + boxSize / 2;

  //blobs= [100];

  for (var i = 0; i < 100; i++) {
    blobs[i] = new Blob(width / 2, height / 2, random(20, 75));

  }
}

function draw() {
  background("#000000");

  fill(255, 15);
  //stroke(10);
  //strokeWeight(5);
  rectMode(CENTER);
  rect(width / 2, height / 2, boxSize, boxSize);

  for (var i = 0; i < blobs.length; i++) {
    blobs[i].displayOutline();
  }
  for (var i = 0; i < blobs.length; i++) {
    blobs[i].display();
    blobs[i].update();
  }
}

function Blob(_x, _y, _sz) {
  this.x = _x;
  this.y = _y;
  this.sz = _sz;

  this.vx = random(-1.5, 1.5);
  this.vy = random(-1.5, 1.5);

  this.display = function() {
    noStroke();
    fill(0);
    ellipse(this.x, this.y, this.sz, this.sz);
  };

  this.displayOutline = function() {
    noStroke();
    fill(255);
    ellipse(this.x, this.y, this.sz + 10, this.sz + 10);
  };

  this.update = function() {
    this.x = this.x + this.vx;
    this.y = this.y + this.vy;

    // constrain
    if (this.x > limitRight - this.sz / 2) {
      this.x = limitRight - this.sz / 2;
      this.vx *= -1.0;
    }

    if (this.x < limitLeft + this.sz / 2) {
      this.x = limitLeft + this.sz / 2;
      this.vx *= -1.0;
    }
    if (this.y > limitBottom - this.sz / 2) {
      this.y = limitBottom - this.sz / 2;
      this.vy *= -1.0;
    }
    if (this.y < limitTop + this.sz / 2) {
      this.y = limitTop + this.sz / 2;
      this.vy *= -1.0;
    }
  };
} // Blob
              
            
!
999px

Console