Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 18th, 2012  |  syntax: None  |  size: 22.42 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5.  
  6.   <meta charset="UTF-8">
  7.   <!-- IF PEN IS PRIVATE -->
  8.   <!-- <meta name="robots" content="noindex"> -->
  9.   <!-- END -->
  10.  
  11.   <title>Canvas Fireworks &middot; CodePen</title>
  12.  
  13.   <!--
  14.     Copyright (c) 2012 Jack Rugile, http://codepen.io/jackrugile
  15.  
  16.     Permission is hereby granted, free of charge, to any person obtaining
  17.     a copy of this software and associated documentation files (the
  18.     "Software"), to deal in the Software without restriction, including
  19.     without limitation the rights to use, copy, modify, merge, publish,
  20.     distribute, sublicense, and/or sell copies of the Software, and to
  21.     permit persons to whom the Software is furnished to do so, subject to
  22.     the following conditions:
  23.  
  24.     The above copyright notice and this permission notice shall be
  25.     included in all copies or substantial portions of the Software.
  26.  
  27.     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28.     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29.     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  30.     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  31.     LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  32.     OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  33.     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  34.   -->
  35.  
  36.   <link rel="stylesheet" href="http://codepen.io/stylesheets/css/reset.css">
  37.  
  38.   <style>
  39. html, body {
  40.         margin: 0;     
  41.         padding: 0;
  42. }
  43.  
  44. body {
  45.         background: #171717;
  46.         color: #999;
  47.         font: 100%/18px helvetica, arial, sans-serif;
  48. }
  49.  
  50. a {
  51.         color: #2fa1d6;
  52.         font-weight: bold;
  53.         text-decoration: none;
  54. }
  55.  
  56. a:hover {
  57.         color: #fff;   
  58. }
  59.  
  60. #canvas-container {
  61.         background: #000 url(http://jackrugile.com/lab/fireworks-v2/images/bg.jpg);
  62.   height: 400px;
  63.         left: 50%;
  64.         margin: -200px 0 0 -300px;
  65.         position: absolute;
  66.         top: 50%;
  67.   width: 600px;
  68.         z-index: 2;
  69. }
  70.  
  71. canvas {
  72.         cursor: crosshair;
  73.         display: block;
  74.         position: relative;
  75.         z-index: 3;
  76. }
  77.  
  78. canvas:active {
  79.         cursor: crosshair;
  80. }
  81.  
  82. #skyline {
  83.         background: url(http://jackrugile.com/lab/fireworks-v2/images/skyline.png) repeat-x 50% 0;
  84.         bottom: 0;
  85.         height: 135px;
  86.         left: 0;
  87.         position: absolute;
  88.         width: 100%;
  89.         z-index: 1;    
  90. }
  91.  
  92. #mountains1 {
  93.         background: url(http://jackrugile.com/lab/fireworks-v2/images/mountains1.png) repeat-x 40% 0;
  94.         bottom: 0;
  95.         height: 200px;
  96.         left: 0;
  97.         position: absolute;
  98.         width: 100%;
  99.         z-index: 1;    
  100. }
  101.  
  102. #mountains2 {
  103.         background: url(http://jackrugile.com/lab/fireworks-v2/images/mountains2.png) repeat-x 30% 0;
  104.         bottom: 0;
  105.         height: 250px;
  106.         left: 0;
  107.         position: absolute;
  108.         width: 100%;
  109.         z-index: 1;    
  110. }
  111.  
  112. #gui {
  113.         right: 0;
  114.         position: fixed;
  115.         top: 0;
  116.         z-index: 3;
  117. }
  118.   </style>
  119.  
  120.   <style>
  121.     #codepen-footer, #codepen-footer * {
  122.       -webkit-box-sizing: border-box !important;
  123.       -moz-box-sizing: border-box !important;
  124.       box-sizing: border-box !important;
  125.     }
  126.     #codepen-footer {
  127.       display: block !important;
  128.       position: fixed !important;
  129.       bottom: 0 !important;
  130.       left: 0 !important;
  131.       width: 100% !important;
  132.       padding: 0 10px !important;
  133.       margin: 0 !important;
  134.       height: 30px !important;
  135.       line-height: 30px !important;
  136.       font-size: 12px !important;
  137.       color: #eeeeee !important;
  138.       background-color: #505050 !important;
  139.       text-align: left !important;
  140.       background: -webkit-linear-gradient(top, #505050, #383838) !important;
  141.       background: -moz-linear-gradient(top, #505050, #383838) !important;
  142.       background: -ms-linear-gradient(top, #505050, #383838) !important;
  143.       background: -o-linear-gradient(top, #505050, #383838) !important;
  144.       border-top: 1px solid black !important;
  145.       border-bottom: 1px solid black !important;
  146.       border-radius: 0 !important;
  147.       border-image: none !important;
  148.       box-shadow: inset 0 1px 0 #6e6e6e, 0 2px 2px rgba(0, 0, 0, 0.4) !important;
  149.       z-index: 300 !important;
  150.       font-family: "Lucida Grande", "Lucida Sans Unicode", Tahoma, sans-serif !important;
  151.       letter-spacing: 0 !important;
  152.       word-spacing: normal !important;
  153.       word-spacing: 0 !important;
  154.       -webkit-transform: none !important;
  155.       -moz-transform: none !important;
  156.       -ms-transform: none !important;
  157.       -o-transform: none !important;
  158.       transform: none !important;
  159.     }
  160.     #codepen-footer a {
  161.       color: #a7a7a7 !important;
  162.       text-decoration: none !important;
  163.       text-shadow: none !important;
  164.       border: 0 !important;
  165.     }
  166.     #codepen-footer a:hover {
  167.       color: white !important;
  168.     }
  169.   </style>
  170.  
  171.   <script>
  172.     // Kill alerts, confirmations and prompts
  173.     // window.alert   = function(){}; we're going to allow alerts for now
  174.     window.confirm = function(){};
  175.     window.prompt  = function(){};
  176.     window.open    = function(){};
  177.     window.print   = function(){};
  178.   </script>
  179.  
  180.   <script src="http://codepen.io/javascripts/libs/prefixfree.min.js"></script>
  181.  
  182. </head>
  183.  
  184. <body>
  185.  
  186.   <div id="gui"></div>         
  187. <div id="canvas-container">
  188.   <div id="mountains2"></div>
  189.   <div id="mountains1"></div>
  190.   <div id="skyline"></div>
  191. </div>
  192.  
  193.   <script src="http://code.jquery.com/jquery-latest.js"></script>
  194.  
  195.   <script src="http://jackrugile.com/lab/fireworks-v2/js/dat.gui.min.js"></script>
  196.  
  197.   <script>
  198. (function() {
  199.  
  200. var Fireworks = function(){
  201.         /*=============================================================================*/      
  202.         /* Utility
  203.         /*=============================================================================*/
  204.         var self = this;
  205.         var rand = function(rMi, rMa){return ~~((Math.random()*(rMa-rMi+1))+rMi);}
  206.         var hitTest = function(x1, y1, w1, h1, x2, y2, w2, h2){return !(x1 + w1 < x2 || x2 + w2 < x1 || y1 + h1 < y2 || y2 + h2 < y1);};
  207.         window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();
  208.  
  209.         /*=============================================================================*/      
  210.         /* Initialize
  211.         /*=============================================================================*/
  212.         self.init = function(){
  213.                 self.canvas = document.createElement('canvas');                        
  214.                 self.canvasContainer = $('#canvas-container');
  215.  
  216.                 var canvasContainerDisabled = document.getElementById('canvas-container');
  217.                 self.canvas.onselectstart = function() {
  218.                         return false;
  219.                 };
  220.  
  221.                 self.canvas.width = self.cw = 600;
  222.                 self.canvas.height = self.ch = 400;    
  223.  
  224.                 self.particles = [];   
  225.                 self.partCount = 30;
  226.                 self.fireworks = [];   
  227.                 self.mx = self.cw/2;
  228.                 self.my = self.ch/2;
  229.                 self.currentHue = 170;
  230.                 self.partSpeed = 5;
  231.                 self.partSpeedVariance = 10;
  232.                 self.partWind = 50;
  233.                 self.partFriction = 5;
  234.                 self.partGravity = 1;
  235.                 self.hueMin = 150;
  236.                 self.hueMax = 200;
  237.                 self.fworkSpeed = 2;
  238.                 self.fworkAccel = 4;
  239.                 self.hueVariance = 30;
  240.                 self.flickerDensity = 20;
  241.                 self.showShockwave = false;
  242.                 self.showTarget = true;
  243.                 self.clearAlpha = 25;
  244.  
  245.                 self.canvasContainer.append(self.canvas);
  246.                 self.ctx = self.canvas.getContext('2d');
  247.                 self.ctx.lineCap = 'round';
  248.                 self.ctx.lineJoin = 'round';
  249.                 self.lineWidth = 1;
  250.                 self.bindEvents();                     
  251.                 self.canvasLoop();
  252.  
  253.                 self.canvas.onselectstart = function() {
  254.                         return false;
  255.                 };
  256.  
  257.         };             
  258.  
  259.         /*=============================================================================*/      
  260.         /* Particle Constructor
  261.         /*=============================================================================*/
  262.         var Particle = function(x, y, hue){
  263.                 this.x = x;
  264.                 this.y = y;
  265.                 this.coordLast = [
  266.                         {x: x, y: y},
  267.                         {x: x, y: y},
  268.                         {x: x, y: y}
  269.                 ];
  270.                 this.angle = rand(0, 360);
  271.                 this.speed = rand(((self.partSpeed - self.partSpeedVariance) <= 0) ? 1 : self.partSpeed - self.partSpeedVariance, (self.partSpeed + self.partSpeedVariance));
  272.                 this.friction = 1 - self.partFriction/100;
  273.                 this.gravity = self.partGravity/2;
  274.                 this.hue = rand(hue-self.hueVariance, hue+self.hueVariance);
  275.                 this.brightness = rand(50, 80);
  276.                 this.alpha = rand(40,100)/100;
  277.                 this.decay = rand(10, 50)/1000;
  278.                 this.wind = (rand(0, self.partWind) - (self.partWind/2))/25;
  279.                 this.lineWidth = self.lineWidth;
  280.         };
  281.  
  282.         Particle.prototype.update = function(index){
  283.                 var radians = this.angle * Math.PI / 180;
  284.                 var vx = Math.cos(radians) * this.speed;
  285.                 var vy = Math.sin(radians) * this.speed + this.gravity;
  286.                 this.speed *= this.friction;
  287.  
  288.                 this.coordLast[2].x = this.coordLast[1].x;
  289.                 this.coordLast[2].y = this.coordLast[1].y;
  290.                 this.coordLast[1].x = this.coordLast[0].x;
  291.                 this.coordLast[1].y = this.coordLast[0].y;
  292.                 this.coordLast[0].x = this.x;
  293.                 this.coordLast[0].y = this.y;
  294.  
  295.                 this.x += vx;
  296.                 this.y += vy;
  297.  
  298.                 this.angle += this.wind;                               
  299.                 this.alpha -= this.decay;
  300.  
  301.                 if(!hitTest(0,0,self.cw,self.ch,this.x-this.radius, this.y-this.radius, this.radius*2, this.radius*2) || this.alpha < .05){                                    
  302.                         self.particles.splice(index, 1);       
  303.                 }                      
  304.         };
  305.  
  306.         Particle.prototype.draw = function(){
  307.                 var coordRand = (rand(1,3)-1);
  308.                 self.ctx.beginPath();                                                          
  309.                 self.ctx.moveTo(Math.round(this.coordLast[coordRand].x), Math.round(this.coordLast[coordRand].y));
  310.                 self.ctx.lineTo(Math.round(this.x), Math.round(this.y));
  311.                 self.ctx.closePath();                          
  312.                 self.ctx.strokeStyle = 'hsla('+this.hue+', 100%, '+this.brightness+'%, '+this.alpha+')';
  313.                 self.ctx.stroke();                             
  314.  
  315.                 if(self.flickerDensity > 0){
  316.                         var inverseDensity = 50 - self.flickerDensity;                                 
  317.                         if(rand(0, inverseDensity) === inverseDensity){
  318.                                 self.ctx.beginPath();
  319.                                 self.ctx.arc(Math.round(this.x), Math.round(this.y), rand(this.lineWidth,this.lineWidth+3)/2, 0, Math.PI*2, false)
  320.                                 self.ctx.closePath();
  321.                                 var randAlpha = rand(50,100)/100;
  322.                                 self.ctx.fillStyle = 'hsla('+this.hue+', 100%, '+this.brightness+'%, '+randAlpha+')';
  323.                                 self.ctx.fill();
  324.                         }      
  325.                 }
  326.         };
  327.  
  328.         /*=============================================================================*/      
  329.         /* Create Particles
  330.         /*=============================================================================*/
  331.         self.createParticles = function(x,y, hue){
  332.                 var countdown = self.partCount;
  333.                 while(countdown--){                                            
  334.                         self.particles.push(new Particle(x, y, hue));
  335.                 }
  336.         };
  337.  
  338.         /*=============================================================================*/      
  339.         /* Update Particles
  340.         /*=============================================================================*/              
  341.         self.updateParticles = function(){
  342.                 var i = self.particles.length;
  343.                 while(i--){
  344.                         var p = self.particles[i];
  345.                         p.update(i);
  346.                 };
  347.         };
  348.  
  349.         /*=============================================================================*/      
  350.         /* Draw Particles
  351.         /*=============================================================================*/
  352.         self.drawParticles = function(){
  353.                 var i = self.particles.length;
  354.                 while(i--){
  355.                         var p = self.particles[i];                             
  356.                         p.draw();                              
  357.                 };
  358.         };
  359.  
  360.         /*=============================================================================*/      
  361.         /* Firework Constructor
  362.         /*=============================================================================*/
  363.         var Firework = function(startX, startY, targetX, targetY){
  364.                 this.x = startX;
  365.                 this.y = startY;
  366.                 this.startX = startX;
  367.                 this.startY = startY;
  368.                 this.hitX = false;
  369.                 this.hitY = false;
  370.                 this.coordLast = [
  371.                         {x: startX, y: startY},
  372.                         {x: startX, y: startY},
  373.                         {x: startX, y: startY}
  374.                 ];
  375.                 this.targetX = targetX;
  376.                 this.targetY = targetY;
  377.                 this.speed = self.fworkSpeed;
  378.                 this.angle = Math.atan2(targetY - startY, targetX - startX);
  379.                 this.shockwaveAngle = Math.atan2(targetY - startY, targetX - startX)+(90*(Math.PI/180));
  380.                 this.acceleration = self.fworkAccel/100;
  381.                 this.hue = self.currentHue;
  382.                 this.brightness = rand(50, 80);
  383.                 this.alpha = rand(50,100)/100;
  384.                 this.lineWidth = self.lineWidth;
  385.                 this.targetRadius = 1;
  386.         };
  387.  
  388.         Firework.prototype.update = function(index){
  389.                 self.ctx.lineWidth = this.lineWidth;
  390.  
  391.                 vx = Math.cos(this.angle) * this.speed,
  392.                 vy = Math.sin(this.angle) * this.speed;
  393.                 this.speed *= 1 + this.acceleration;                           
  394.                 this.coordLast[2].x = this.coordLast[1].x;
  395.                 this.coordLast[2].y = this.coordLast[1].y;
  396.                 this.coordLast[1].x = this.coordLast[0].x;
  397.                 this.coordLast[1].y = this.coordLast[0].y;
  398.                 this.coordLast[0].x = this.x;
  399.                 this.coordLast[0].y = this.y;
  400.  
  401.                 if(self.showTarget){
  402.                         if(this.targetRadius < 8){
  403.                                 this.targetRadius += .25;
  404.                         } else {
  405.                                 this.targetRadius = 1; 
  406.                         }
  407.                 }
  408.  
  409.                 if(this.startX >= this.targetX){
  410.                         if(this.x + vx <= this.targetX){
  411.                                 this.x = this.targetX;
  412.                                 this.hitX = true;
  413.                         } else {
  414.                                 this.x += vx;
  415.                         }
  416.                 } else {
  417.                         if(this.x + vx >= this.targetX){
  418.                                 this.x = this.targetX;
  419.                                 this.hitX = true;
  420.                         } else {
  421.                                 this.x += vx;
  422.                         }
  423.                 }
  424.  
  425.                 if(this.startY >= this.targetY){
  426.                         if(this.y + vy <= this.targetY){
  427.                                 this.y = this.targetY;
  428.                                 this.hitY = true;
  429.                         } else {
  430.                                 this.y += vy;
  431.                         }
  432.                 } else {
  433.                         if(this.y + vy >= this.targetY){
  434.                                 this.y = this.targetY;
  435.                                 this.hitY = true;
  436.                         } else {
  437.                                 this.y += vy;
  438.                         }
  439.                 }                              
  440.  
  441.                 if(this.hitX && this.hitY){
  442.                         var randExplosion = rand(0, 9);
  443.                         self.createParticles(this.targetX, this.targetY, this.hue);
  444.                         self.fireworks.splice(index, 1);                                       
  445.                 }
  446.         };
  447.  
  448.         Firework.prototype.draw = function(){
  449.                 self.ctx.lineWidth = this.lineWidth;
  450.  
  451.                 var coordRand = (rand(1,3)-1);                                 
  452.                 self.ctx.beginPath();                                                  
  453.                 self.ctx.moveTo(Math.round(this.coordLast[coordRand].x), Math.round(this.coordLast[coordRand].y));
  454.                 self.ctx.lineTo(Math.round(this.x), Math.round(this.y));
  455.                 self.ctx.closePath();
  456.                 self.ctx.strokeStyle = 'hsla('+this.hue+', 100%, '+this.brightness+'%, '+this.alpha+')';
  457.                 self.ctx.stroke();     
  458.  
  459.                 if(self.showTarget){
  460.                         self.ctx.save();
  461.                         self.ctx.beginPath();
  462.                         self.ctx.arc(Math.round(this.targetX), Math.round(this.targetY), this.targetRadius, 0, Math.PI*2, false)
  463.                         self.ctx.closePath();
  464.                         self.ctx.lineWidth = 1;
  465.                         self.ctx.stroke();
  466.                         self.ctx.restore();
  467.                 }
  468.  
  469.                 if(self.showShockwave){
  470.                         self.ctx.save();
  471.                         self.ctx.translate(Math.round(this.x), Math.round(this.y));
  472.                         self.ctx.rotate(this.shockwaveAngle);
  473.                         self.ctx.beginPath();
  474.                         self.ctx.arc(0, 0, 1*(this.speed/5), 0, Math.PI, true);
  475.                         self.ctx.strokeStyle = 'hsla('+this.hue+', 100%, '+this.brightness+'%, '+rand(25, 60)/100+')';
  476.                         self.ctx.lineWidth = this.lineWidth;
  477.                         self.ctx.stroke();
  478.                         self.ctx.restore();
  479.                 }                                                                
  480.         };
  481.  
  482.         /*=============================================================================*/      
  483.         /* Create Fireworks
  484.         /*=============================================================================*/
  485.         self.createFireworks = function(startX, startY, targetX, targetY){                     
  486.                 self.fireworks.push(new Firework(startX, startY, targetX, targetY));
  487.         };
  488.  
  489.         /*=============================================================================*/      
  490.         /* Update Fireworks
  491.         /*=============================================================================*/              
  492.         self.updateFireworks = function(){
  493.                 var i = self.fireworks.length;
  494.                 while(i--){
  495.                         var f = self.fireworks[i];
  496.                         f.update(i);
  497.                 };
  498.         };
  499.  
  500.         /*=============================================================================*/      
  501.         /* Draw Fireworks
  502.         /*=============================================================================*/
  503.         self.drawFireworks = function(){
  504.                 var i = self.fireworks.length;                 
  505.                 while(i--){
  506.                         var f = self.fireworks[i];             
  507.                         f.draw();
  508.                 };
  509.         };
  510.  
  511.         /*=============================================================================*/      
  512.         /* Events
  513.         /*=============================================================================*/
  514.         self.bindEvents = function(){
  515.                 $(window).on('resize', function(){                     
  516.                         clearTimeout(self.timeout);
  517.                         self.timeout = setTimeout(function() {
  518.                                 //self.canvas.width = self.cw = $(window).innerWidth();
  519.                                 //self.canvas.height = self.ch = $(window).innerHeight();
  520.                                 self.ctx.lineCap = 'round';
  521.                                 self.ctx.lineJoin = 'round';
  522.                         }, 100);
  523.                 });
  524.  
  525.                 $(self.canvas).on('mousedown', function(e){
  526.                         var randLaunch = rand(0, 5);
  527.                         self.mx = e.pageX - self.canvasContainer.offset().left;
  528.                         self.my = e.pageY - self.canvasContainer.offset().top;
  529.                         self.currentHue = rand(self.hueMin, self.hueMax);
  530.                         self.createFireworks(self.cw/2, self.ch, self.mx, self.my);    
  531.  
  532.                         $(self.canvas).on('mousemove.fireworks', function(e){
  533.                                 var randLaunch = rand(0, 5);
  534.                                 self.mx = e.pageX - self.canvasContainer.offset().left;
  535.                                 self.my = e.pageY - self.canvasContainer.offset().top;
  536.                                 self.currentHue = rand(self.hueMin, self.hueMax);
  537.                                 self.createFireworks(self.cw/2, self.ch, self.mx, self.my);                                                                    
  538.                         });    
  539.  
  540.                 });
  541.  
  542.                 $(self.canvas).on('mouseup', function(e){
  543.                         $(self.canvas).off('mousemove.fireworks');                                                                     
  544.                 });
  545.  
  546.         }
  547.  
  548.         /*=============================================================================*/      
  549.         /* Clear Canvas
  550.         /*=============================================================================*/
  551.         self.clear = function(){
  552.                 self.particles = [];
  553.                 self.fireworks = [];
  554.                 self.ctx.clearRect(0, 0, self.cw, self.ch);
  555.         };
  556.  
  557.         /*=============================================================================*/      
  558.         /* Main Loop
  559.         /*=============================================================================*/
  560.         self.canvasLoop = function(){
  561.                 requestAnimFrame(self.canvasLoop, self.canvas);                
  562.                 self.ctx.globalCompositeOperation = 'destination-out';
  563.                 self.ctx.fillStyle = 'rgba(0,0,0,'+self.clearAlpha/100+')';
  564.                 self.ctx.fillRect(0,0,self.cw,self.ch);
  565.                 self.ctx.globalCompositeOperation = 'lighter';
  566.                 self.updateFireworks();
  567.                 self.updateParticles();
  568.                 self.drawFireworks();                  
  569.                 self.drawParticles();                  
  570.         };
  571.  
  572.         self.init();
  573.  
  574.   var initialLaunchCount = 10;
  575.   while(initialLaunchCount--){
  576.     setTimeout(function(){
  577.                 self.fireworks.push(new Firework(self.cw/2, self.ch, rand(50, self.cw-50), rand(50, self.ch/2)-50));
  578.     }, initialLaunchCount*200);
  579.   }
  580.  
  581. }
  582.  
  583. /*=============================================================================*/      
  584. /* GUI
  585. /*=============================================================================*/      
  586. var guiPresets = {
  587.                           "preset": "Default",
  588.                           "remembered": {
  589.                                 "Default": {
  590.                                   "0": {
  591.                                         "fworkSpeed": 2,
  592.                                         "fworkAccel": 4,
  593.                                         "showShockwave": false,
  594.                                         "showTarget": true,
  595.                                         "partCount": 30,
  596.                                         "partSpeed": 5,
  597.                                         "partSpeedVariance": 10,
  598.                                         "partWind": 50,
  599.                                         "partFriction": 5,
  600.                                         "partGravity": 1,
  601.                                         "flickerDensity": 20,
  602.                                         "hueMin": 150,
  603.                                         "hueMax": 200,
  604.                                         "hueVariance": 30,
  605.                                         "lineWidth": 1,
  606.                                         "clearAlpha": 25
  607.                                   }
  608.                                 },
  609.                                 "Anti Gravity": {
  610.                                   "0": {
  611.                                         "fworkSpeed": 4,
  612.                                         "fworkAccel": 10,
  613.                                         "showShockwave": true,
  614.                                         "showTarget": false,
  615.                                         "partCount": 150,
  616.                                         "partSpeed": 5,
  617.                                         "partSpeedVariance": 10,
  618.                                         "partWind": 10,
  619.                                         "partFriction": 10,
  620.                                         "partGravity": -10,
  621.                                         "flickerDensity": 30,
  622.                                         "hueMin": 0,
  623.                                         "hueMax": 360,
  624.                                         "hueVariance": 30,
  625.                                         "lineWidth": 1,
  626.                                         "clearAlpha": 50
  627.                                   }
  628.                                 },
  629.                                 "Battle Field": {
  630.                                   "0": {
  631.                                         "fworkSpeed": 10,
  632.                                         "fworkAccel": 20,
  633.                                         "showShockwave": true,
  634.                                         "showTarget": true,
  635.                                         "partCount": 200,
  636.                                         "partSpeed": 30,
  637.                                         "partSpeedVariance": 5,
  638.                                         "partWind": 0,
  639.                                         "partFriction": 5,
  640.                                         "partGravity": 0,
  641.                                         "flickerDensity": 0,
  642.                                         "hueMin": 20,
  643.                                         "hueMax": 30,
  644.                                         "hueVariance": 10,
  645.                                         "lineWidth": 1,
  646.                                         "clearAlpha": 40
  647.                                   }
  648.                                 },
  649.                                 "Mega Blast": {
  650.                                   "0": {
  651.                                         "fworkSpeed": 3,
  652.                                         "fworkAccel": 3,
  653.                                         "showShockwave": true,
  654.                                         "showTarget": true,
  655.                                         "partCount": 500,
  656.                                         "partSpeed": 50,
  657.                                         "partSpeedVariance": 5,
  658.                                         "partWind": 0,
  659.                                         "partFriction": 0,
  660.                                         "partGravity": 0,
  661.                                         "flickerDensity": 0,
  662.                                         "hueMin": 0,
  663.                                         "hueMax": 360,
  664.                                         "hueVariance": 30,
  665.                                         "lineWidth": 20,
  666.                                         "clearAlpha": 20
  667.                                   }
  668.                                 },
  669.                                 "Nimble": {
  670.                                   "0": {
  671.                                         "fworkSpeed": 10,
  672.                                         "fworkAccel": 50,
  673.                                         "showShockwave": false,
  674.                                         "showTarget": false,
  675.                                         "partCount": 120,
  676.                                         "partSpeed": 10,
  677.                                         "partSpeedVariance": 10,
  678.                                         "partWind": 100,
  679.                                         "partFriction": 50,
  680.                                         "partGravity": 0,
  681.                                         "flickerDensity": 20,
  682.                                         "hueMin": 0,
  683.                                         "hueMax": 360,
  684.                                         "hueVariance": 30,
  685.                                         "lineWidth": 1,
  686.                                         "clearAlpha": 80
  687.                                   }
  688.                                 },
  689.                                 "Slow Launch": {
  690.                                   "0": {
  691.                                         "fworkSpeed": 2,
  692.                                         "fworkAccel": 2,
  693.                                         "showShockwave": false,
  694.                                         "showTarget": false,
  695.                                         "partCount": 200,
  696.                                         "partSpeed": 10,
  697.                                         "partSpeedVariance": 0,
  698.                                         "partWind": 100,
  699.                                         "partFriction": 0,
  700.                                         "partGravity": 2,
  701.                                         "flickerDensity": 50,
  702.                                         "hueMin": 0,
  703.                                         "hueMax": 360,
  704.                                         "hueVariance": 20,
  705.                                         "lineWidth": 4,
  706.                                         "clearAlpha": 10
  707.                                   }
  708.                                 },
  709.                                 "Perma Trail": {
  710.                                   "0": {
  711.                                         "fworkSpeed": 4,
  712.                                         "fworkAccel": 10,
  713.                                         "showShockwave": false,
  714.                                         "showTarget": false,
  715.                                         "partCount": 150,
  716.                                         "partSpeed": 10,
  717.                                         "partSpeedVariance": 10,
  718.                                         "partWind": 100,
  719.                                         "partFriction": 3,
  720.                                         "partGravity": 0,
  721.                                         "flickerDensity": 0,
  722.                                         "hueMin": 0,
  723.                                         "hueMax": 360,
  724.                                         "hueVariance": 20,
  725.                                         "lineWidth": 1,
  726.                                         "clearAlpha": 0
  727.                                   }
  728.                                 }
  729.                           },
  730.                           "closed": true,
  731.                           "folders": {
  732.                                 "Fireworks": {
  733.                                   "preset": "Default",
  734.                                   "closed": false,
  735.                                   "folders": {}
  736.                                 },
  737.                                 "Particles": {
  738.                                   "preset": "Default",
  739.                                   "closed": true,
  740.                                   "folders": {}
  741.                                 },
  742.                                 "Color": {
  743.                                   "preset": "Default",
  744.                                   "closed": true,
  745.                                   "folders": {}
  746.                                 },
  747.                                 "Other": {
  748.                                   "preset": "Default",
  749.                                   "closed": true,
  750.                                   "folders": {}
  751.                                 }
  752.                           }
  753.                         };
  754.  
  755. var fworks = new Fireworks();
  756. var gui = new dat.GUI({
  757.         autoPlace: false,
  758.         load: guiPresets,
  759.         preset: 'Default'
  760. });
  761. var customContainer = document.getElementById('gui');
  762. customContainer.appendChild(gui.domElement);
  763.  
  764. var guiFireworks = gui.addFolder('Fireworks');
  765. guiFireworks.add(fworks, 'fworkSpeed').min(1).max(10).step(1);
  766. guiFireworks.add(fworks, 'fworkAccel').min(0).max(50).step(1);
  767. guiFireworks.add(fworks, 'showShockwave');
  768. guiFireworks.add(fworks, 'showTarget');
  769.  
  770. var guiParticles = gui.addFolder('Particles');
  771. guiParticles.add(fworks, 'partCount').min(0).max(500).step(1); 
  772. guiParticles.add(fworks, 'partSpeed').min(1).max(100).step(1);
  773. guiParticles.add(fworks, 'partSpeedVariance').min(0).max(50).step(1);
  774. guiParticles.add(fworks, 'partWind').min(0).max(100).step(1);
  775. guiParticles.add(fworks, 'partFriction').min(0).max(50).step(1);
  776. guiParticles.add(fworks, 'partGravity').min(-20).max(20).step(1);
  777. guiParticles.add(fworks, 'flickerDensity').min(0).max(50).step(1);
  778.  
  779. var guiColor = gui.addFolder('Color');
  780. guiColor.add(fworks, 'hueMin').min(0).max(360).step(1);
  781. guiColor.add(fworks, 'hueMax').min(0).max(360).step(1);
  782. guiColor.add(fworks, 'hueVariance').min(0).max(180).step(1);
  783.  
  784. var guiOther = gui.addFolder('Other');
  785. guiOther.add(fworks, 'lineWidth').min(1).max(20).step(1);
  786. guiOther.add(fworks, 'clearAlpha').min(0).max(100).step(1);
  787. guiOther.add(fworks, 'clear').name('Clear');
  788.  
  789. gui.remember(fworks);
  790.  
  791. })();
  792.   </script>
  793.  
  794.   <div id="codepen-footer">
  795.  
  796.     <a style="color: #f73535 !important;" href="https://codepen.wufoo.com/forms/m7x3r3/def/field14=" target="_blank">Report Abuse</a>
  797.  
  798.     &nbsp;
  799.  
  800.     <a href="/jackrugile/pen/acAgx" target="_blank">Edit this Pen</a>
  801.   </div>
  802.  
  803. </body>
  804.  
  805. </html>