25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

165 satır
4.3KB

  1. /*
  2. * ParameterGroup.js
  3. * Keynote HTML Player
  4. *
  5. * Created by Tungwei Cheng
  6. * Copyright (c) 2018-2019 Apple Inc. All rights reserved.
  7. */
  8. var KNAnimParameterGroup = Class.create({
  9. initialize: function(name) {
  10. this.parameterGroup = ParameterGroup[name];
  11. this.animationCurves = {};
  12. },
  13. doubleForKey: function(key) {
  14. var result = this.parameterGroup[key].dblValue;
  15. if (!result) {
  16. result = this.parameterGroup[key];
  17. }
  18. return result;
  19. },
  20. boolForKey: function(key) {
  21. var result = this.parameterGroup[key].dblValue;
  22. if (!result) {
  23. result = this.parameterGroup[key];
  24. }
  25. return result > 0;
  26. },
  27. doubleForAnimationCurve: function(key, percent) {
  28. var path = this.pathForAnimationCurve(key);
  29. var result = path.yValueFromXValue(percent);
  30. return result;
  31. },
  32. pathForAnimationCurve: function(key) {
  33. var bezierCurve = this.animationCurves[key];
  34. if (!bezierCurve) {
  35. var parameter = this.parameterGroup[key];
  36. bezierCurve = new CubicBezierPath(parameter.controlPoints[0], parameter.controlPoints[1]);
  37. this.animationCurves[key] = bezierCurve;
  38. }
  39. return bezierCurve;
  40. }
  41. });
  42. // Bezier Curve with Newton's method for solving
  43. var CubicBezierPath = Class.create({
  44. initialize: function(p1, p2) {
  45. var cx = this.cx = 3 * p1.x;
  46. var bx = this.bx = 3 * (p2.x - p1.x) - cx;
  47. var ax = this.ax = 1 - cx - bx;
  48. var cy = this.cy = 3 * p1.y;
  49. var by = this.by = 3 * (p2.y - p1.y) - cy;
  50. var ay = this.ay = 1 - cy - by;
  51. // loop 5 times maximum
  52. this.iteration = 5;
  53. // the tolerance accepted
  54. this.epsilon = 1e-4;
  55. },
  56. bezierCurveX: function(t) {
  57. return t * (this.cx + t * (this.bx + t * this.ax));
  58. },
  59. bezierCurveY: function(t) {
  60. return t * (this.cy + t * (this.by + t * this.ay));
  61. },
  62. bezierCurveDerivativeX: function(t) {
  63. return this.cx + t * (2 * this.bx + 3 * this.ax * t);
  64. },
  65. solveXForT: function(t) {
  66. var epsilon = this.epsilon;
  67. var x0 = t;
  68. var x1;
  69. for (var i = 0, length = this.iteration; i < length; i++) {
  70. x1 = this.bezierCurveX(x0) - t;
  71. if (Math.abs(x1) < epsilon) {
  72. break;
  73. }
  74. x0 = x0 - (x1 / this.bezierCurveDerivativeX(x0));
  75. }
  76. return x0;
  77. },
  78. yValueFromXValue: function(xValue) {
  79. return this.bezierCurveY(this.solveXForT(xValue));
  80. }
  81. });
  82. var ParameterGroup = {
  83. "Fireworks": {
  84. "FireworkSizeMax": 0.3,
  85. "FireworkDurationMax": 2,
  86. "ParticleTrailsDitherMax": 2,
  87. "SparkleStartTime": 0.5,
  88. "TextOpacityEndTime": 0.6,
  89. "ParticleTransparency": {
  90. "dblValue": 0,
  91. "controlPoints": [{"x": 1, "y": 0}, {"x": 0.718446, "y": 1}]
  92. },
  93. "TextOpacityTiming": {
  94. "dblValue": 0,
  95. "controlPoints": [{"x": 1, "y": 0}, {"x": 0.825627, "y": 1}]
  96. },
  97. "BloomBlurScale":4,
  98. "Gravity": 20,
  99. "ParticleBurstTiming": {
  100. "dblValue": 0,
  101. "controlPoints": [{"x": 0, "y": 1}, {"x": 0.551894, "y": 0.993738}]
  102. },
  103. "ParticleSizeStart": 0.5,
  104. "ParticleTrailsDitherAmount": 0.5,
  105. "CenterBurstOpacity": 1,
  106. "BloomPower": 3,
  107. "ParticleSizeMax": 0.5,
  108. "ParticleSizeMin": 3,
  109. "CenterBurstScaleMin": 0.15,
  110. "TrailsFadeOutMax": 0.1,
  111. "CenterBurstScaleMax": 0.3,
  112. "TrailsFadeOutMin": 0.03,
  113. "TextOpacityBeginTime": 0.1,
  114. "ParticleCount": 200,
  115. "SparklePeriod": 13,
  116. "ParticleColorRandomness": 0.09,
  117. "FireworkSpeedMax": 1,
  118. "FireworkDurationMin": 1,
  119. "FireworkSizeMin": 0.15,
  120. "ParticleLifeSpanMinDuration": 0.5,
  121. "FireworkSpeedMin": 0.8,
  122. "FireworksCount": 2
  123. },
  124. "timingFunction": {
  125. "EaseIn": {
  126. "controlPoints": [{"x": 0.42, "y": 0}, {"x": 1, "y": 1}]
  127. },
  128. "EaseOut": {
  129. "controlPoints": [{"x": 0, "y": 0}, {"x": 0.58, "y": 1}]
  130. },
  131. "EaseInEaseOut": {
  132. "controlPoints": [{"x": 0.42, "y": 0}, {"x": 0.58, "y": 1}]
  133. }
  134. }
  135. };