cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console