]> _ Git - Animations.git/commitdiff
wait #2593 @0.30 donuts effect
authornael <nael@cubedesigners.com>
Wed, 13 Feb 2019 12:49:44 +0000 (13:49 +0100)
committernael <nael@cubedesigners.com>
Wed, 13 Feb 2019 12:49:44 +0000 (13:49 +0100)
Circle-Animation/main.js

index e1c7c04bf007aa443a17fcc2c27c65b6207700fe..25a7d546f94c6e2d2a1210d654f51bdf1f7aefa9 100644 (file)
@@ -3,13 +3,12 @@ let paperWidth = window.innerWidth;
 
 const color = "#fff";
 const stroke = "none";
-
 let paper = Raphael('canvas', paperWidth,paperHeight);
 let paperRadius ;
 
 $(function () {
 
-    let delayValue = 2;
+    let delayValue = 0;
     // circle size
     let circleOption = 2;
 
@@ -20,7 +19,6 @@ $(function () {
         paperRadius = Math.min(paperWidth, paperHeight) /2;
     }
 
-
 // circle direction
     let circleStart = 90;
 
@@ -36,31 +34,45 @@ $(function () {
 
     updateAngle();
 
+    console.log("Le rayon est: "+paperRadius);
+
     TweenMax.to(window,5,{angle: angleEnd ,onUpdate:updateAngle, delay: delayValue });
 });
 
+// choose percent radius of the donut circle
+let donutRadius = 0.50;
+
 function updateAngle() {
     paper.clear();
-    sector(paper,paperWidth/2, paperHeight/2,paperRadius, window.angle, window.angleEnd,{fill: color,stroke: stroke});
+    sector(paper,paperWidth/2, paperHeight/2,paperRadius, donutRadius ,window.angle, window.angleEnd,{fill: color,stroke: stroke});
 }
 
 function calcHypotenuse(a, b) {
     return(Math.sqrt((a * a) + (b * b)));
-
 }
-function sector(paper,cx, cy, r, startAngle, endAngle, params) {
+function sector(paper,cx, cy, r, pct, startAngle, endAngle, params) {
     if(window.circleDirection===1){
-        var sa=startAngle;
+        let sa=startAngle;
         startAngle=endAngle;
         endAngle=sa;
     }
-
+    // init radian
     let rad= Math.PI/180;
+    // first circle (bigger)
     let x1 = cx + r * Math.cos(-startAngle * rad),
         x2 = cx + r * Math.cos(-endAngle * rad),
         y1 = cy + r * Math.sin(-startAngle * rad),
         y2 = cy + r * Math.sin(-endAngle * rad);
-    var long= +(endAngle - startAngle > 180);
 
-    return paper.path(["M", cx, cy, "L", x1, y1, "A", r, r, 0,long, 0, x2, y2, "z"]).attr(params);
-}
\ No newline at end of file
+    // second circle / donut section
+    let r1 = r * pct;
+    let
+        x3 = cx + r1 * Math.cos(-endAngle * rad),
+        y3 = cy + r1 * Math.sin(-endAngle * rad),
+        x4 = cx + r1 * Math.cos(-startAngle * rad),
+        y4 = cy + r1 * Math.sin(-startAngle * rad);
+
+    let long= +(endAngle - startAngle > 180);
+
+   return paper.path(["M", x4,y4, "L", x1,y1, "A", r,r, 0,long, 0, x2,y2, "L", x3,y3, "A", r1,r1,0, long, 1, x4,y4,"z"]).attr(params);
+}