-
Notifications
You must be signed in to change notification settings - Fork 0
/
particlepic.js
76 lines (63 loc) · 2.04 KB
/
particlepic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(function (window, undefined) {
'use strict';
function Particle(targetX, targetY, startX, startY, targetSize, color) {
this.tx = targetX;
this.ty = targetY;
this.x = startX;
this.y = startY;
this.ts = targetSize;
this.color = color;
}
Particle.prototype = {
constructor: Particle,
update: function () {
}
};
function ParticlePic(canvas, image) {
this._can = canvas;
this._particles = [];
this._init(image);
this._ani = 0;
}
ParticlePic.prototype = {
constructor: ParticlePic,
start: function () {
this._ani = requestAnimationFrame(this.start);
this._update();
this._draw();
}.bind(this),
stop: function () {
cancelRequestAnimationFrame(this._ani);
}.bind(this),
_update: function () {
},
_draw: function () {
},
_init: function (image) {
this._height = this._can.height;
this._width = this._can.width;
this._loadImage(image);
this.start();
},
_loadImage: function (image) {
var tCtx = document.createElement('canvas').getContext('2d'),
tImg = new Image();
tImg.onload = function () {
var w = tCtx.canvas.width = tImg.width;
var h = tCtx.canvas.height = tImg.height;
tCtx.drawImage(tImg, 0, 0);
var imgData = tCtx.getImageData(0, 0, w, h).data;
var size = 10;
for (var x = 0; x < w; x++)
for (var y = 0; y < h; y++) {
var i = (y * w + x) * 4;
if(imgData[i+3] > 0){
}
}
};
tImg.src = image;
}
};
if (typeof window.module === object && typeof window.module.exports !== undefined) module.exports = ParticlePic;
else window.ParticlePic = ParticlePic;
}(window));