Skip to content

Commit b45670b

Browse files
committed
burst: run method implemented
1 parent 557fff0 commit b45670b

15 files changed

Lines changed: 325 additions & 80 deletions

css/main.styl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ windowSize = 1280
8787
// position absolute
8888
// svg
8989
// hl hotpink
90-
9190
// body
9291
// height 600px
9392

dist/burst.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Burst = (function(_super) {
2121
return Burst.__super__.constructor.apply(this, arguments);
2222
}
2323

24+
Burst.prototype.skipProps = {
25+
childOptions: 1
26+
};
27+
2428
Burst.prototype.defaults = {
2529
count: 5,
2630
degree: 360,
@@ -54,7 +58,7 @@ Burst = (function(_super) {
5458
points: 3,
5559
duration: 500,
5660
delay: 0,
57-
repeat: 1,
61+
repeat: 0,
5862
yoyo: false,
5963
easing: 'Linear.None',
6064
type: 'circle',
@@ -80,24 +84,40 @@ Burst = (function(_super) {
8084
};
8185

8286
Burst.prototype.run = function(o) {
83-
var i, tr, _results;
84-
Burst.__super__.run.apply(this, arguments);
85-
i = this.transits.length;
86-
_results = [];
87-
while (i--) {
88-
tr = this.transits[i];
89-
if (this.props.randomAngle || this.props.randomRadius) {
87+
var i, key, keys, len, tr, transit, _base, _i, _len, _ref;
88+
if ((o != null) && Object.keys(o).length) {
89+
if (o.count || ((_ref = o.childOptions) != null ? _ref.count : void 0)) {
90+
this.h.warn('Sorry, count can not be changed on run');
91+
}
92+
this.extendDefaults(o);
93+
keys = Object.keys(o.childOptions || {});
94+
if ((_base = this.o).childOptions == null) {
95+
_base.childOptions = {};
96+
}
97+
for (i = _i = 0, _len = keys.length; _i < _len; i = ++_i) {
98+
key = keys[i];
99+
this.o.childOptions[key] = o.childOptions[key];
100+
}
101+
len = this.transits.length;
102+
while (len--) {
103+
transit = this.transits[len];
104+
transit.tuneNewOption(this.getOption(len), true);
105+
}
106+
this.tween.recalcDuration();
107+
}
108+
if (this.props.randomAngle || this.props.randomRadius) {
109+
len = this.transits.length;
110+
while (len--) {
111+
tr = this.transits[len];
90112
this.props.randomAngle && tr.setProp({
91113
angleShift: this.generateRandomAngle()
92114
});
93-
_results.push(this.props.randomRadius && tr.setProp({
115+
this.props.randomRadius && tr.setProp({
94116
radiusScale: this.generateRandomRadius()
95-
}));
96-
} else {
97-
_results.push(void 0);
117+
});
98118
}
99119
}
100-
return _results;
120+
return this.startTween();
101121
};
102122

103123
Burst.prototype.createBit = function() {

dist/mojs.js

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ Burst = (function(_super) {
397397
return Burst.__super__.constructor.apply(this, arguments);
398398
}
399399

400+
Burst.prototype.skipProps = {
401+
childOptions: 1
402+
};
403+
400404
Burst.prototype.defaults = {
401405
count: 5,
402406
degree: 360,
@@ -430,7 +434,7 @@ Burst = (function(_super) {
430434
points: 3,
431435
duration: 500,
432436
delay: 0,
433-
repeat: 1,
437+
repeat: 0,
434438
yoyo: false,
435439
easing: 'Linear.None',
436440
type: 'circle',
@@ -456,24 +460,40 @@ Burst = (function(_super) {
456460
};
457461

458462
Burst.prototype.run = function(o) {
459-
var i, tr, _results;
460-
Burst.__super__.run.apply(this, arguments);
461-
i = this.transits.length;
462-
_results = [];
463-
while (i--) {
464-
tr = this.transits[i];
465-
if (this.props.randomAngle || this.props.randomRadius) {
463+
var i, key, keys, len, tr, transit, _base, _i, _len, _ref;
464+
if ((o != null) && Object.keys(o).length) {
465+
if (o.count || ((_ref = o.childOptions) != null ? _ref.count : void 0)) {
466+
this.h.warn('Sorry, count can not be changed on run');
467+
}
468+
this.extendDefaults(o);
469+
keys = Object.keys(o.childOptions || {});
470+
if ((_base = this.o).childOptions == null) {
471+
_base.childOptions = {};
472+
}
473+
for (i = _i = 0, _len = keys.length; _i < _len; i = ++_i) {
474+
key = keys[i];
475+
this.o.childOptions[key] = o.childOptions[key];
476+
}
477+
len = this.transits.length;
478+
while (len--) {
479+
transit = this.transits[len];
480+
transit.tuneNewOption(this.getOption(len), true);
481+
}
482+
this.tween.recalcDuration();
483+
}
484+
if (this.props.randomAngle || this.props.randomRadius) {
485+
len = this.transits.length;
486+
while (len--) {
487+
tr = this.transits[len];
466488
this.props.randomAngle && tr.setProp({
467489
angleShift: this.generateRandomAngle()
468490
});
469-
_results.push(this.props.randomRadius && tr.setProp({
491+
this.props.randomRadius && tr.setProp({
470492
radiusScale: this.generateRandomRadius()
471-
}));
472-
} else {
473-
_results.push(void 0);
493+
});
474494
}
475495
}
476-
return _results;
496+
return this.startTween();
477497
};
478498

479499
Burst.prototype.createBit = function() {
@@ -1556,23 +1576,25 @@ Tween = require('./tween');
15561576

15571577
Transit = require('./transit');
15581578

1559-
burst = new Transit({
1579+
burst = new Burst({
15601580
type: 'polygon',
15611581
duration: 500,
15621582
count: 3,
15631583
isIt: true,
1564-
isRunLess: true,
15651584
radius: {
15661585
0: 75
15671586
},
1568-
points: 5
1587+
points: 5,
1588+
isSwirl: true,
1589+
swirlFrequency: 'rand(0,10)',
1590+
swirlSize: 'rand(0,10)'
15691591
});
15701592

15711593
document.addEventListener('click', function(e) {
15721594
return burst.run({
15731595
x: e.x,
15741596
y: e.y,
1575-
duration: 4000
1597+
duration: 1000
15761598
});
15771599
});
15781600

@@ -2156,7 +2178,7 @@ Transit = (function(_super) {
21562178
};
21572179

21582180
Transit.prototype.extendDefaults = function(o) {
2159-
var defaultsValue, delta, fromObject, isObject, key, optionsValue, _ref, _results;
2181+
var defaultsValue, delta, fromObject, isObject, key, optionsValue, _ref, _ref1, _results;
21602182
if (this.props == null) {
21612183
this.props = {};
21622184
}
@@ -2165,6 +2187,9 @@ Transit = (function(_super) {
21652187
_results = [];
21662188
for (key in fromObject) {
21672189
defaultsValue = fromObject[key];
2190+
if ((_ref = this.skipProps) != null ? _ref[key] : void 0) {
2191+
continue;
2192+
}
21682193
if (o) {
21692194
this.o[key] = defaultsValue;
21702195
optionsValue = defaultsValue;
@@ -2186,7 +2211,7 @@ Transit = (function(_super) {
21862211
if ((key === 'x' || key === 'y') && !this.o.ctx) {
21872212
this.h.warn('Consider to animate shiftX/shiftY properties instead of x/y, as it would be much more performant', optionsValue);
21882213
}
2189-
if ((_ref = this.skipPropsDelta) != null ? _ref[key] : void 0) {
2214+
if ((_ref1 = this.skipPropsDelta) != null ? _ref1[key] : void 0) {
21902215
continue;
21912216
}
21922217
delta = this.h.parseDelta(key, optionsValue);
@@ -2308,19 +2333,23 @@ Transit = (function(_super) {
23082333
};
23092334

23102335
Transit.prototype.run = function(o) {
2336+
this.tuneNewOption(o);
2337+
!this.o.isDrawLess && this.setProgress(0, true);
2338+
return this.startTween();
2339+
};
2340+
2341+
Transit.prototype.tuneNewOption = function(o, isForeign) {
23112342
if ((o != null) && (o.type != null) && o.type !== (this.o.type || this.type)) {
23122343
this.h.warn('Sorry, type can not be changed on run');
23132344
delete o.type;
23142345
}
23152346
if ((o != null) && Object.keys(o).length) {
23162347
this.extendDefaults(o);
23172348
this.resetTimeline();
2318-
this.tween.recalcDuration();
2349+
!isForeign && this.tween.recalcDuration();
23192350
this.calcSize();
2320-
this.setElStyles();
2351+
return !isForeign && this.setElStyles();
23212352
}
2322-
!this.o.isDrawLess && this.setProgress(0, true);
2323-
return this.startTween();
23242353
};
23252354

23262355
Transit.prototype.startTween = function() {

dist/mojs.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/transit.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Transit = (function(_super) {
274274
};
275275

276276
Transit.prototype.extendDefaults = function(o) {
277-
var defaultsValue, delta, fromObject, isObject, key, optionsValue, _ref, _results;
277+
var defaultsValue, delta, fromObject, isObject, key, optionsValue, _ref, _ref1, _results;
278278
if (this.props == null) {
279279
this.props = {};
280280
}
@@ -283,6 +283,9 @@ Transit = (function(_super) {
283283
_results = [];
284284
for (key in fromObject) {
285285
defaultsValue = fromObject[key];
286+
if ((_ref = this.skipProps) != null ? _ref[key] : void 0) {
287+
continue;
288+
}
286289
if (o) {
287290
this.o[key] = defaultsValue;
288291
optionsValue = defaultsValue;
@@ -304,7 +307,7 @@ Transit = (function(_super) {
304307
if ((key === 'x' || key === 'y') && !this.o.ctx) {
305308
this.h.warn('Consider to animate shiftX/shiftY properties instead of x/y, as it would be much more performant', optionsValue);
306309
}
307-
if ((_ref = this.skipPropsDelta) != null ? _ref[key] : void 0) {
310+
if ((_ref1 = this.skipPropsDelta) != null ? _ref1[key] : void 0) {
308311
continue;
309312
}
310313
delta = this.h.parseDelta(key, optionsValue);
@@ -426,19 +429,23 @@ Transit = (function(_super) {
426429
};
427430

428431
Transit.prototype.run = function(o) {
432+
this.tuneNewOption(o);
433+
!this.o.isDrawLess && this.setProgress(0, true);
434+
return this.startTween();
435+
};
436+
437+
Transit.prototype.tuneNewOption = function(o, isForeign) {
429438
if ((o != null) && (o.type != null) && o.type !== (this.o.type || this.type)) {
430439
this.h.warn('Sorry, type can not be changed on run');
431440
delete o.type;
432441
}
433442
if ((o != null) && Object.keys(o).length) {
434443
this.extendDefaults(o);
435444
this.resetTimeline();
436-
this.tween.recalcDuration();
445+
!isForeign && this.tween.recalcDuration();
437446
this.calcSize();
438-
this.setElStyles();
447+
return !isForeign && this.setElStyles();
439448
}
440-
!this.o.isDrawLess && this.setProgress(0, true);
441-
return this.startTween();
442449
};
443450

444451
Transit.prototype.startTween = function() {

js/burst.coffee

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ h = require './h'
88
Tween = require './tween'
99

1010
class Burst extends Transit
11+
skipProps: childOptions: 1
1112
defaults:
1213
# presentation props
1314
count: 5
@@ -43,7 +44,7 @@ class Burst extends Transit
4344
points: 3
4445
duration: 500
4546
delay: 0
46-
repeat: 1
47+
repeat: 0
4748
yoyo: false
4849
easing: 'Linear.None'
4950
type: 'circle'
@@ -65,16 +66,29 @@ class Burst extends Transit
6566
onComplete: 1
6667
onUpdate: 1
6768
run:(o)->
68-
super
69-
i = @transits.length
70-
while(i--)
71-
tr = @transits[i]
72-
if @props.randomAngle or @props.randomRadius
73-
@props.randomAngle and tr.setProp angleShift: @generateRandomAngle()
69+
if o? and Object.keys(o).length
70+
if o.count or o.childOptions?.count
71+
@h.warn 'Sorry, count can not be changed on run'
72+
@extendDefaults(o)
73+
# copy child options to options
74+
keys = Object.keys(o.childOptions or {})
75+
@o.childOptions ?= {}
76+
for key, i in keys
77+
@o.childOptions[key] = o.childOptions[key]
78+
# tune transits
79+
len = @transits.length
80+
while(len--)
81+
transit = @transits[len]
82+
transit.tuneNewOption @getOption(len), true
83+
@tween.recalcDuration()
84+
if @props.randomAngle or @props.randomRadius
85+
len = @transits.length
86+
while(len--)
87+
tr = @transits[len]
88+
@props.randomAngle and tr.setProp angleShift: @generateRandomAngle()
7489
@props.randomRadius and tr.setProp radiusScale: @generateRandomRadius()
75-
# option = @getOption(i); option.ctx = @ctx
76-
# option.isDrawLess = option.isRunLess = option.isTweenLess = true
77-
# tr.o = option
90+
@startTween()
91+
7892
createBit:->
7993
@transits = []
8094
for i in [0...@props.count]
@@ -136,7 +150,7 @@ class Burst extends Transit
136150
for key, value of @childDefaults
137151
# firstly try to find the prop in @o.childOptions
138152
option[key] = @getPropByMod key: key, i: i
139-
# if fail - continue to this objects
153+
# if fail
140154
# if the same option could be defined for parent and child
141155
# get the option from childDefaults and continue
142156
if @optionsIntersection[key]

js/mojs.coffee

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,27 @@ Transit = require './transit'
2424
# t.add tw2
2525
# t.start()
2626

27-
burst = new Transit(
27+
burst = new Burst(
2828
# isRunLess: true
2929
type: 'polygon'
3030
duration: 500
3131
count: 3
3232
isIt: true
33-
isRunLess: true
34-
# randomAngle: .3
33+
# isRunLess: true
34+
# randomAngle: 1
3535
# degree: 20
3636
radius: {0: 75}
3737
points: 5
38+
isSwirl: true
39+
swirlFrequency: 'rand(0,10)'
40+
swirlSize: 'rand(0,10)'
3841
)
3942

4043
document.addEventListener 'click', (e)->
4144
burst.run
42-
x: e.x, y: e.y, duration: 4000
45+
x: e.x, y: e.y,
46+
duration: 1000
47+
# angle: {360: 0}
4348
# duration: 4000
4449
# type: 'circle'
4550
# # angle: 'rand(0,400)'

0 commit comments

Comments
 (0)