/** * Created by Tony O'Rourke on 3/11/2017. */ (function () { var RISE_END = 218, SVGNS= "http://www.w3.org/2000/svg", CENTER_X_AXIS = 320, //ASSEMBLY_DURATION = .2, SPEED_DIVISOR = 1, ASSEMBLY_DURATION = 2 / SPEED_DIVISOR, chakras =[ {name: 'mooladhara', endY: 790, color: 'orange', triggered: false, scale:1, qualities: ['Wisdom', 'Innocence'], gradient1: '#ff9b08', gradient2: '#d68505'}, {name: 'swadistan', endY: 720, color: 'yellow', triggered: false, scale:1.1, qualities: ['Creativity', 'Pure Knowledge'], gradient1: '#fffe8d', gradient2: '#ffff00'}, {name: 'nabhi', endY: 655, color: 'green', triggered: false, scale:1.2, qualities: ['Evolution', 'Satisfaction', 'Dignity'], gradient1: '#00ff00', gradient2: '#005d00'}, {name: 'void', endY: 590, color: '#aad7a2', triggered: false, scale:1.0, qualities: ['Self-Mastery', 'Balance'], gradient1: '#00ff00', gradient2: '#005d00'}, {name: 'anahat', endY: 525, color: 'red', triggered: false, scale:1.2, qualities: ['Responsibility', 'The Spirit'], gradient1: '#ff443f', gradient2: '#9f0000'}, {name: 'vishuddhi', endY: 425, color: 'cyan', triggered: false, scale:1.2, qualities: ['Collectivity', 'Self-Esteem','Diplomacy'], gradient1: '#01b2ff', gradient2: '#01638b'}, {name: 'agnya', endY: 295, color: 'gray', triggered: false, scale:1, qualities: [ 'Forgiveness', 'Humility','Forgiveness'], gradient1: '#aaaaaa', gradient2: '#818181'}, {name: 'sahasrara', endY: RISE_END, color: 'white', triggered: false, scale:1, qualities: ['Thoughtless Awareness']} ], ego, egoNormalPath, egoBalloonPath, egoSmallPath, superego, superEgoNormalPath, superEgoBalloonPath, superEgoSmallPath, snap, EGO_STEP_DURATION_MS = 1000 / SPEED_DIVISOR, EGO_STEP_DURATION_SECONDS = 1 / SPEED_DIVISOR, EGO_BATTLE_DELAY_SECONDS = 1/ SPEED_DIVISOR, egoMessages = ['Bloated Ego', 'Anxiety', 'Over Activity', 'Lack of Focus'], superEgoMessages = ['Bloated SuperEgo', 'Destructive Habits', 'Conditionings', 'Depression'], messageLocations = {'l': {x: 230, y:225}, 'r': {x: 420, y:225}, 'c' : {x: 320, y: 70}}, KUNDALINI_WIDTH = 9, KUNDALINI_RISE_DURATION = 3 / SPEED_DIVISOR, //KUNDALINI_RISE_DURATION = .5, KUNDALINI_RISE_START = 739.5, KUNDALINI_HEIGHT = 500, kundaliniRisingAnimation, lastKundaliniHeight, CHAKRA_OPEN_DURATION = 1, CHAKRA_TRANSFORM_DURATION = 6000 / SPEED_DIVISOR, SR_1 = "Mother, please give me my Self-Realization!", SR_2 = "Shri Mataji, please give me my Self-Realization!", PRE_REALIZATION_MESSAGE = 'State of Imbalance before Self-Realization', PRE_REALIZATION_MESSAGE_2 = 'Oscillation between ego and superego', RADAR_COUNT = 7, RADAR_COUNT_TRIGGER = 0, RADAR_EXPAND_DURATION = 10, RADAR_EXPAND_INTERVAL_FACTOR = .4, RADAR_START_RADIUS = 90, KUNDALINI_CHANGE_COLOR_DELAY = 4, KUNDALINI_CHANGE_COLOR_DURATION = 3, //START_AWAKENING_DELAY_MS = 7, START_AWAKENING_DELAY_MS = 7000 / SPEED_DIVISOR, radarArray = [], selfRealizationText, SINGLE_LETTER_WRITE_DURATION = .25, IMAGE_TO = { x: 390, y: 80}, RADAR_CENTER = {x: 535, y: 192}, documentHeight, svgHeight, SVG_SIZE_ORIG = {WIDTH: 640, HEIGHT: 800}, svgScaleY, starsCompleted = 0, beforeRealizationText, bGarlandAtEnd = true, egoEase = mina.bounce, CHAKRA_STAR_TRANSFORM = true, svg //raw svg node ,tonyText ; function onRising(tween) { //console.log('rising', tween); var element = tween.target, delta = 0, height = element.height().toFixed(0); if (lastKundaliniHeight) { delta = height - lastKundaliniHeight; } var activated = triggeredActivation(height, delta); if (activated) { // if (activated == 5) { // tween.pause(); // } if (chakras[activated].starShape) { var circleShape = snap.select('g#chakra-prestar-' + activated + ' path'); TweenLite.set(circleShape, { attr: { fill: chakras[activated].color}}) $( circleShape.node.parentElement).addClass('enlightened'); if (chakras[activated].gradient1 && chakras[activated].gradient2) { var gradientString = "r(0.5, 0.5, 0.5)" + chakras[activated].gradient1 + "-" + chakras[activated].gradient2; var g = snap.gradient(gradientString); circleShape.attr({fill:g}); } circleShape.animate({ d: chakras[activated].starShape, rotation: 45, transform:'s' + chakras[activated].scale} ,CHAKRA_TRANSFORM_DURATION , mina.elastic, chakraDone); } else { var pattern = 'circle#chakra-' + chakras[activated].name; console.log('pattern', pattern) if (chakras[activated].name == 'void') { pattern = 'g#chakra-' + chakras[activated].name + ' circle'; TweenLite.to(pattern, CHAKRA_OPEN_DURATION, {fill: chakras[activated].color }); } else { TweenLite.set(pattern, {stroke: 'none'}); TweenLite.to(pattern, CHAKRA_OPEN_DURATION, {fill: chakras[activated].color , attr: {r: 15}}); } // console.log('trying', pattern); } // kundaliniRisingAnimation.pause(); } lastKundaliniHeight = height; } function chakraDone() { //console.log('chakra.done', starsCompleted); qualityText = snap.text(320, chakras[starsCompleted].endY - 24, chakras[starsCompleted].qualities[0]); TweenLite.set(qualityText.node, {opacity: 0}); qualityText.addClass('quality').addClass(chakras[starsCompleted].name); //sahasra text gets pulled to left just a little bit more TweenLite.to(qualityText.node, 1, {x: starsCompleted == 7 ? -320 : -180, opacity:1, ease: Bounce.easeOut}); qualityText = snap.text(320, chakras[starsCompleted].endY - 24, chakras[starsCompleted].qualities[1]); TweenLite.set(qualityText.node, {opacity: 0}); qualityText.addClass('quality').addClass(chakras[starsCompleted].name); TweenLite.to(qualityText.node, 1, {x: 60, opacity:1, ease: Bounce.easeOut}); starsCompleted++; } function triggeredActivation(height, delta) { for(var i = 0; i < chakras.length; i++) { if (!chakras[i].triggered) { // console.log('checking height[' + i + ']', height, KUNDALINI_RISE_START - chakras[i].endY); //trigger points based on full size svg, so need to multiply by svgScaleY if image is smaller if (height > (KUNDALINI_RISE_START - chakras[i].endY) * svgScaleY) { chakras[i].triggered = true; // console.log('triggering height[' + i + ']', height, KUNDALINI_RISE_START - chakras[i].endY); return i; } } } } function askForSelfRealization() { // console.log('Asking for Self-Realization ...'); // beforeRealizationText.remove(); //text comes from level of heart selfRealizationText = snap.text(messageLocations['c'].x, chakras[4].endY, SR_2); selfRealizationText.addClass('message').attr('id', 'self_realization_request' ).attr('text-anchor', 'middle') TweenLite.to( selfRealizationText.node, 1, {y: messageLocations['c'].y - chakras[4].endY, onComplete: showRadar, ease: Linear.Power1 }); } function drawGarland() { // console.log('drawGarland'); var numDaisies = 24, g = snap.g().attr('id', 'daisy-g'), baseX = 518, baseY = 72, // baseX = 300, // baseY = 150, radius = 91, circlePath = [ {x:radius + baseX, y: radius + baseY}, {x: baseX, y: radius * 2 + baseY}, {x: baseX - radius, y:radius + baseY}, {x:baseX, y: baseY}, {x:radius + baseX, y: radius + baseY} ], duration = 2, //duration (in seconds) tl; Snap.load( "/img/sahaja/subtle/daisy.svg", function(fragment) { g.append(fragment.node).addClass('daisy-garland'); snap.append(g); TweenLite.set("g#daisy-g", { x: baseX, y:baseY , css: {scale: .65}}); var daisy = snap.select('g#daisy-g'), i, path = circlePath, //points on the path (BezierPlugin will plot a Bezier through these). Adjust however you please. position = {x:path[0].x, y:path[0].y}; //tracks the current position, so we set it initially to the first node in the path. It's the target of the tween. //we can remove the first point on the path because the position is already there and we want to draw the Bezier from there through the other points path.shift(); tween = TweenLite.to(position, numDaisies, { bezier: { values:path, curviness:1.5, autoRotate:true }, ease:Linear.easeNone });//this does all the work of figuring out the positions over time. tl = new TimelineMax({repeat:0}); for (i = 0; i <= numDaisies; i++) { tween.time(i); //jumps to the appropriate time in the tween, causing position.x and position.y to be updated accordingly. var flower = daisy.clone(); flower.addClass('daisy-garland').attr('id', 'daisy-' + i); TweenLite.set(flower.node, {x: position.x, y: position.y}); tl.set(flower.node, {visibility:"visible"}, i * (duration / numDaisies)); //toggle the visibility on at the appropriate time. } }); } function showRadar() { for(var i = 0; i < RADAR_COUNT; i++) { // RADAR_CENTER var circle = snap.circle(RADAR_CENTER.x, RADAR_CENTER.y, 0 ).addClass('emanating'); circle.attr({ fill:'none', strokeWidth:0, strokeOpacity: .6}); radarArray.push(circle); TweenLite.fromTo( radarArray[i].node, RADAR_EXPAND_DURATION, {attr: {r: RADAR_START_RADIUS, strokeOpacity: 1, stroke: '#F00'}}, { delay: RADAR_EXPAND_INTERVAL_FACTOR * i, attr: {r: 800, strokeOpacity: 1 }, // css: {'strokeWidth': 2}, onStart:onRadarStart, onStartParams:[i], onComplete: radarComplete, onCompleteParams:[i], ease: Linear.Power0 } ); } TweenLite.to('g#kundalini path', KUNDALINI_CHANGE_COLOR_DURATION, {delay: KUNDALINI_CHANGE_COLOR_DELAY, attr:{ stroke: '#F00'}}); window.setTimeout(startAwakening, START_AWAKENING_DELAY_MS); } function onRadarStart(i) { var node = radarArray[i].node; // console.log('onRadarStart',i, node); TweenLite.set(node,{css: {'strokeWidth': 2}} ); } function radarComplete(i) { //console.log('radarComplete', i); //TweenLite.set('g#kundalini path').attr{stroke: ''}; radarArray[i].remove(); if (i == RADAR_COUNT_TRIGGER) { // startAwakening(); } } function loadMothersImage() { return; var image = snap.image("/img/sahaja/subtle/shri-mataji-face.jpg", 388, 88, 310, 213); var circleMask = snap.circle(538, 178, 0 ); circleMask.attr({'fill': '#fff', 'id':'mask1'}); image.attr({mask: circleMask}); TweenLite.to(circleMask.node, 1, {attr: {r: 84}, onComplete: askForSelfRealization, ease: Linear.easeOut }); // console.log('node', image.node, Linear.easeInOut); } function getMothersImageTimeline() { var tl = new TimelineMax({onComplete: mothersImageComplete}); var image = snap.image("/img/sahaja/subtle/shri-mataji-face.jpg", 388, 88, 310, 213); var circleMask = snap.circle(538, 178, 0 ); circleMask.attr({'fill': '#fff', 'id':'mask1'}); image.attr({mask: circleMask}); var text = makeText(320, -100, 'What is the solution?', {'class': 'message', 'id':'whatIsToBeDoneMessage', 'text-anchor':'middle'}); svg = document.getElementById('drawing'); svg.append(text); // tl.to('text#whattodomessage',.5, {y: messageLocations['c'].y}) tl.to('text#whatIsToBeDoneMessage',.5, {y: 200}) .add('whattodo') .to('text#whatIsToBeDoneMessage', .5, {x: -640}, "whattodo+=2") .add('postwhattodo') .to(circleMask.node, 1, {attr: {r: 84}, onComplete: askForSelfRealization, ease: Linear.easeOut }, 'postwhattodo'); return tl; } function mothersImageComplete() { var text = Snap.select('text#whatIsToBeDoneMessage'); if(text) { text.remove(); } } function startAwakening() { // selfRealizationText.remove(); TweenLite.set('g#kundalini-rise rect', {scaleY: -1, width: KUNDALINI_WIDTH}); //activate mooladhara var circleShape = snap.select('g#chakra-prestar-0 path'); $( circleShape.node.parentElement).addClass('enlightened'); TweenLite.to('g#kundalini-rise rect', KUNDALINI_RISE_DURATION, { delay: 1, attr: {height: KUNDALINI_HEIGHT}, onUpdate:onRising, onUpdateParams:["{self}"], onComplete: onKundaliniRiseComplete, ease:Linear.Power0 } ); var gradientString = "r(0.5, 0.5, 0.5)" + chakras[0].gradient1 + "-" + chakras[0].gradient2; TweenLite.set(circleShape, { attr: { fill: gradientString }}); circleShape.animate({d: chakras[0].starShape, rotation: 45},CHAKRA_TRANSFORM_DURATION, mina.elastic, chakraDone); } function onKundaliniRiseComplete() { // console.log('rising complete'); //remove asking text var text = snap.select('text#self_realization_request'); var removed = text.remove(); var circle = makeCircle(CENTER_X_AXIS, chakras[7].endY, 7, 'chakra-' + chakras[7].name); $('#drawing').append(circle); var sahasrara = $("g#chakra-sahasrara"); var e = sahasrara[0]; TweenLite.set(e, {opacity:0}); sahasrara.removeClass('hidden'); TweenLite.to(e, 3, {opacity: 1, onComplete:onSahasraraLoaded, ease:Linear.Power0}) } function onSahasraraLoaded() { chakraDone(); //undo red color of central channel TweenLite.to('g#kundalini-rise rect', 3, { attr: { fill: 'none' }}); setInterval(swapFlames, 500); setTimeout(drawLogoText, 3500); } function swapFlames() { var flames = $('g#chakra-sahasrara path'); flames.each(function(i) { var rnd = Math.random(); if (rnd < .5) { rnd = 1 - rnd; } var flame = flames[i]; TweenLite.to(flame, .5, {opacity: rnd}); }); } function makeCircle(cx, cy, r, id) { var shape = document.createElementNS(SVGNS, "circle"); shape.setAttributeNS(null, "cx", cx); shape.setAttributeNS(null, "cy", cy); shape.setAttributeNS(null, "r", r); shape.setAttributeNS(null, "id", id); shape.setAttributeNS(null, "class", 'chakra'); return shape; } function makeText(x, y, text, attributes) { var shape = document.createElementNS(SVGNS, "text"); shape.setAttributeNS(null, "x", x); shape.setAttributeNS(null, "y", y); // console.log('ta', typeof attr); if (attributes && typeof attributes === 'object') { for (var prop in attributes) { //console.log(prop) if (attributes.hasOwnProperty(prop)) { shape.setAttributeNS(null, prop, attributes[prop]); } } } var textNode = document.createTextNode(text); shape.appendChild(textNode); return shape; } var calcAssemblyDurations = function(index) { var totalDistance = chakras[0].endY - chakras[6].endY; var thisDistance = chakras[0].endY - chakras[index].endY; var duration = thisDistance / totalDistance * ASSEMBLY_DURATION; //console.log('d', index, thisDistance, distance, duration); return duration; }; //not using this anymore since tweening chakras to stars function makeCircles(timeLine) { for(var i = 6; i <7; i++) { var circle = makeCircle(CENTER_X_AXIS, chakras[0].endY, 7, 'chakra-' + chakras[i].name); $('#drawing').append(circle); var newY = (chakras[0].endY - chakras[i].endY) * -1; TweenLite.to('circle#chakra-' + chakras[i].name, calcAssemblyDurations(i), {x:0, y: newY}) } } function drawLogoText() { var logoSet = snap.selectAll('g#logo-text g path'); //console.log('logo', logoSet); var logoTimeline = new TimelineMax({onComplete: logoTimelineComplete }); logoSet.forEach(function(e) { var length = e.node.getTotalLength(); TweenLite.set(e.node, {x:-635, y:-50, stroke: '#aaa', "stroke-dasharray": length + ' ' + length, "stroke-dashoffset": length}); logoTimeline.add( TweenLite.to( e.node, SINGLE_LETTER_WRITE_DURATION, {"stroke-dashoffset":0}) ); }); logoTimeline.play(); } function logoTimelineComplete() { drawGarland(); } function battleComplete() { // var text = snap.select('text#beforeRealizationText'); // if (text) { // text.remove(); // } var msg = Snap.select('text#superEgoMessage'); if (msg) { msg.remove(); } // // console.log('battleComplete', x, removed); loadMothersImage(); } function getBattleTimeline() { var el = {}; el.x = 0;//dummy element to tween var battleTimeline = new TimelineMax({repeat:3, onComplete: battleComplete}); battleTimeline .to( el, EGO_STEP_DURATION_SECONDS, {x:100, onStart: startA, onStartParams:[battleTimeline] }) .to( el, EGO_STEP_DURATION_SECONDS, {x:200, delay: EGO_BATTLE_DELAY_SECONDS, onStart: startB}) .to( el, EGO_STEP_DURATION_SECONDS, {x:300, onStart: startC, onStartParams:[battleTimeline] }) .to( el, EGO_STEP_DURATION_SECONDS, {x:400, delay: EGO_BATTLE_DELAY_SECONDS, onStart: startD}); return battleTimeline; } function getBattleIntroTimeline() { console.log('startBattle'); var introMessage = makeText(320, -100, PRE_REALIZATION_MESSAGE, { id: 'beforeRealizationText', 'text-anchor':'middle', class: 'message' }); svg = document.getElementById('drawing'); svg.append(introMessage); var introMessage2 = makeText(320, -100, PRE_REALIZATION_MESSAGE_2, { id: 'beforeRealizationText2', 'text-anchor':'middle', class: 'message' }); svg.append(introMessage2); var introTimeLine = new TimelineMax(); introTimeLine .to( 'text#beforeRealizationText', .5, {y: "200", ease: Bounce.easeOut} ) .to( 'text#beforeRealizationText', .5, {x: "-620", ease: Bounce.easeOut, onComplete:removeIntroText1, delay: 2}) .add('after1') .to( 'text#beforeRealizationText2', .5, {y: "200", ease: Bounce.easeOut}, "after1-=.25") .to( 'text#beforeRealizationText2', .5, {x: "-620", ease: Bounce.easeOut, onComplete:removeIntroText2, delay: 2} ); // introTimeLine.pause(); return introTimeLine; // beforeRealizationText = snap.text(messageLocations['c'].x, messageLocations['c'].y, PRE_REALIZATION_MESSAGE); // beforeRealizationText.addClass('message').attr('id', 'beforeRealizationText').attr('text-anchor', 'middle'); } function removeIntroText1() { console.log('removeIntroText1') var text = Snap.select('text#beforeRealizationText'); if (text) { text.remove(); } } function removeIntroText2() { console.log('removeIntroText2') var text = Snap.select('text#beforeRealizationText2'); if (text) { text.remove(); } } function startA(tl) { //console.log('startA'); var text = Snap.select('text#superEgoMessage'); if (text) { text.remove(); } var index = tl._cycle; ego.animate({ d: egoBalloonPath}, EGO_STEP_DURATION_MS, egoEase) superego.animate({ d: superEgoSmallPath}, EGO_STEP_DURATION_MS, egoEase) if (egoMessages[index]) { var egoText = makeText(messageLocations['r'].x - 100, messageLocations['r'].y, egoMessages[index], {id:'egoMessage', 'text-anchor':'start', 'class':'message'}); svg = document.getElementById('drawing'); svg.append(egoText); TweenLite.to('text#egoMessage', .5, {x: "100", ease: Bounce.easeOut}); } } function startB() { // console.log('startB'); ego.animate({ d: egoNormalPath}, EGO_STEP_DURATION_MS, mina.linear); superego.animate({ d: superEgoNormalPath}, EGO_STEP_DURATION_MS, mina.linear); } function startC(tl) { var text = Snap.select('text#egoMessage'); if (text) { text.remove(); } superego.animate({ d: superEgoBalloonPath}, EGO_STEP_DURATION_MS, egoEase); ego.animate({ d: egoSmallPath}, EGO_STEP_DURATION_MS, egoEase); var index = tl._cycle; if (superEgoMessages[index]) { var egoText = makeText(messageLocations['l'].x+100, messageLocations['l'].y, superEgoMessages[index], {id:'superEgoMessage', 'text-anchor':'end', 'class':'message'}); svg = document.getElementById('drawing'); svg.append(egoText); TweenLite.to('text#superEgoMessage', .5, {x: "-100", ease: Bounce.easeOut}); } // console.log('startC'); } function startD() { // console.log('startD'); ego.animate({ d: egoNormalPath}, EGO_STEP_DURATION_MS, mina.linear); superego.animate({ d: superEgoNormalPath}, EGO_STEP_DURATION_MS, mina.linear); } $(function() { documentHeight = $(document).height(); svgHeight = documentHeight - 30; svgScaleY = svgHeight / SVG_SIZE_ORIG.HEIGHT; $("#container").load("/img/sahaja/subtle/sprite.svg", function() { var svg = $(this).find('svg'); svg.attr('id', 'drawing') //remove svg hardcoded width, set height to document height svg.removeAttr('width'); svg.attr('height', svgHeight); $('#chakra-sahasrara').addClass('hidden'); $('g#daisy').addClass('hidden'); var kundalini = $('#kundalini'); TweenLite.set('g#kundalini-rise rect', {attr:{height: 1}}); snap = Snap("svg#drawing"); ego = snap.select('g#ego path'); superego = snap.select('g#superego path'); egoNormalPath = snap.select('g#ego path').node.attributes.d.value; egoSmallPath = snap.select('g#ego-small path').node.attributes.d.value; egoBalloonPath = snap.select('g#ego-balloon path').node.attributes.d.value; superEgoNormalPath = snap.select('g#superego path').node.attributes.d.value; superEgoBalloonPath = snap.select('g#superego-balloon path').node.attributes.d.value; superEgoSmallPath = snap.select('g#superego-small path').node.attributes.d.value; if (CHAKRA_STAR_TRANSFORM) { for(var i = 0; i < 7; i++) { var starPath = snap.select('g#chakra-star-' + i + ' path'); // console.log('sp', starPath); if (starPath) { chakras[i].starShape = starPath.node.attributes.d.value; } else { chakras[i].starShape = false; } // var starShape = snap.select('g#chakra-star-' + i + ' path').node.attributes.d.value; // var starShape = snap.select('g#chakra-star-' + i + ' path').node.attributes.d.value; //chakras[i].starShape = starShape; } } // loadMothersImage(); var master = new TimelineMax(), startBattleTimeline = getBattleIntroTimeline(), battleTimeline = getBattleTimeline(), mothersImageTimeline = getMothersImageTimeline(); if (true) { master.add( TweenLite.fromTo( '#kundalini', ASSEMBLY_DURATION, {x:0, y:-720, opacity:0.5}, {x:0, y:0, opacity:1}) ); master.addLabel("afterKundalini"); master.add( startBattleTimeline, "afterKundalini" ) master.addLabel("afterIntroMessage"); master.add(battleTimeline, "afterIntroMessage"); } master.addLabel("mothersImage"); master.add(mothersImageTimeline); // makeCircles(assembly); //assembly.play(); if (!bGarlandAtEnd) { drawGarland(); } //timeline.pause(); master.play(); // imbalanceBattle() //s timeline.play(); // drawLogoText() // $('#drawing').append(textNode); // $('#container').append(textNode); }); $( window ).resize(function() { var h = $(document).height(), w = h * 640 / 800; // console.log('resize', w, h); // $('svg#drawing').attr('height', h); //$('svg#drawing').attr('width',w); }); }); })();