cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <div id="WebGL-output"></div>
<div id="Stats-output"></div>
            
          
!
            
              body {
  margin: 0;
  overflow: hidden;
  background : #270000;
}

/* p5.js canvas */

#defaultCanvas0 {
  display: none;
}
            
          
!
            
              // 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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console