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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

              
                	

<!--
   I got the SVG image from:
     * https://commons.wikimedia.org/wiki/File:Milky_way_stargate_with_very_detailed_glyphs2.svg
     * Author: Max Willis & User:M.A.D.company
     * I split the image up into separate parts:
       - The outer edge
       - The ring that rotates
       - each Chevron

   Videos of stargate dialing:
     * https://www.youtube.com/watch?v=B8JoShAUE1U
     * https://www.youtube.com/watch?v=3Ds0DRCNXN4

   Info about how stargates are "supposed" to work:
     * https://en.wikipedia.org/wiki/Stargate_(device)
    
        - Six or more symbols must be dialed in a specific order
          to establish a wormhole with another desired gate

 -->


	Attribution: See HTML comments for information.


<div id="info"></div>
 
	<div id="stargateContainer">
		<img id="symbols" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateSymbols.svg">
		<img id="outerEdge" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateOuterEdge.svg">
		<img id="chevron1" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron1.svg">
		<img id="chevron2" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron2.svg">
		<img id="chevron3" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron3.svg">
		<img id="chevron4" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron4.svg">
		<img id="chevron5" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron5.svg">
		<img id="chevron6" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron6.svg">
		<img id="chevron7" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron7.svg">
		<img id="chevron8" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron8.svg">
		<img id="chevron9" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron9.svg">
    <div id="penTitle">#codePenChallenge</div>
	</div>
	
<div id="standAloneLink">
<a href="/orvilleChomer/debug/yvWmGY" target="_new">Stand-alone Window</a>
</div>



	<style id="animationStyles"></style>
	
              
            
!

CSS

              
                
	body {
	  background:#212121;
	}


	#stargateContainer {
		position:absolute;
	  	left:30px;
	  	top:60px;
    z-index:210;
    transform-origin:0 0;
	} 
	
	
	.stargate {
	  position:absolute;
	  left:0px;
	  top:0px;
	  width:528px;
	  height:526px;
    z-index:100;
	}

    
    .attribBtn {
    	position:absolute;
    	left:5px;
	  	top:5px;
    } 

#standAloneLink {
  display:none;
}

a {
  color:white;
  font-family: "Lato", "Lucida Grande", "Lucida Sans Unicode", Tahoma, Sans-Serif;
}

#penTitle {
  font-family: "Lato", "Lucida Grande", "Lucida Sans Unicode", Tahoma, Sans-Serif;
  position:absolute;
  top:240px;
  left:85px;
  width:354px;
  height:90px;
  overflow:hidden;
  font-family:Lucida Console;
  font-size:25pt;
  font-weight:bold;
  color:orange;
  text-align:center;
}


#info {
  position:absolute;
  top:30px;
  left:120px;
}
              
            
!

JS

              
                
	var stargate ={};
	
	pageSetup();
	
	function pageSetup() {
    var info = $("#info")[0];
    var standAloneLink = $("#standAloneLink")[0];
    var stargateContainer = $("#stargateContainer")[0];
    var outerEdge = $("#outerEdge")[0];
    var s=[];
    var nScale;
    var sScale;
    
		stargate.currentRotationDir = "clockwise";
		
    // color codes
    stargate.chevronColorNotLit = "";
		stargate.chevronColorLit = "";
    
		stargate.degreesPerSymbol = 360 / 39; // there are 39 symbols
		stargate.classCounter = 0;
		stargate.currentGateAngle = 0;
    stargate.currentSymbolIndex = 0;
    stargate.width = 700;
    stargate.animationIdx = -1;
    stargate.animationsByIndex = [];
    console.log("");
    
    stargate.addAnimation = function(sType, optParams) {
			var ani = {};
			var nMax = stargate.animationsByIndex.length;
			
			ani.animationType = sType;
			ani.idx = nMax;
			ani.optParams = optParams;
			
			stargate.animationsByIndex[nMax] = ani;
			
		} // end of method stargate.addAnimation()
    
    
    
    if(document.location.href.indexOf("debug")<0) {
      standAloneLink.style.display = "block";
    } // end if
    
    
    
    if (stargate.width > (window.innerWidth)) {
      sScale = "scale(0.72)";
      stargateContainer.style.left = "15px";
      stargateContainer.style.transform = sScale;
    } // end if    

    stargate.addAnimation("dialSymbol",{"num":5});
		//stargate.addAnimation("activateChevron",{"num":1,"xOffset":0,"yOffset":20});
		stargate.addAnimation("dialSymbol",{"num":35});
		stargate.addAnimation("dialSymbol",{"num":23});
		stargate.addAnimation("dialSymbol",{"num":4});
		stargate.addAnimation("dialSymbol",{"num":8});
		stargate.addAnimation("dialSymbol",{"num":14});
		stargate.addAnimation("updateCenterCaption",{"caption":"Engaging<br>7th Symbol"});
		stargate.addAnimation("dialSymbol",{"num":8});
		stargate.addAnimation("updateCenterCaption",{"caption":""});
    console.log("Animations added");
    runNextAnimation();
    
	} // end of function pageSetup()
	

	
	function runNextAnimation() {
		console.log("runNextAnimation() called");
		var nMax = stargate.animationsByIndex.length;
		var ani,optParams;
		
		
		if (stargate.animationIdx === nMax-1) {
			return; // done running animations
		} // end if
		
		stargate.performingAnimation = true;
		stargate.animationIdx = stargate.animationIdx + 1;
		
		ani = stargate.animationsByIndex[stargate.animationIdx];
		optParams = ani.optParams;
		
		switch(ani.animationType) {
			case "dialSymbol":
				dialSymbolNum(optParams.num);
				break;
			case "activateChevron":
				doChevronAnimation(optParams.num, 
				                   optParams.xOffset, 
				                   optParams.yOffset);
				break;
			case "updateCenterCaption":
				updateCenterCaption(optParams);
				runNextAnimation();
				break;
		} // end of switch(ani.animationType)
				
	} // end of function


	
	function animationComplete() {
		console.log("animationComplete() called");
		stargate.performingAnimation = false;
		
		runNextAnimation();
	} // end of function animationComplete()


	function crazyRounding(nNum, nPrecision) {
		var sNum = nNum+"";
		var nPos = sNum.indexOf(".");
		var nLen = sNum.length;
		var nLastDigit,nCheckDigit;
		
		if (typeof nPrecision === "undefined") {
			nPrecision = 3; // inferred precision if none is provided
		} // end if
		
		if (nPos===-1 || nPos > nLen-nPrecision) {
			return nNum; // no need to round
		} // end if
		
		nLastDigit = (sNum.substr(nPos+nPrecision,1))-0;
		nCheckDigit = (sNum.substr(nPos+nPrecision+1,1))-0;
		
		if (nCheckDigit > 5) {
			nLastDigit = nLastDigit + 1; // round up
		} // end if
		
		sNum = sNum.substr(0,nPos+nPrecision) + nLastDigit;
		nNum = sNum - 0;
		
		return nNum;
		
	} // end of function crazyRounding(()



	
	
	function dialSymbolNum(nIdx) {
		console.log("dialSymbolNum() called");
		var nIndexSymbolAngle = stargate.degreesPerSymbol * nIdx;
		var nStartAngle = stargate.currentGateAngle;
		var nEndAngle,nOffset;
		var sRotation = stargate.currentRotationDir;
		
		if (sRotation === "clockwise") {
			if (nIndexSymbolAngle < nStartAngle) {
				nOffset = nStartAngle - nIndexSymbolAngle;
				
				// instead of going backwards, go all the way
				// around (minus the offset):
				nEndAngle = nStartAngle + 360 - nOffset;
				doRotateGateAnimation(nEndAngle);
				return;
			} // end if
			
			if (nIndexSymbolAngle === nStartAngle) {
				// same spot as before? Boring!
				// go around twice (to make things a little interesting):
				nEndAngle = nStartAngle + 360 * 2;
				doRotateGateAnimation(nEndAngle);
				return;
			} // end if
			
			if (nIndexSymbolAngle > nStartAngle) {
				nOffset = nIndexSymbolAngle - nStartAngle;
				nEndAngle = nIndexSymbolAngle; // just move clockwise to the desired symbol
				
				//unless...
				if (nOffset < 181) {
					// too small of a change... we want more movement!
					nEndAngle = nEndAngle + 360;
				} // end if
				doRotateGateAnimation(nEndAngle);
				return;
			} // end if
			
		} else {
			// counter-clockwise...
			
			if (nIndexSymbolAngle > nStartAngle) {
				nOffset = nIndexSymbolAngle - nStartAngle;
				
				// instead of going forwards, go all the way
				// around (plus the offset):
				nEndAngle = nStartAngle - 360 + nOffset;
				doRotateGateAnimation(nEndAngle);
			} // end if (nIndexSymbolAngle > nStartAngle)
			
			
			if (nIndexSymbolAngle === nStartAngle) {
				// same spot as before? Boring!
				// go around twice (to make things a little interesting):
				nEndAngle = nStartAngle - 360 * 2;
				doRotateGateAnimation(nEndAngle);
				return;
			} // end if (nIndexSymbolAngle === nStartAngle)
						
			if (nIndexSymbolAngle < nStartAngle) {
				nOffset = nStartAngle - nIndexSymbolAngle;
				nEndAngle = nIndexSymbolAngle; // just move cntr clockwise to the desired symbol
				
				if (nOffset > 180) {
					// too small of a change... we want more movement!
					nEndAngle = nEndAngle - 360;
				} // end if (nOffset > 180) 
        
				doRotateGateAnimation(nEndAngle);
				return;				
			} // end if (nIndexSymbolAngle < nStartAngle)
		} // end if/else
	} // end of function dialSymbolNum()

	
	function doRotateGateAnimation(nEndAngle) {
		var sRotation = stargate.currentRotationDir;
		var s =[];
		var sClass = getAnimationClassName();
		var symbols = $("#symbols")[0];
		var animationStyles = $("#animationStyles")[0];
		var nStartAngle;
		var nSymbolAngle = 360 /39; // there are 39 symbols
    
    nEndAngle = crazyRounding(nEndAngle);    
    nStartAngle = stargate.currentGateAngle;
   	
    s[s.length] = "@keyframes "+sClass+"KF {"; 
	  s[s.length] = " from {transform: translate(0px,1px) rotate("+nStartAngle+"deg) }";
	 	s[s.length] = " to {transform: translate(0px,1px) rotate("+nEndAngle+"deg) };";	   		   	
	  s[s.length] = "}";
		s[s.length] = "";
		
	  s[s.length] = "."+sClass+" {";
    s[s.length] = " animation-delay: .25s;";
    s[s.length] = " animation-name:"+sClass+"KF;";
    s[s.length] = " animation-duration:5s;";
    s[s.length] = " animation-fill-mode: both;";
    s[s.length] = "}";	
        
    animationStyles.innerHTML = s.join("\n");
    symbols.addEventListener("animationend", runNextAnimation, false);	
		symbols.className = "stargate "+sClass;

		toggleGateRotation();
	} // end of function
	
	
	function getAnimationClassName() {
		stargate.classCounter++
		
		if (stargate.classCounter > 100) {
			stargate.classCounter = 1;
		} // end if
		
		return "aniCls"+stargate.classCounter;
	} // end of function
	
	
	function doEngageChevronAnimation() {
	} // end of function
	
	function doBlinkChevronAnimation() {
	} // end of function
	
	
	
	
	
	function toggleGateRotation() {
		var sRotation = stargate.currentRotationDir;
				
		if (sRotation === "clockwise") {
			stargate.currentRotationDir = "counter-clockwise";
		} else {
			stargate.currentRotationDir = "clockwise";
		} // end if/else	
	} // end of function
	
	

function showAttribution() {
  var attribPanel = $("#attribPanel")[0];
  
  attribPanel.style.display = "block";
  return false;
} // end of function

              
            
!
999px

Console