Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!--
    Old-school method of animating:  setTimeout()

    Probably would be smoother using CSS Animation
    but only had some much time to throw this together

    ๐Ÿ˜œ



-->
<div id="portal"> 
  <div id="dspArea"> 
  </div><!-- dspArea -->
  <div id="title">Fruit and Veg</div>
</div><!-- portal -->
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Montserrat:800&display=swap');

body {
  overflow:hidden;
  margin:0;
  
}

.fruitAndVeg {
  display:none;
}

#portal {
  position:absolute;
  overflow:hidden;
  margin:0;
  padding:0;
  top:0px;
  left:0px;
  background: rgb(65,56,117);
  background: linear-gradient(0deg, rgba(65,56,117,1) 0%, rgba(161,59,46,1) 100%);

}


#dspArea {
  position:absolute;
  overflow:hidden;
  background: rgb(73,199,244);
  background: linear-gradient(0deg, rgba(73,199,244,1) 0%, rgba(45,253,230,1) 100%);
  width:400px;
  border-left:solid #7733ff 3px;
  border-right:solid #2a0080 3px;
}

#title {
  z-order:10;
  text-align:center;
  width:400px;
  position:absolute;
  top:10px;
  font-family: Montserrat, Helvetica, Arial, sans-serif;
  font-size:26pt;
  color:#660033;
  text-shadow:3px 3px 4px gray;
}



.small0 {
  position:absolute;
  width:40px;
  height:50px;
 
  z-order:1;
  font-size:30pt;
}

.small1 {
  position:absolute;
  width:50px;
  height:50px;
  
  z-order:1;
  overflow:hidden;
  font-size:34pt;
}

.small2 {
  position:absolute;
  width:60px;
  height:60px;
  
  z-order:1;
  overflow:hidden;
  font-size:38pt;
}

.medium0 {
  position:absolute;
  width:66px;
  height:66px;
  
  z-order:1;
  overflow:hidden;
  font-size:44pt;
}

.medium1 {
  position:absolute;
  width:70px;
  height:70px;
  
  z-order:1;
  overflow:hidden;
  font-size:48pt;
}

.medium2 {
  position:absolute;
  width:70px;
  height:70px;
  
  z-order:1;
  overflow:hidden;
  font-size:50pt;
}

.large0 {
  position:absolute;
  width:80px;
  height:80px;
  
  z-order:1;
  font-size:70pt;
}

.large1 {
  position:absolute;
  width:80px;
  height:80px;
  
  z-order:1;
  font-size:75pt;
}

.large2 {
  position:absolute;
  width:100px;
  height:100px;
  
  z-order:1;
  font-size:95pt;
}
              
            
!

JS

              
                let w,h;
let sPieces = [];
let nIdCount = 0;
let sTypes = [];
let nSpeeds = [];
let nSpinSpeeds = [];
let batchInfo = {};
let currentPieces = [];

const BATCH_TOTAL1 = 155;
const BATCH_TOTAL2 = 155;


function pageSetup() {
    
  sPieces[0] = [];
  sPieces[1] = [];
  sPieces[2] = [];
  
  sPieces[0][0] = "๐ŸŒถ";
  sPieces[0][1] = "๐Ÿ’";
  sPieces[0][2] = "๐Ÿ“";
  
  sPieces[1][0] = "๐ŸŽ";
  sPieces[1][1] = "๐Ÿ…";
  sPieces[1][2] = "๐ŸŒฝ";
  sPieces[1][3] = "๐Ÿฅ•";
  sPieces[1][4] = "๐Ÿฅฆ";
  sPieces[1][5] = "๐Ÿ‹";
  sPieces[1][6] = "๐Ÿ‡";
  sPieces[1][7] = "๐Ÿ“";
  sPieces[1][8] = "๐Ÿ";
  
  sPieces[2][0] = "๐Ÿ‰";
  sPieces[2][1] = "๐Ÿ";
  
  
  sTypes[0] = "small";
  sTypes[1] = "medium";
  sTypes[2] = "large";
  
  nSpeeds[0] = 8;
  nSpeeds[1] = 12;
  nSpeeds[2] = 16;
  nSpeeds[3] = 20;
  
  nSpinSpeeds[0]=1;
  nSpinSpeeds[1]=4;
  nSpinSpeeds[2]=8;
  nSpinSpeeds[3]=20;
  
  window.addEventListener('resize', pageResize);
  pageResize();
  
  makeABatch();
  setTimeout("renderFruitAndVeg()",1000); // give time for first batch to be made (at least some of it)
  console.log("got to end of pageSetup()")
} // end of function pageSetup()


function pageResize() {
  w = window.innerWidth;
	h = window.innerHeight;
  
  let nLeft = Math.floor((w - 400) / 2);
  
  if (nLeft < 0) {
    nLeft = 0;
  } // end if
  
  let portal = $("#portal")[0];
  portal.style.width = (w)+"px";
  portal.style.height = (h)+"px";
  
  let dspArea = $("#dspArea")[0];
  dspArea.style.left = (nLeft)+"px";
  dspArea.style.height = (h)+"px";
  
  let title = $("#title")[0];
  title.style.left = (nLeft)+"px";
} // end of function pageResize()


function rnd(nNum) {
  return Math.floor(Math.random() * nNum);
} // end of function rnd


function makeAPiece() {
  const dspArea = $("#dspArea")[0];
  let nType = rnd(3);
  let nSize = rnd(3);
  let sPossibilities = sPieces[nType];

  let nPiece = rnd(sPossibilities.length);
  let sPiece = sPossibilities[nPiece];//.substr(nPiece,1);
  let sClass = sTypes[nType] + (nSize);
  let nTotalDropDistance = h + Math.floor(h/3);
  let piece = {};
  piece.char = sPiece;
  piece.className = sClass;
  piece.totalDropDistance = nTotalDropDistance;
  piece.currentPos = 0 - Math.floor(h/5);
  piece.currentAngle = rnd(364);
  piece.speed = rnd(4);
  piece.spinSpeed = rnd(4);
  const el = document.createElement("div");
  el.innerHTML = sPiece;
  el.className = sClass;
  nIdCount++;
  
  if (nIdCount>100000) {
    nIdCount = 1;
  } // end if
  
  piece.elId = "pc"+nIdCount;
  el.id = piece.elId;
  let nLeft = rnd(h) - 40;
  el.style.left = (nLeft)+"px";
  el.style.top = (piece.currentPos)+"px";
  el.style.transform = "rotate("+(piece.currentAngle)+"deg)";
  piece.el = el;
  dspArea.appendChild(el);  
  currentPieces.push(piece);
  //console.log(sClass)
} // function makeAPiece() 


function makeABatch() {
  batchInfo.currentIndex = 0;
  batchInfo.batchTotal = rnd(BATCH_TOTAL1)+BATCH_TOTAL2;
  setTimeout("makeABatch2()", 10)
} // end of function makeABatch()



function makeABatch2() {
  makeAPiece();
  batchInfo.currentIndex++;
  let nDelay;
  if (batchInfo.currentIndex < batchInfo.batchTotal) {
    nDelay = rnd(200)+100;
    setTimeout("makeABatch2()",nDelay);
  } else {
    nDelay = (rnd(2)+1) * 1000 + rnd(200);
    setTimeout("makeABatch()",nDelay);
  } // end if/else
  
}// end of function makeABatch2()



function renderFruitAndVeg() {
  let n,el;
  //console.log("efg "+currentPieces.length)

  for (n=0;n<currentPieces.length;n++) {
    piece = currentPieces[n];
    //console.log("before currentPos")
    piece.currentPos = piece.currentPos + nSpeeds[piece.speed];
    piece.currentAngle = piece.currentAngle + nSpinSpeeds[piece.spinSpeed];
    
    if (piece.currentAngle > 364) {
      piece.currentAngle = 0;
    } // end if
    
    el = piece.el;
   // console.log("before style top "+piece.currentPos)
    el.style.top = (piece.currentPos)+"px";
    el.style.transform = "rotate("+(piece.currentAngle)+"deg)";
  //  console.log("after style top")
    if (piece.currentPos > piece.totalDropDistance) {
      console.log("deleting")
      el.parentNode.removeChild(el);
      currentPieces.splice(n, 1); 
      n--;
    } // end if
  } // end for let
  //console.log("abc")
  setTimeout("renderFruitAndVeg()",5);
} // end of function renderFruitAndVeg



pageSetup();
              
            
!
999px

Console