Make percent to hold fixed configurable during init().
catseye
11 years ago
43 | 43 | var info; |
44 | 44 | var numBalls = 200; |
45 | 45 | var pctToHoldFixedCtrl; |
46 | var options; | |
47 | var percentToHoldFixed; | |
46 | 48 | |
47 | 49 | var t = 0; |
48 | 50 | |
49 | this.init = function(c) { | |
51 | this.init = function(c, opts) { | |
52 | options = opts || {}; | |
53 | percentToHoldFixed = options.percentToHoldFixed || 10; | |
50 | 54 | canvas = c; |
51 | 55 | ctx = canvas.getContext("2d"); |
52 | 56 | info = document.getElementById('info'); |
88 | 92 | balls[i].draw(ctx, t); |
89 | 93 | } |
90 | 94 | |
91 | var numFixed = balls.length * (pctToHoldFixedCtrl.value / 100); | |
95 | var p = percentToHoldFixed; | |
96 | if (pctToHoldFixedCtrl) { | |
97 | p = pctToHoldFixedCtrl.value; | |
98 | } | |
99 | var numFixed = balls.length * (p / 100); | |
92 | 100 | for (var i = 0; i < balls.length; i++) { |
93 | 101 | if (i < numFixed) continue; |
94 | 102 | balls[i].updateXY(balls[i].getPct(t)); |
95 | 103 | } |
96 | ||
104 | ||
97 | 105 | t += 1; |
98 | 106 | }; |
99 | 107 | }; |