Skip to content

Commit 78bd09e

Browse files
author
Peter Kim
committed
Merge branch 'develop' of github.com:typecode/typecode-js into develop
2 parents 540ed3a + 5d04a90 commit 78bd09e

File tree

4 files changed

+56
-30
lines changed

4 files changed

+56
-30
lines changed

README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ Versions
3333

3434
0.1 - first release version, only whole version with all files in
3535
top level directory
36+
37+
38+
39+
Some notes added as an example.

lib/particle/tc.particle.context.js

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,35 @@
2727
if(!tc){ var tc = {}; }
2828

2929
(function(tc) {
30-
if(!tc.particle){ tc.particle = {}; }
30+
31+
32+
(function requestAnimationFrame() {
33+
var lastTime = 0;
34+
var vendors = ['ms', 'moz', 'webkit', 'o'];
35+
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
36+
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
37+
window.cancelAnimationFrame =
38+
window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
39+
}
3140

41+
if(!window.requestAnimationFrame)
42+
window.requestAnimationFrame = function(callback, element) {
43+
var currTime = new Date().getTime();
44+
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
45+
var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall);
46+
lastTime = currTime + timeToCall;
47+
return id;
48+
};
49+
50+
if(!window.cancelAnimationFrame)
51+
window.cancelAnimationFrame = function(id) {
52+
clearTimeout(id);
53+
};
54+
}());
55+
56+
if(!tc.particle){ tc.particle = {}; }
3257

33-
tc.particle.context = function(app,dom,options){
58+
tc.particle.context = function(dom,options){
3459
var _me, o;
3560
_me = dom;
3661

@@ -51,7 +76,6 @@ if(!tc){ var tc = {}; }
5176
_me.particles = [];
5277
_me.frame = 0;
5378
_me.stopped = true;
54-
_me.paused = false;
5579
_me.timer = null;
5680
_me.mouse_pos = null;
5781
_me.mouse_down_pos = null;
@@ -75,7 +99,7 @@ if(!tc){ var tc = {}; }
7599
_me.css(size).attr('width',size.width).attr('height',size.height);
76100
_me.anchor_offset = {
77101
x:size.width/2,
78-
y:90
102+
y:size.height/3
79103
}
80104
for(i = 0; i < _me.particles.length; i++){
81105
_me.particles[i]['set_anchor_offset'](_me.anchor_offset);
@@ -106,8 +130,10 @@ if(!tc){ var tc = {}; }
106130
for(i = 0; i < _me.forces.length; i++){
107131
_me.forces[i].radius = (_me.forces[i].radius * 0.98);
108132
}
109-
_me.timer = setTimeout(_me.update,(1000/o.fps));
110-
if(!_me.stopped){
133+
if(_me.stopped){
134+
window.cancelAnimationFrame();
135+
} else {
136+
window.requestAnimationFrame(_me.update);
111137
for(i = 0; i < _me.particles.length; i++){
112138
_me.particles[i]['reset_forces']();
113139
_me.particles[i]['add_forces'](_me.forces);
@@ -118,40 +144,30 @@ if(!tc){ var tc = {}; }
118144
_me.particles[i]['update']();
119145
_me.net_energy = _me.net_energy + _me.particles[i].norm_dist_from_anchor;
120146
}
147+
_me.net_energy = _me.net_energy / _me.particles.length;
148+
_me.mouse_down_pos = null;
149+
_draw();
121150
}
122-
_me.net_energy = _me.net_energy / _me.particles.length;
123-
_me.mouse_down_pos = null;
124-
_draw();
125-
}
126-
127-
_me.isPaused = function(){
128-
return _paused;
151+
129152
}
130153

131154
_me.start = function(){
132-
_me.paused = false;
133155
_me.mouse_pos = null;
134156
_me.mouse_down_pos = null;
135157
if(_me.stopped){
136158
_me.stopped = false;
137-
_me.timer = setTimeout(_me.update,(1000/o.fps));
159+
window.requestAnimationFrame(_me.update);
138160
}
139161
}
140162

141-
_me.pause = function(){
142-
_me.paused = true;
143-
}
144-
145163
_me.stop = function(){
146164
_me.stopped = true;
147-
//_me.timer.cancel();
148-
clearTimeout(_me.timer);
149165
}
150166

151-
function _draw(){
167+
function _draw(drawing_context){
152168
var opacity, i, alpha;
153169

154-
_me.context.globalAlpha = 1;
170+
_me.context.globalAlpha = 1.0;
155171
_me.context.fillStyle = 'rgba(252,252,252,0.45)';
156172
_me.context.fillRect(
157173
0,
@@ -171,17 +187,22 @@ if(!tc){ var tc = {}; }
171187
}
172188

173189
if(opacity){
174-
alpha = 1 - opacity + 0.01;
190+
alpha = 1.0 - opacity + 0.01;
175191
} else {
176-
alpha = 1;
192+
alpha = 1.0;
177193
}
178194

179195
_me.context.globalAlpha = alpha;
180196

197+
_me.context.fillStyle = '#000000';
181198
for(i = 0; i < _me.particles.length; i++){
182199
_me.particles[i].draw(_me.context);
183200
}
184201
}
202+
203+
function _render(){
204+
205+
}
185206

186207
return this.initialize();
187208
}

lib/particle/tc.particle.particle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if(!tc){ var tc = {}; }
2929
(function(tc) {
3030
if(!tc.particle){ tc.particle = {}; }
3131

32-
tc.particle.particle = function(app,options){
32+
tc.particle.particle = function(options){
3333
var _me, o, damping, color;
3434
_me = this;
3535

@@ -74,6 +74,7 @@ if(!tc){ var tc = {}; }
7474
(0+o.anchor.y+o.anchor_offset.y)
7575
]);
7676
_me.radius = o.radius;
77+
_me.diameter = o.radius*2;
7778
if(_me.options.opacity < 1.0){
7879
_me.fill = "rgba("+color.getRGBFromHex('r',o.color)+","+color.getRGBFromHex('g',o.color)+","+color.getRGBFromHex('b',o.color)+","+o.opacity+")";
7980
} else {

lib/tc.merlin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@
243243

244244
// begin transition handling
245245
if (o.transition=='fade') {
246-
if (internal.counters.n_times_step_rendered != 0) {
246+
if (internal.counters.n_times_step_rendered !== 0) {
247247
o.$e.find(internal.current_step.selector).fadeIn(o.transition_speed).siblings('.step').hide();
248248
} else {
249249
o.$e.find(internal.current_step.selector).show().siblings('.step').hide();
250250
}
251251
} else if (o.transition=='slide') {
252-
if (internal.counters.n_times_step_rendered != 0) {
252+
if (internal.counters.n_times_step_rendered !== 0) {
253253
o.$e.find(internal.current_step.selector).siblings('.step').slideUp(o.transition_speed/2);
254254
o.$e.find(internal.current_step.selector).delay(o.transition_speed/2).slideDown(o.transition_speed);
255255
} else {
@@ -260,7 +260,7 @@
260260
}
261261
// end transition handling
262262

263-
if(internal.current_step.n_times_shown == 0 && $.isFunction(internal.current_step.init)){
263+
if(internal.current_step.n_times_shown === 0 && $.isFunction(internal.current_step.init)){
264264
internal.current_step.init(me);
265265
}
266266

@@ -298,8 +298,8 @@
298298

299299
internal.current_step.nav_data = nav_data;
300300

301+
internal.counters.n_times_step_rendered++;
301302
if($.isFunction(internal.current_step.visible)){
302-
internal.counters.n_times_step_rendered++;
303303
internal.current_step.visible(me);
304304
}
305305

0 commit comments

Comments
 (0)