Advertisement
Guest User

Untitled

a guest
Aug 4th, 2012
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function drawTriangles(opacities) {
  2.     var stage = new Kinetic.Stage({
  3.             container: "triangles",
  4.             width: 960,
  5.             height: 395
  6.         }),
  7.         datacolors = $j('.slide.current').data('colors'),
  8.         colors = datacolors.split(',');
  9.        
  10.     var layer = new Kinetic.Layer(),
  11.         opacities = [0, 0, 0, 0, 0, 0, 0, 1.0, .8, .5, .2, .1],
  12.         movement = [
  13.             {x: 34, y: 66},
  14.             {x: -34, y: -66}
  15.         ],
  16.         coordsUp = [43, 67, 74,130, 13,130],
  17.         coordsDown = [43,130, 74,67, 13,67];
  18.    
  19.     // Make 6 Rows
  20.     for(var n = 0; n < 6; n++) {
  21.         // Vertical offset per row
  22.         var coory = n * 66,
  23.             offsetx = 0;
  24.        
  25.         // Every other row
  26.         if(n % 2) {
  27.             offsetx = -34;
  28.         }
  29.        
  30.         // Each row with 26 triangles
  31.         for(var i = 0; i < 28; i++) {
  32.             var coorx = (i * 34) + offsetx,
  33.                 coords = coordsUp,
  34.                 myopacity = opacities[Math.floor(Math.random() * opacities.length)],
  35.                 myname = '';
  36.            
  37.             if(myopacity < .6) {myname = 'tri';}
  38.            
  39.             // Every other triangle, flip it
  40.             if(i % 2) {
  41.                 coords = coordsDown;
  42.             }
  43.            
  44.             // Don't place triangles in the text zone
  45.             if(coorx < 440 && n < 4) {
  46.                 continue;
  47.             }
  48.                
  49.             if(coorx < 280 && n < 5) {
  50.                 continue;
  51.             }          
  52.  
  53.             if(coorx < 180 && n < 6) {
  54.                 continue;
  55.             }      
  56.                        
  57.             if(myopacity > .25) {
  58.                 var poly = new Kinetic.Polygon({
  59.                     x: coorx,
  60.                     y: coory,
  61.                     points: coords,
  62.                     alpha: 0,
  63.                     fill: colors[Math.floor(Math.random() * colors.length)],
  64.                     name: myname
  65.                 });        
  66.  
  67.                 // add the shape to the layer
  68.                 layer.add(poly);
  69.             }
  70.         }
  71.     }
  72.     stage.add(layer);
  73.    
  74.     return layer;
  75. }
  76.  
  77. function fadeShapes(layer, movementOut, opacity) {
  78.     var shapes = layer.getChildren();
  79.    
  80.     for(var n = 0; n < shapes.length; n++) {
  81.         var shape = layer.getChildren()[n];
  82.        
  83.         shape.transitionTo({
  84.             alpha: opacity,
  85.             offset: movementOut[Math.floor(Math.random() * movementOut.length)],
  86.             duration: 1.0
  87.         });                
  88.     }
  89. }
  90.  
  91. function setColor(layer) {
  92.     var shapes = layer.getChildren(),
  93.         datacolors = $j('.slide.current').data('colors'),
  94.         colors = datacolors.split(',');
  95.    
  96.     for(var n = 0; n < shapes.length; n++) {
  97.         var shape = layer.getChildren()[n];
  98.         shape.setFill(colors[Math.floor(Math.random() * colors.length)]);
  99.     }
  100. }
  101.  
  102. $j(window).load(function(){
  103.     var $slide = $j('.slide'),
  104.         $first = $slide.first(),
  105.         $items = $j('.scrollable .items'),
  106.         opacities = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, .8, .5, .2, .1],
  107.         opacity = (opacities[Math.floor(Math.random() * opacities.length)] * 1.5) + .7,
  108.         movementIn = [
  109.             {x: 34, y: 66},
  110.             {x: -34, y: -66}
  111.         ],
  112.         movementOut = [
  113.             {x: -76, y: -132},
  114.             {x: 76, y: 132}
  115.         ],
  116.         layer = drawTriangles(opacities),
  117.         $next,
  118.         nextIndex;
  119.    
  120.     fadeShapes(layer, movementIn, opacity);
  121.    
  122.     // Trans class used for slides using a transparent png… places triangles behind image
  123.     if($first.hasClass('trans')) {
  124.         $items.addClass('trans');
  125.     }
  126.    
  127.     // Change slides every 6 seconds
  128.     setInterval(function(){
  129.         var $current = $slide.filter('.current');
  130.        
  131.         $next = $current.next('.slide');
  132.            
  133.         if($next.length == 0) {$next = $first;}
  134.        
  135.         nextIndex = $next.index();
  136.    
  137.         fadeShapes(layer, movementOut, 0);
  138.        
  139.         setTimeout(function(){
  140.             $items.removeClass('trans');
  141.            
  142.             opacity = (opacities[Math.floor(Math.random() * opacities.length)] * 1.5) + .7;
  143.            
  144.             $slide.removeClass('current');
  145.             $next.addClass('current');
  146.            
  147.             setColor(layer);
  148.             fadeShapes(layer, movementIn, opacity);
  149.            
  150.             if($next.hasClass('trans')) {
  151.                 $items.addClass('trans');
  152.             }
  153.         }, 1250);
  154.     }, 5000);
  155.    
  156.    
  157.     $j('.banner').aviaSlider({
  158.         autorotationSpeed: 4.0,
  159.         animationSpeed: 1000,
  160.         betweenBlockDelay:0,
  161.         transition: 'fade',
  162.         slides:".slide",
  163.         showText: false
  164.     });
  165.    
  166. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement