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

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

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.

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.

            
              body 
{
			margin: 0;
			padding: 0;
			background-color: #000000;
}
            
          
!
            
              // Function for sorting depth array
Array.prototype.sortByProp = function(p)
{
  return this.sort(function(a,b)
                   {
    return (parseFloat(a[p],10) > parseFloat(b[p],10)) ? 1 : (parseFloat(a[p],10) < parseFloat(b[p],10)) ? -1 : 0;
  });
}

$(window).resize(resize)
window.onorientationchange = resize;

document.addEventListener('DOMContentLoaded', start, false);

var w = 1024;
var h = 768;

var n = 2000;
var d = 1;
var current = 1;
var objs = 17;
var vx = 0;
var vy = 0;
var vz = 0;
var points1 = [];
var points2 = [];
var points3 = [];
var tpoint1 = [];
var tpoint2 = [];
var tpoint3 = [];
var ballTexture = new PIXI.Texture.fromImage("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwY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GKADAj0EAbXWW+M5LlXrm1rrzWazuff8fwMMx2klcHl6TwAAAABJRU5ErkJggg==");

// Depth array
var dl = [];

function start() {

// create an object
var rendererOptions = {
    antialiasing:true,
    transparent:false,
    forceFXAA:true,
    resolution:1
}
  renderer = PIXI.autoDetectRenderer(w, h,rendererOptions);

  stage = new PIXI.Container();
  
  //var filter = new PIXI.filters.FXAAFilter()
  
  //stage.filters = [filter];

  document.body.appendChild(renderer.view);
  

  makeObject(0);

  for (var i = 0; i < n; i++)
  {
    tpoint1[i] = points1[i];
    tpoint2[i] = points2[i];
    tpoint3[i] = points3[i];

    var tempBall = new PIXI.Sprite(ballTexture);

    // Tint the sprite.
    tempBall.tint = 0x00FF00;

    tempBall.anchor.x = 0.5;
    tempBall.anchor.y = 0.5;

    stage.addChild(tempBall);
  }

  resize();

  setTimeout(nextObject, 15000);

  requestAnimationFrame(update);

}

function nextObject () {

  current++;

  if (current > objs)
  {
    current = 0;
  }

  makeObject(current);

  setTimeout(nextObject, 24000);

}

function makeObject ( t ) {

  var xd;

  switch (t)
  {
    case 0:

      for (var i = 0; i < n; i++)
      {
        points1[i] = -50 + Math.round(Math.random() * 100);
        points2[i] = 0;
        points3[i] = 0;
      }
      break;

    case 1:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(t * 360 / n) * 10);
        points2[i] = (Math.cos(xd) * 10) * (Math.sin(t * 360 / n) * 10);
        points3[i] = Math.sin(xd) * 100;
      }
      break;

    case 2:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(t * 360 / n) * 10);
        points2[i] = (Math.cos(xd) * 10) * (Math.sin(t * 360 / n) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;

    case 3:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(xd) * 10);
        points2[i] = (Math.cos(xd) * 10) * (Math.sin(xd) * 10);
        points3[i] = Math.sin(xd) * 100;
      }
      break;

    case 4:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(xd) * 10);
        points2[i] = (Math.cos(xd) * 10) * (Math.sin(xd) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;

    case 5:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(xd) * 10);
        points2[i] = (Math.cos(i * 360 / n) * 10) * (Math.sin(xd) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;

    case 6:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(i * 360 / n) * 10) * (Math.cos(i * 360 / n) * 10);
        points2[i] = (Math.cos(i * 360 / n) * 10) * (Math.sin(xd) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;

    case 7:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(i * 360 / n) * 10) * (Math.cos(i * 360 / n) * 10);
        points2[i] = (Math.cos(i * 360 / n) * 10) * (Math.sin(i * 360 / n) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;

    case 8:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(i * 360 / n) * 10);
        points2[i] = (Math.cos(i * 360 / n) * 10) * (Math.sin(i * 360 / n) * 10);
        points3[i] = Math.sin(xd) * 100;
      }
      break;

    case 9:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(i * 360 / n) * 10);
        points2[i] = (Math.cos(i * 360 / n) * 10) * (Math.sin(xd) * 10);
        points3[i] = Math.sin(xd) * 100;
      }
      break;

    case 10:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(i * 360 / n) * 10) * (Math.cos(i * 360 / n) * 10);
        points2[i] = (Math.cos(xd) * 10) * (Math.sin(xd) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;

    case 11:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(i * 360 / n) * 10);
        points2[i] = (Math.sin(xd) * 10) * (Math.sin(i * 360 / n) * 10);
        points3[i] = Math.sin(xd) * 100;
      }
      break;

    case 12:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(xd) * 10);
        points2[i] = (Math.sin(xd) * 10) * (Math.sin(xd) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;

    case 13:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(i * 360 / n) * 10);
        points2[i] = (Math.sin(i * 360 / n) * 10) * (Math.sin(xd) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;

    case 14:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.sin(xd) * 10) * (Math.cos(xd) * 10);
        points2[i] = (Math.sin(xd) * 10) * (Math.sin(i * 360 / n) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;

    case 15:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(i * 360 / n) * 10) * (Math.cos(i * 360 / n) * 10);
        points2[i] = (Math.sin(i * 360 / n) * 10) * (Math.sin(xd) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;

    case 16:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(i * 360 / n) * 10);
        points2[i] = (Math.sin(i * 360 / n) * 10) * (Math.sin(xd) * 10);
        points3[i] = Math.sin(xd) * 100;
      }
      break;

    case 17:

      for (var i = 0; i < n; i++)
      {
        xd = -90 + Math.round(Math.random() * 180);
        points1[i] = (Math.cos(xd) * 10) * (Math.cos(xd) * 10);
        points2[i] = (Math.cos(i * 360 / n) * 10) * (Math.sin(i * 360 / n) * 10);
        points3[i] = Math.sin(i * 360 / n) * 100;
      }
      break;
  }

}

function resize()
{
  w = $(window).width() - 16;
  h = $(window).height() - 16;

  renderer.resize(w, h);
}

function update()
{
  var x3d, y3d, z3d, tx, ty, tz, ox;

  // Reset/erase depth array.
  dl = [];

  if (d < 250)
  {
    d++;
  }

  vx += 0.0075;
  vy += 0.0075;
  vz += 0.0075;


  for (var i = 0; i < n; i++)
  {
    if (points1[i] > tpoint1[i]) { tpoint1[i] = tpoint1[i] + 1; }
    if (points1[i] < tpoint1[i]) { tpoint1[i] = tpoint1[i] - 1; }
    if (points2[i] > tpoint2[i]) { tpoint2[i] = tpoint2[i] + 1; }
    if (points2[i] < tpoint2[i]) { tpoint2[i] = tpoint2[i] - 1; }
    if (points3[i] > tpoint3[i]) { tpoint3[i] = tpoint3[i] + 1; }
    if (points3[i] < tpoint3[i]) { tpoint3[i] = tpoint3[i] - 1; }

    x3d = tpoint1[i];
    y3d = tpoint2[i];
    z3d = tpoint3[i];

    ty = (y3d * Math.cos(vx)) - (z3d * Math.sin(vx));
    tz = (y3d * Math.sin(vx)) + (z3d * Math.cos(vx));
    tx = (x3d * Math.cos(vy)) - (tz * Math.sin(vy));
    tz = (x3d * Math.sin(vy)) + (tz * Math.cos(vy));
    ox = tx;
    tx = (tx * Math.cos(vz)) - (ty * Math.sin(vz));
    ty = (ox * Math.sin(vz)) + (ty * Math.cos(vz));

    var x = (512 * tx) / (d - tz) + w / 2;
    var y = (h/2) - (512 * ty) / (d - tz);

    // Calculate z co-ord (depth) of each sprite.
    var z = ((512/(d - tz)))/8;

    // Add x, y and z co-ords RE: each sprite to depth array.
    dl.push({x:x, y:y, z:z});


  }

  // Sort depth array using z co-ords in array.
  dl.sortByProp('z');

  // Delete all sprites.
  stage.removeChildren();


  for (var i = 0; i < n; i++)
  {   

    // Add all sprites again - as pixi.js draws sprites in the order they were created.
    // We need to do this as we are using the "painter's algorithm"
    var tempBall = new PIXI.Sprite(ballTexture);

    // Tint the sprite.
    tempBall.tint = 0x00FFFF;

    tempBall.anchor.x = 0.5;
    tempBall.anchor.y = 0.5;

    tempBall.position.x =  dl[i] ["x"];
    tempBall.position.y =  dl[i] ["y"];

    // Scale each sprite based on it's z co-ord.
    tempBall.scale = new PIXI.Point(dl[i] ["z"],  dl[i] ["z"]);
    
    stage.addChild(tempBall);
  }

  renderer.render(stage);

  requestAnimationFrame(update);

}

            
          
!
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.

Console