xmedia-project 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/index.html +16 -0
- package/demo/server.mjs +6 -1
- package/package.json +2 -1
- package/xMediaSDK/filter/background/halloween/bloodMoon.js +257 -0
- package/xMediaSDK/filter/background/halloween/bloodMoon.min.js +1 -0
- package/xMediaSDK/filter/background/halloween/bloodMoon.min.mjs +1 -0
- package/xMediaSDK/filter/background/halloween/bloodMoon.mjs +248 -0
- package/xMediaSDK/filter/background/halloween/darkForest.js +264 -0
- package/xMediaSDK/filter/background/halloween/darkForest.min.js +1 -0
- package/xMediaSDK/filter/background/halloween/darkForest.min.mjs +1 -0
- package/xMediaSDK/filter/background/halloween/darkForest.mjs +255 -0
- package/xMediaSDK/filter/background/halloween/graveyard.js +272 -0
- package/xMediaSDK/filter/background/halloween/graveyard.min.js +1 -0
- package/xMediaSDK/filter/background/halloween/graveyard.min.mjs +1 -0
- package/xMediaSDK/filter/background/halloween/graveyard.mjs +263 -0
- package/xMediaSDK/filter/background/halloween/hauntedHouse.js +270 -0
- package/xMediaSDK/filter/background/halloween/hauntedHouse.min.js +1 -0
- package/xMediaSDK/filter/background/halloween/hauntedHouse.min.mjs +1 -0
- package/xMediaSDK/filter/background/halloween/hauntedHouse.mjs +261 -0
- package/xMediaSDK/filter/background/halloween/pumpkinPatch.js +282 -0
- package/xMediaSDK/filter/background/halloween/pumpkinPatch.min.js +1 -0
- package/xMediaSDK/filter/background/halloween/pumpkinPatch.min.mjs +1 -0
- package/xMediaSDK/filter/background/halloween/pumpkinPatch.mjs +273 -0
- package/xMediaSDK/filter/background.js +135 -0
- package/xMediaSDK/filter/background.min.js +1 -0
- package/xMediaSDK/filter/background.min.mjs +1 -0
- package/xMediaSDK/filter/background.mjs +126 -0
- package/xMediaSDK/filter/face.js +269 -0
- package/xMediaSDK/filter/face.min.js +1 -0
- package/xMediaSDK/filter/face.min.mjs +1 -0
- package/xMediaSDK/filter/face.mjs +259 -0
- package/xMediaSDK/filter/mask/cat.js +271 -0
- package/xMediaSDK/filter/mask/cat.min.js +1 -0
- package/xMediaSDK/filter/mask/cat.min.mjs +1 -0
- package/xMediaSDK/filter/mask/cat.mjs +262 -0
- package/xMediaSDK/filter/mask/clown.js +254 -0
- package/xMediaSDK/filter/mask/clown.min.js +1 -0
- package/xMediaSDK/filter/mask/clown.min.mjs +1 -0
- package/xMediaSDK/filter/mask/clown.mjs +245 -0
- package/xMediaSDK/filter/mask/costume.js +280 -0
- package/xMediaSDK/filter/mask/costume.min.js +1 -0
- package/xMediaSDK/filter/mask/costume.min.mjs +1 -0
- package/xMediaSDK/filter/mask/costume.mjs +271 -0
- package/xMediaSDK/filter/mask/general/bunny.js +282 -0
- package/xMediaSDK/filter/mask/general/bunny.min.js +1 -0
- package/xMediaSDK/filter/mask/general/bunny.min.mjs +1 -0
- package/xMediaSDK/filter/mask/general/bunny.mjs +273 -0
- package/xMediaSDK/filter/mask/general/butterflies.js +267 -0
- package/xMediaSDK/filter/mask/general/butterflies.min.js +1 -0
- package/xMediaSDK/filter/mask/general/butterflies.min.mjs +1 -0
- package/xMediaSDK/filter/mask/general/butterflies.mjs +258 -0
- package/xMediaSDK/filter/mask/general/flowerCrown.js +274 -0
- package/xMediaSDK/filter/mask/general/flowerCrown.min.js +1 -0
- package/xMediaSDK/filter/mask/general/flowerCrown.min.mjs +1 -0
- package/xMediaSDK/filter/mask/general/flowerCrown.mjs +265 -0
- package/xMediaSDK/filter/mask/general/freckles.js +261 -0
- package/xMediaSDK/filter/mask/general/freckles.min.js +1 -0
- package/xMediaSDK/filter/mask/general/freckles.min.mjs +1 -0
- package/xMediaSDK/filter/mask/general/freckles.mjs +252 -0
- package/xMediaSDK/filter/mask/general/hearts.js +257 -0
- package/xMediaSDK/filter/mask/general/hearts.min.js +1 -0
- package/xMediaSDK/filter/mask/general/hearts.min.mjs +1 -0
- package/xMediaSDK/filter/mask/general/hearts.mjs +248 -0
- package/xMediaSDK/filter/mask/general/makeup.js +284 -0
- package/xMediaSDK/filter/mask/general/makeup.min.js +1 -0
- package/xMediaSDK/filter/mask/general/makeup.min.mjs +1 -0
- package/xMediaSDK/filter/mask/general/makeup.mjs +275 -0
- package/xMediaSDK/filter/mask/general/puppy.js +283 -0
- package/xMediaSDK/filter/mask/general/puppy.min.js +1 -0
- package/xMediaSDK/filter/mask/general/puppy.min.mjs +1 -0
- package/xMediaSDK/filter/mask/general/puppy.mjs +274 -0
- package/xMediaSDK/filter/mask/general/sparkles.js +255 -0
- package/xMediaSDK/filter/mask/general/sparkles.min.js +1 -0
- package/xMediaSDK/filter/mask/general/sparkles.min.mjs +1 -0
- package/xMediaSDK/filter/mask/general/sparkles.mjs +246 -0
- package/xMediaSDK/filter/mask/general/tiara.js +280 -0
- package/xMediaSDK/filter/mask/general/tiara.min.js +1 -0
- package/xMediaSDK/filter/mask/general/tiara.min.mjs +1 -0
- package/xMediaSDK/filter/mask/general/tiara.mjs +271 -0
- package/xMediaSDK/filter/mask/general/unicorn.js +270 -0
- package/xMediaSDK/filter/mask/general/unicorn.min.js +1 -0
- package/xMediaSDK/filter/mask/general/unicorn.min.mjs +1 -0
- package/xMediaSDK/filter/mask/general/unicorn.mjs +261 -0
- package/xMediaSDK/filter/mask/glasses.js +271 -0
- package/xMediaSDK/filter/mask/glasses.min.js +1 -0
- package/xMediaSDK/filter/mask/glasses.min.mjs +1 -0
- package/xMediaSDK/filter/mask/glasses.mjs +262 -0
- package/xMediaSDK/filter/mask/halloween/bats.js +269 -0
- package/xMediaSDK/filter/mask/halloween/bats.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/bats.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/bats.mjs +260 -0
- package/xMediaSDK/filter/mask/halloween/blood.js +256 -0
- package/xMediaSDK/filter/mask/halloween/blood.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/blood.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/blood.mjs +247 -0
- package/xMediaSDK/filter/mask/halloween/fangs.js +256 -0
- package/xMediaSDK/filter/mask/halloween/fangs.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/fangs.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/fangs.mjs +247 -0
- package/xMediaSDK/filter/mask/halloween/frankenstein.js +300 -0
- package/xMediaSDK/filter/mask/halloween/frankenstein.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/frankenstein.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/frankenstein.mjs +291 -0
- package/xMediaSDK/filter/mask/halloween/ghost.js +277 -0
- package/xMediaSDK/filter/mask/halloween/ghost.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/ghost.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/ghost.mjs +268 -0
- package/xMediaSDK/filter/mask/halloween/horns.js +250 -0
- package/xMediaSDK/filter/mask/halloween/horns.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/horns.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/horns.mjs +241 -0
- package/xMediaSDK/filter/mask/halloween/mummy.js +267 -0
- package/xMediaSDK/filter/mask/halloween/mummy.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/mummy.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/mummy.mjs +258 -0
- package/xMediaSDK/filter/mask/halloween/pumpkin.js +296 -0
- package/xMediaSDK/filter/mask/halloween/pumpkin.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/pumpkin.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/pumpkin.mjs +287 -0
- package/xMediaSDK/filter/mask/halloween/skull.js +277 -0
- package/xMediaSDK/filter/mask/halloween/skull.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/skull.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/skull.mjs +268 -0
- package/xMediaSDK/filter/mask/halloween/spiderweb.js +300 -0
- package/xMediaSDK/filter/mask/halloween/spiderweb.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/spiderweb.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/spiderweb.mjs +291 -0
- package/xMediaSDK/filter/mask/halloween/witchHat.js +262 -0
- package/xMediaSDK/filter/mask/halloween/witchHat.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/witchHat.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/witchHat.mjs +253 -0
- package/xMediaSDK/filter/mask/halloween/zombie.js +278 -0
- package/xMediaSDK/filter/mask/halloween/zombie.min.js +1 -0
- package/xMediaSDK/filter/mask/halloween/zombie.min.mjs +1 -0
- package/xMediaSDK/filter/mask/halloween/zombie.mjs +269 -0
- package/xMediaSDK/filter/mask/hat.js +250 -0
- package/xMediaSDK/filter/mask/hat.min.js +1 -0
- package/xMediaSDK/filter/mask/hat.min.mjs +1 -0
- package/xMediaSDK/filter/mask/hat.mjs +241 -0
- package/xMediaSDK/filter/mask/image.js +286 -0
- package/xMediaSDK/filter/mask/image.min.js +1 -0
- package/xMediaSDK/filter/mask/image.min.mjs +1 -0
- package/xMediaSDK/filter/mask/image.mjs +277 -0
- package/xMediaSDK/filter/mask/mustache.js +245 -0
- package/xMediaSDK/filter/mask/mustache.min.js +1 -0
- package/xMediaSDK/filter/mask/mustache.min.mjs +1 -0
- package/xMediaSDK/filter/mask/mustache.mjs +236 -0
- package/xMediaSDK/filter/mask/pixel.js +249 -0
- package/xMediaSDK/filter/mask/pixel.min.js +1 -0
- package/xMediaSDK/filter/mask/pixel.min.mjs +1 -0
- package/xMediaSDK/filter/mask/pixel.mjs +240 -0
- package/xMediaSDK/filter/mask/witch/broom.js +292 -0
- package/xMediaSDK/filter/mask/witch/broom.min.js +1 -0
- package/xMediaSDK/filter/mask/witch/broom.min.mjs +1 -0
- package/xMediaSDK/filter/mask/witch/broom.mjs +283 -0
- package/xMediaSDK/filter/mask/witch/cauldron.js +271 -0
- package/xMediaSDK/filter/mask/witch/cauldron.min.js +1 -0
- package/xMediaSDK/filter/mask/witch/cauldron.min.mjs +1 -0
- package/xMediaSDK/filter/mask/witch/cauldron.mjs +262 -0
- package/xMediaSDK/filter/mask/witch/magic.js +251 -0
- package/xMediaSDK/filter/mask/witch/magic.min.js +1 -0
- package/xMediaSDK/filter/mask/witch/magic.min.mjs +1 -0
- package/xMediaSDK/filter/mask/witch/magic.mjs +242 -0
- package/xMediaSDK/filter/mask/witch/raven.js +276 -0
- package/xMediaSDK/filter/mask/witch/raven.min.js +1 -0
- package/xMediaSDK/filter/mask/witch/raven.min.mjs +1 -0
- package/xMediaSDK/filter/mask/witch/raven.mjs +267 -0
- package/xMediaSDK/filter/mask/witch/witchMakeup.js +258 -0
- package/xMediaSDK/filter/mask/witch/witchMakeup.min.js +1 -0
- package/xMediaSDK/filter/mask/witch/witchMakeup.min.mjs +1 -0
- package/xMediaSDK/filter/mask/witch/witchMakeup.mjs +249 -0
- package/xMediaSDK/filter/mask/witch/witchNose.js +273 -0
- package/xMediaSDK/filter/mask/witch/witchNose.min.js +1 -0
- package/xMediaSDK/filter/mask/witch/witchNose.min.mjs +1 -0
- package/xMediaSDK/filter/mask/witch/witchNose.mjs +264 -0
- package/xMediaSDK/filter/retouch.js +230 -0
- package/xMediaSDK/filter/retouch.min.js +1 -0
- package/xMediaSDK/filter/retouch.min.mjs +1 -0
- package/xMediaSDK/filter/retouch.mjs +221 -0
- package/xMediaSDK/xMediaPlayer.css +226 -45
- package/xMediaSDK/xMediaPlayer.min.css +1 -1
- package/xMediaSDK/xMediaPlayer.min.css.map +1 -1
- package/xMediaSDK/xMediaSDK.js +1085 -41
- package/xMediaSDK/xMediaSDK.min.js +1 -1
- package/xMediaSDK/xMediaSDK.min.js.map +1 -1
- package/xMediaSDK/xMediaSDK.mjs +1085 -42
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
var xMediaFilterModule = (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var xMediaScene = function(__xMediaFilter, __options, __sceneOptions) {
|
|
5
|
+
|
|
6
|
+
var $this = this;
|
|
7
|
+
var __sceneCanvas;
|
|
8
|
+
var __sceneCtx;
|
|
9
|
+
var __personCanvas;
|
|
10
|
+
var __personCtx;
|
|
11
|
+
var __sceneData = null;
|
|
12
|
+
|
|
13
|
+
this.getOrder = function() {
|
|
14
|
+
return 10;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
this.getGroup = function() {
|
|
18
|
+
return 'background';
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
this.isExclusive = function() {
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
this.getOptions = function() {
|
|
26
|
+
return __options;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
this.setOptions = function(options) {
|
|
30
|
+
for(var key in options){
|
|
31
|
+
if(options.hasOwnProperty(key)){
|
|
32
|
+
__options[key] = options[key];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
this.load = function() {
|
|
38
|
+
return __xMediaFilter.loadSegmenter().then(function() {
|
|
39
|
+
return $this;
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
this.process = function(frame) {
|
|
44
|
+
var person = __xMediaFilter.segmentPerson(frame);
|
|
45
|
+
if(!person){
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
var width = frame['width'];
|
|
49
|
+
var height = frame['height'];
|
|
50
|
+
var ctx = frame['ctx'];
|
|
51
|
+
if(__sceneCanvas.width !== width || __sceneCanvas.height !== height || !__sceneData){
|
|
52
|
+
__xMediaFilter.resizeCanvas(__sceneCanvas, width, height);
|
|
53
|
+
__sceneData = __sceneOptions['drawStatic'](__sceneCtx, width, height, xMediaScene.createRandom(__sceneOptions['seed'] || 7)) || {};
|
|
54
|
+
}
|
|
55
|
+
__xMediaFilter.resizeCanvas(__personCanvas, width, height);
|
|
56
|
+
__personCtx.globalCompositeOperation = 'copy';
|
|
57
|
+
__personCtx.drawImage(person['canvas'], 0, 0, width, height);
|
|
58
|
+
__personCtx.globalCompositeOperation = 'source-in';
|
|
59
|
+
__personCtx.drawImage(frame['canvas'], 0, 0);
|
|
60
|
+
ctx.globalCompositeOperation = 'copy';
|
|
61
|
+
ctx.drawImage(__sceneCanvas, 0, 0);
|
|
62
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
63
|
+
if(__sceneOptions['drawBack']){
|
|
64
|
+
ctx.save();
|
|
65
|
+
__sceneOptions['drawBack'](ctx, width, height, frame['timestamp'], __sceneData);
|
|
66
|
+
ctx.restore();
|
|
67
|
+
}
|
|
68
|
+
ctx.drawImage(__personCanvas, 0, 0);
|
|
69
|
+
if(__sceneOptions['drawFront']){
|
|
70
|
+
ctx.save();
|
|
71
|
+
__sceneOptions['drawFront'](ctx, width, height, frame['timestamp'], __sceneData);
|
|
72
|
+
ctx.restore();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
this.destroy = function() {
|
|
77
|
+
__sceneData = null;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
(function() {
|
|
81
|
+
__options = __options || {};
|
|
82
|
+
__sceneCanvas = __xMediaFilter.createCanvas();
|
|
83
|
+
__sceneCtx = __sceneCanvas.getContext('2d');
|
|
84
|
+
__personCanvas = __xMediaFilter.createCanvas();
|
|
85
|
+
__personCtx = __personCanvas.getContext('2d');
|
|
86
|
+
})();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
xMediaScene.createRandom = function(seed) {
|
|
90
|
+
var value = seed % 2147483647 || 1;
|
|
91
|
+
return function() {
|
|
92
|
+
value = value * 16807 % 2147483647;
|
|
93
|
+
return (value - 1) / 2147483646;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
xMediaScene.fillSky = function(ctx, width, height, colorList) {
|
|
98
|
+
var gradient = ctx.createLinearGradient(0, 0, 0, height);
|
|
99
|
+
for(var i = 0; i < colorList.length; i++){
|
|
100
|
+
gradient.addColorStop(i / (colorList.length - 1), colorList[i]);
|
|
101
|
+
}
|
|
102
|
+
ctx.fillStyle = gradient;
|
|
103
|
+
ctx.fillRect(0, 0, width, height);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
xMediaScene.drawStars = function(ctx, width, height, random, count) {
|
|
107
|
+
for(var i = 0; i < count; i++){
|
|
108
|
+
ctx.fillStyle = 'rgba(255, 255, 255, ' + (0.3 + random() * 0.7) + ')';
|
|
109
|
+
ctx.fillRect(random() * width, random() * height * 0.6, random() < 0.9 ? 1 : 2, 1 + (random() < 0.1 ? 1 : 0));
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
xMediaScene.drawMoon = function(ctx, x, y, radius, color, glowColor) {
|
|
114
|
+
var glow = ctx.createRadialGradient(x, y, radius * 0.8, x, y, radius * 3);
|
|
115
|
+
glow.addColorStop(0, glowColor);
|
|
116
|
+
glow.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
|
117
|
+
ctx.fillStyle = glow;
|
|
118
|
+
ctx.fillRect(x - radius * 3, y - radius * 3, radius * 6, radius * 6);
|
|
119
|
+
var body = ctx.createRadialGradient(x - radius * 0.3, y - radius * 0.3, radius * 0.1, x, y, radius);
|
|
120
|
+
body.addColorStop(0, '#ffffff');
|
|
121
|
+
body.addColorStop(0.35, color);
|
|
122
|
+
body.addColorStop(1, color);
|
|
123
|
+
ctx.fillStyle = body;
|
|
124
|
+
ctx.beginPath();
|
|
125
|
+
ctx.arc(x, y, radius, 0, Math.PI * 2);
|
|
126
|
+
ctx.fill();
|
|
127
|
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.08)';
|
|
128
|
+
var craterList = [[-0.3, -0.2, 0.18], [0.25, 0.1, 0.22], [-0.1, 0.4, 0.12], [0.35, -0.35, 0.1]];
|
|
129
|
+
for(var i = 0; i < craterList.length; i++){
|
|
130
|
+
ctx.beginPath();
|
|
131
|
+
ctx.arc(x + craterList[i][0] * radius, y + craterList[i][1] * radius, craterList[i][2] * radius, 0, Math.PI * 2);
|
|
132
|
+
ctx.fill();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
xMediaScene.drawTree = function(ctx, x, y, length, angle, width, depth, random) {
|
|
137
|
+
var endX = x + Math.cos(angle) * length;
|
|
138
|
+
var endY = y + Math.sin(angle) * length;
|
|
139
|
+
ctx.lineWidth = width;
|
|
140
|
+
ctx.lineCap = 'round';
|
|
141
|
+
ctx.beginPath();
|
|
142
|
+
ctx.moveTo(x, y);
|
|
143
|
+
ctx.quadraticCurveTo(x + Math.cos(angle + 0.3) * length * 0.5, y + Math.sin(angle + 0.3) * length * 0.5, endX, endY);
|
|
144
|
+
ctx.stroke();
|
|
145
|
+
if(depth <= 0){
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
var branchCount = 2 + Math.floor(random() * 2);
|
|
149
|
+
for(var i = 0; i < branchCount; i++){
|
|
150
|
+
xMediaScene.drawTree(ctx, endX, endY, length * (0.55 + random() * 0.2), angle + (random() - 0.5) * 1.4, width * 0.62, depth - 1, random);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
xMediaScene.drawBat = function(ctx, x, y, size, flap) {
|
|
155
|
+
ctx.save();
|
|
156
|
+
ctx.translate(x, y);
|
|
157
|
+
ctx.scale(size, size);
|
|
158
|
+
ctx.beginPath();
|
|
159
|
+
for(var side = -1; side <= 1; side += 2){
|
|
160
|
+
ctx.moveTo(0, 0);
|
|
161
|
+
ctx.quadraticCurveTo(side * 0.4, -0.5 * flap - 0.1, side * 1, -0.3 * flap);
|
|
162
|
+
ctx.quadraticCurveTo(side * 0.7, -0.05, side * 0.55, 0.15);
|
|
163
|
+
ctx.quadraticCurveTo(side * 0.35, 0, side * 0.15, 0.15);
|
|
164
|
+
ctx.closePath();
|
|
165
|
+
}
|
|
166
|
+
ctx.ellipse(0, 0.05, 0.12, 0.2, 0, 0, Math.PI * 2);
|
|
167
|
+
ctx.fill();
|
|
168
|
+
ctx.restore();
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
xMediaScene.drawFog = function(ctx, width, height, time, y, color, count, speed) {
|
|
172
|
+
for(var i = 0; i < count; i++){
|
|
173
|
+
var radius = width * (0.18 + (i % 3) * 0.06);
|
|
174
|
+
var x = ((i * 0.37 + time * speed / width * (1 + (i % 2) * 0.5)) % 1.4 - 0.2) * width;
|
|
175
|
+
var fogY = y + Math.sin(time / 2000 + i) * height * 0.02;
|
|
176
|
+
var gradient = ctx.createRadialGradient(x, fogY, 0, x, fogY, radius);
|
|
177
|
+
gradient.addColorStop(0, color);
|
|
178
|
+
gradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
|
179
|
+
ctx.fillStyle = gradient;
|
|
180
|
+
ctx.fillRect(x - radius, fogY - radius, radius * 2, radius * 2);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
xMediaScene.createModule = function(name, SceneClass, info) {
|
|
185
|
+
return {
|
|
186
|
+
'name': 'background/' + (info['category'] ? info['category'] + '/' : '') + name,
|
|
187
|
+
'filterList': [{'name': name, 'category': 'background', 'title': info['title'], 'icon': info['icon'], 'filterClass': SceneClass}],
|
|
188
|
+
'dependencyList': []
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
var _drawStatic = function(ctx, width, height, random) {
|
|
193
|
+
xMediaScene.fillSky(ctx, width, height, ['#020504', '#08140f', '#14261d', '#0a120d']);
|
|
194
|
+
var layerList = [['#1a2d24', 0.012, 14], ['#0f1d17', 0.02, 10], ['#060d0a', 0.035, 7]];
|
|
195
|
+
for(var i = 0; i < layerList.length; i++){
|
|
196
|
+
ctx.fillStyle = layerList[i][0];
|
|
197
|
+
for(var j = 0; j < layerList[i][2]; j++){
|
|
198
|
+
var x = random() * width;
|
|
199
|
+
var trunkWidth = height * layerList[i][1] * (0.7 + random() * 0.8) * 3;
|
|
200
|
+
ctx.beginPath();
|
|
201
|
+
ctx.moveTo(x - trunkWidth * 0.6, height);
|
|
202
|
+
ctx.lineTo(x - trunkWidth * 0.3, 0);
|
|
203
|
+
ctx.lineTo(x + trunkWidth * 0.3, 0);
|
|
204
|
+
ctx.lineTo(x + trunkWidth * 0.6, height);
|
|
205
|
+
ctx.closePath();
|
|
206
|
+
ctx.fill();
|
|
207
|
+
}
|
|
208
|
+
ctx.strokeStyle = layerList[i][0];
|
|
209
|
+
for(var k = 0; k < 3; k++){
|
|
210
|
+
xMediaScene.drawTree(ctx, random() * width, height * (0.3 + random() * 0.3), height * 0.12, -Math.PI / 2 + (random() - 0.5), height * layerList[i][1], 3, random);
|
|
211
|
+
}
|
|
212
|
+
var mist = ctx.createLinearGradient(0, height * 0.4, 0, height);
|
|
213
|
+
mist.addColorStop(0, 'rgba(120, 160, 140, 0)');
|
|
214
|
+
mist.addColorStop(1, 'rgba(120, 160, 140, 0.12)');
|
|
215
|
+
ctx.fillStyle = mist;
|
|
216
|
+
ctx.fillRect(0, 0, width, height);
|
|
217
|
+
}
|
|
218
|
+
var eyeList = [];
|
|
219
|
+
for(var m = 0; m < 6; m++){
|
|
220
|
+
eyeList.push({'x': random() * width, 'y': height * (0.3 + random() * 0.45), 'size': height * (0.006 + random() * 0.006), 'phase': random() * 20, 'red': random() < 0.4});
|
|
221
|
+
}
|
|
222
|
+
return {'eyeList': eyeList};
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
var _drawBack = function(ctx, width, height, time, data) {
|
|
226
|
+
var eyeList = data['eyeList'];
|
|
227
|
+
ctx.globalCompositeOperation = 'lighter';
|
|
228
|
+
for(var i = 0; i < eyeList.length; i++){
|
|
229
|
+
var eye = eyeList[i];
|
|
230
|
+
var cycle = (time / 1000 + eye['phase']) % 7;
|
|
231
|
+
if(cycle > 4.5 || (cycle > 2 && cycle < 2.15)){
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
for(var side = -1; side <= 1; side += 2){
|
|
235
|
+
var x = eye['x'] + side * eye['size'] * 2.2;
|
|
236
|
+
var gradient = ctx.createRadialGradient(x, eye['y'], 0, x, eye['y'], eye['size'] * 2.5);
|
|
237
|
+
gradient.addColorStop(0, eye['red'] ? 'rgba(255, 60, 40, 1)' : 'rgba(255, 230, 80, 1)');
|
|
238
|
+
gradient.addColorStop(0.35, eye['red'] ? 'rgba(255, 30, 20, 0.6)' : 'rgba(255, 200, 40, 0.6)');
|
|
239
|
+
gradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
|
240
|
+
ctx.fillStyle = gradient;
|
|
241
|
+
ctx.fillRect(x - eye['size'] * 2.5, eye['y'] - eye['size'] * 2.5, eye['size'] * 5, eye['size'] * 5);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
245
|
+
xMediaScene.drawFog(ctx, width, height, time, height * 0.85, 'rgba(140, 180, 160, 0.14)', 6, 0.012);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
var _drawFront = function(ctx, width, height, time) {
|
|
249
|
+
xMediaScene.drawFog(ctx, width, height, time, height * 1.05, 'rgba(140, 180, 160, 0.1)', 4, 0.02);
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
var xMediaDarkForestScene = function(__xMediaFilter, __options) {
|
|
253
|
+
xMediaScene.call(this, __xMediaFilter, __options, {'seed': 59, 'drawStatic': _drawStatic, 'drawBack': _drawBack, 'drawFront': _drawFront});
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
var filterModule = xMediaScene.createModule('darkForest', xMediaDarkForestScene, {'title': 'Dark forest', 'icon': '🌲', 'category': 'halloween'});
|
|
257
|
+
|
|
258
|
+
exports.filterModule = filterModule;
|
|
259
|
+
exports.xMediaDarkForestScene = xMediaDarkForestScene;
|
|
260
|
+
|
|
261
|
+
return exports;
|
|
262
|
+
|
|
263
|
+
})({});
|
|
264
|
+
window.xMediaFilter ? window.xMediaFilter.registerModule(xMediaFilterModule.filterModule) : (window.xMediaFilterModuleList = window.xMediaFilterModuleList || []).push(xMediaFilterModule.filterModule);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var xMediaFilterModule=function(e){"use strict";var r=function(e,a,t){var o,i,l,n,d=this,s=null;this.getOrder=function(){return 10},this.getGroup=function(){return"background"},this.isExclusive=function(){return!0},this.getOptions=function(){return a},this.setOptions=function(e){for(var r in e)e.hasOwnProperty(r)&&(a[r]=e[r])},this.load=function(){return e.loadSegmenter().then(function(){return d})},this.process=function(a){var d=e.segmentPerson(a);if(d){var c=a.width,f=a.height,u=a.ctx;o.width===c&&o.height===f&&s||(e.resizeCanvas(o,c,f),s=t.drawStatic(i,c,f,r.createRandom(t.seed||7))||{}),e.resizeCanvas(l,c,f),n.globalCompositeOperation="copy",n.drawImage(d.canvas,0,0,c,f),n.globalCompositeOperation="source-in",n.drawImage(a.canvas,0,0),u.globalCompositeOperation="copy",u.drawImage(o,0,0),u.globalCompositeOperation="source-over",t.drawBack&&(u.save(),t.drawBack(u,c,f,a.timestamp,s),u.restore()),u.drawImage(l,0,0),t.drawFront&&(u.save(),t.drawFront(u,c,f,a.timestamp,s),u.restore())}},this.destroy=function(){s=null},a=a||{},o=e.createCanvas(),i=o.getContext("2d"),l=e.createCanvas(),n=l.getContext("2d")};r.createRandom=function(e){var r=e%2147483647||1;return function(){return((r=16807*r%2147483647)-1)/2147483646}},r.fillSky=function(e,r,a,t){for(var o=e.createLinearGradient(0,0,0,a),i=0;i<t.length;i++)o.addColorStop(i/(t.length-1),t[i]);e.fillStyle=o,e.fillRect(0,0,r,a)},r.drawStars=function(e,r,a,t,o){for(var i=0;i<o;i++)e.fillStyle="rgba(255, 255, 255, "+(.3+.7*t())+")",e.fillRect(t()*r,t()*a*.6,t()<.9?1:2,1+(t()<.1?1:0))},r.drawMoon=function(e,r,a,t,o,i){var l=e.createRadialGradient(r,a,.8*t,r,a,3*t);l.addColorStop(0,i),l.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=l,e.fillRect(r-3*t,a-3*t,6*t,6*t);var n=e.createRadialGradient(r-.3*t,a-.3*t,.1*t,r,a,t);n.addColorStop(0,"#ffffff"),n.addColorStop(.35,o),n.addColorStop(1,o),e.fillStyle=n,e.beginPath(),e.arc(r,a,t,0,2*Math.PI),e.fill(),e.fillStyle="rgba(0, 0, 0, 0.08)";for(var d=[[-.3,-.2,.18],[.25,.1,.22],[-.1,.4,.12],[.35,-.35,.1]],s=0;s<d.length;s++)e.beginPath(),e.arc(r+d[s][0]*t,a+d[s][1]*t,d[s][2]*t,0,2*Math.PI),e.fill()},r.drawTree=function(e,a,t,o,i,l,n,d){var s=a+Math.cos(i)*o,c=t+Math.sin(i)*o;if(e.lineWidth=l,e.lineCap="round",e.beginPath(),e.moveTo(a,t),e.quadraticCurveTo(a+Math.cos(i+.3)*o*.5,t+Math.sin(i+.3)*o*.5,s,c),e.stroke(),!(n<=0))for(var f=2+Math.floor(2*d()),u=0;u<f;u++)r.drawTree(e,s,c,o*(.55+.2*d()),i+1.4*(d()-.5),.62*l,n-1,d)},r.drawBat=function(e,r,a,t,o){e.save(),e.translate(r,a),e.scale(t,t),e.beginPath();for(var i=-1;i<=1;i+=2)e.moveTo(0,0),e.quadraticCurveTo(.4*i,-.5*o-.1,1*i,-.3*o),e.quadraticCurveTo(.7*i,-.05,.55*i,.15),e.quadraticCurveTo(.35*i,0,.15*i,.15),e.closePath();e.ellipse(0,.05,.12,.2,0,0,2*Math.PI),e.fill(),e.restore()},r.drawFog=function(e,r,a,t,o,i,l,n){for(var d=0;d<l;d++){var s=r*(.18+d%3*.06),c=((.37*d+t*n/r*(1+d%2*.5))%1.4-.2)*r,f=o+Math.sin(t/2e3+d)*a*.02,u=e.createRadialGradient(c,f,0,c,f,s);u.addColorStop(0,i),u.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=u,e.fillRect(c-s,f-s,2*s,2*s)}},r.createModule=function(e,r,a){return{name:"background/"+(a.category?a.category+"/":"")+e,filterList:[{name:e,category:"background",title:a.title,icon:a.icon,filterClass:r}],dependencyList:[]}};var a=function(e,a,t,o){r.fillSky(e,a,t,["#020504","#08140f","#14261d","#0a120d"]);for(var i=[["#1a2d24",.012,14],["#0f1d17",.02,10],["#060d0a",.035,7]],l=0;l<i.length;l++){e.fillStyle=i[l][0];for(var n=0;n<i[l][2];n++){var d=o()*a,s=t*i[l][1]*(.7+.8*o())*3;e.beginPath(),e.moveTo(d-.6*s,t),e.lineTo(d-.3*s,0),e.lineTo(d+.3*s,0),e.lineTo(d+.6*s,t),e.closePath(),e.fill()}e.strokeStyle=i[l][0];for(var c=0;c<3;c++)r.drawTree(e,o()*a,t*(.3+.3*o()),.12*t,-Math.PI/2+(o()-.5),t*i[l][1],3,o);var f=e.createLinearGradient(0,.4*t,0,t);f.addColorStop(0,"rgba(120, 160, 140, 0)"),f.addColorStop(1,"rgba(120, 160, 140, 0.12)"),e.fillStyle=f,e.fillRect(0,0,a,t)}for(var u=[],g=0;g<6;g++)u.push({x:o()*a,y:t*(.3+.45*o()),size:t*(.006+.006*o()),phase:20*o(),red:o()<.4});return{eyeList:u}},t=function(e,a,t,o,i){var l=i.eyeList;e.globalCompositeOperation="lighter";for(var n=0;n<l.length;n++){var d=l[n],s=(o/1e3+d.phase)%7;if(!(s>4.5||s>2&&s<2.15))for(var c=-1;c<=1;c+=2){var f=d.x+c*d.size*2.2,u=e.createRadialGradient(f,d.y,0,f,d.y,2.5*d.size);u.addColorStop(0,d.red?"rgba(255, 60, 40, 1)":"rgba(255, 230, 80, 1)"),u.addColorStop(.35,d.red?"rgba(255, 30, 20, 0.6)":"rgba(255, 200, 40, 0.6)"),u.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=u,e.fillRect(f-2.5*d.size,d.y-2.5*d.size,5*d.size,5*d.size)}}e.globalCompositeOperation="source-over",r.drawFog(e,a,t,o,.85*t,"rgba(140, 180, 160, 0.14)",6,.012)},o=function(e,a,t,o){r.drawFog(e,a,t,o,1.05*t,"rgba(140, 180, 160, 0.1)",4,.02)},i=function(e,i){r.call(this,e,i,{seed:59,drawStatic:a,drawBack:t,drawFront:o})},l=r.createModule("darkForest",i,{title:"Dark forest",icon:"\ud83c\udf32",category:"halloween"});return e.filterModule=l,e.xMediaDarkForestScene=i,e}({});window.xMediaFilter?window.xMediaFilter.registerModule(xMediaFilterModule.filterModule):(window.xMediaFilterModuleList=window.xMediaFilterModuleList||[]).push(xMediaFilterModule.filterModule);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=function(e,r,t){var o,i,n,l,d=this,c=null;this.getOrder=function(){return 10},this.getGroup=function(){return"background"},this.isExclusive=function(){return!0},this.getOptions=function(){return r},this.setOptions=function(a){for(var e in a)a.hasOwnProperty(e)&&(r[e]=a[e])},this.load=function(){return e.loadSegmenter().then(function(){return d})},this.process=function(r){var d=e.segmentPerson(r);if(d){var s=r.width,f=r.height,u=r.ctx;o.width===s&&o.height===f&&c||(e.resizeCanvas(o,s,f),c=t.drawStatic(i,s,f,a.createRandom(t.seed||7))||{}),e.resizeCanvas(n,s,f),l.globalCompositeOperation="copy",l.drawImage(d.canvas,0,0,s,f),l.globalCompositeOperation="source-in",l.drawImage(r.canvas,0,0),u.globalCompositeOperation="copy",u.drawImage(o,0,0),u.globalCompositeOperation="source-over",t.drawBack&&(u.save(),t.drawBack(u,s,f,r.timestamp,c),u.restore()),u.drawImage(n,0,0),t.drawFront&&(u.save(),t.drawFront(u,s,f,r.timestamp,c),u.restore())}},this.destroy=function(){c=null},r=r||{},o=e.createCanvas(),i=o.getContext("2d"),n=e.createCanvas(),l=n.getContext("2d")};a.createRandom=function(a){var e=a%2147483647||1;return function(){return((e=16807*e%2147483647)-1)/2147483646}},a.fillSky=function(a,e,r,t){for(var o=a.createLinearGradient(0,0,0,r),i=0;i<t.length;i++)o.addColorStop(i/(t.length-1),t[i]);a.fillStyle=o,a.fillRect(0,0,e,r)},a.drawStars=function(a,e,r,t,o){for(var i=0;i<o;i++)a.fillStyle="rgba(255, 255, 255, "+(.3+.7*t())+")",a.fillRect(t()*e,t()*r*.6,t()<.9?1:2,1+(t()<.1?1:0))},a.drawMoon=function(a,e,r,t,o,i){var n=a.createRadialGradient(e,r,.8*t,e,r,3*t);n.addColorStop(0,i),n.addColorStop(1,"rgba(0, 0, 0, 0)"),a.fillStyle=n,a.fillRect(e-3*t,r-3*t,6*t,6*t);var l=a.createRadialGradient(e-.3*t,r-.3*t,.1*t,e,r,t);l.addColorStop(0,"#ffffff"),l.addColorStop(.35,o),l.addColorStop(1,o),a.fillStyle=l,a.beginPath(),a.arc(e,r,t,0,2*Math.PI),a.fill(),a.fillStyle="rgba(0, 0, 0, 0.08)";for(var d=[[-.3,-.2,.18],[.25,.1,.22],[-.1,.4,.12],[.35,-.35,.1]],c=0;c<d.length;c++)a.beginPath(),a.arc(e+d[c][0]*t,r+d[c][1]*t,d[c][2]*t,0,2*Math.PI),a.fill()},a.drawTree=function(e,r,t,o,i,n,l,d){var c=r+Math.cos(i)*o,s=t+Math.sin(i)*o;if(e.lineWidth=n,e.lineCap="round",e.beginPath(),e.moveTo(r,t),e.quadraticCurveTo(r+Math.cos(i+.3)*o*.5,t+Math.sin(i+.3)*o*.5,c,s),e.stroke(),!(l<=0))for(var f=2+Math.floor(2*d()),u=0;u<f;u++)a.drawTree(e,c,s,o*(.55+.2*d()),i+1.4*(d()-.5),.62*n,l-1,d)},a.drawBat=function(a,e,r,t,o){a.save(),a.translate(e,r),a.scale(t,t),a.beginPath();for(var i=-1;i<=1;i+=2)a.moveTo(0,0),a.quadraticCurveTo(.4*i,-.5*o-.1,1*i,-.3*o),a.quadraticCurveTo(.7*i,-.05,.55*i,.15),a.quadraticCurveTo(.35*i,0,.15*i,.15),a.closePath();a.ellipse(0,.05,.12,.2,0,0,2*Math.PI),a.fill(),a.restore()},a.drawFog=function(a,e,r,t,o,i,n,l){for(var d=0;d<n;d++){var c=e*(.18+d%3*.06),s=((.37*d+t*l/e*(1+d%2*.5))%1.4-.2)*e,f=o+Math.sin(t/2e3+d)*r*.02,u=a.createRadialGradient(s,f,0,s,f,c);u.addColorStop(0,i),u.addColorStop(1,"rgba(0, 0, 0, 0)"),a.fillStyle=u,a.fillRect(s-c,f-c,2*c,2*c)}},a.createModule=function(a,e,r){return{name:"background/"+(r.category?r.category+"/":"")+a,filterList:[{name:a,category:"background",title:r.title,icon:r.icon,filterClass:e}],dependencyList:[]}};var e=function(e,r,t,o){a.fillSky(e,r,t,["#020504","#08140f","#14261d","#0a120d"]);for(var i=[["#1a2d24",.012,14],["#0f1d17",.02,10],["#060d0a",.035,7]],n=0;n<i.length;n++){e.fillStyle=i[n][0];for(var l=0;l<i[n][2];l++){var d=o()*r,c=t*i[n][1]*(.7+.8*o())*3;e.beginPath(),e.moveTo(d-.6*c,t),e.lineTo(d-.3*c,0),e.lineTo(d+.3*c,0),e.lineTo(d+.6*c,t),e.closePath(),e.fill()}e.strokeStyle=i[n][0];for(var s=0;s<3;s++)a.drawTree(e,o()*r,t*(.3+.3*o()),.12*t,-Math.PI/2+(o()-.5),t*i[n][1],3,o);var f=e.createLinearGradient(0,.4*t,0,t);f.addColorStop(0,"rgba(120, 160, 140, 0)"),f.addColorStop(1,"rgba(120, 160, 140, 0.12)"),e.fillStyle=f,e.fillRect(0,0,r,t)}for(var u=[],g=0;g<6;g++)u.push({x:o()*r,y:t*(.3+.45*o()),size:t*(.006+.006*o()),phase:20*o(),red:o()<.4});return{eyeList:u}},r=function(e,r,t,o,i){var n=i.eyeList;e.globalCompositeOperation="lighter";for(var l=0;l<n.length;l++){var d=n[l],c=(o/1e3+d.phase)%7;if(!(c>4.5||c>2&&c<2.15))for(var s=-1;s<=1;s+=2){var f=d.x+s*d.size*2.2,u=e.createRadialGradient(f,d.y,0,f,d.y,2.5*d.size);u.addColorStop(0,d.red?"rgba(255, 60, 40, 1)":"rgba(255, 230, 80, 1)"),u.addColorStop(.35,d.red?"rgba(255, 30, 20, 0.6)":"rgba(255, 200, 40, 0.6)"),u.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=u,e.fillRect(f-2.5*d.size,d.y-2.5*d.size,5*d.size,5*d.size)}}e.globalCompositeOperation="source-over",a.drawFog(e,r,t,o,.85*t,"rgba(140, 180, 160, 0.14)",6,.012)},t=function(e,r,t,o){a.drawFog(e,r,t,o,1.05*t,"rgba(140, 180, 160, 0.1)",4,.02)},o=function(o,i){a.call(this,o,i,{seed:59,drawStatic:e,drawBack:r,drawFront:t})},i=a.createModule("darkForest",o,{title:"Dark forest",icon:"\ud83c\udf32",category:"halloween"});export{i as filterModule,o as xMediaDarkForestScene};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
var xMediaScene = function(__xMediaFilter, __options, __sceneOptions) {
|
|
2
|
+
|
|
3
|
+
var $this = this;
|
|
4
|
+
var __sceneCanvas;
|
|
5
|
+
var __sceneCtx;
|
|
6
|
+
var __personCanvas;
|
|
7
|
+
var __personCtx;
|
|
8
|
+
var __sceneData = null;
|
|
9
|
+
|
|
10
|
+
this.getOrder = function() {
|
|
11
|
+
return 10;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
this.getGroup = function() {
|
|
15
|
+
return 'background';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
this.isExclusive = function() {
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
this.getOptions = function() {
|
|
23
|
+
return __options;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
this.setOptions = function(options) {
|
|
27
|
+
for(var key in options){
|
|
28
|
+
if(options.hasOwnProperty(key)){
|
|
29
|
+
__options[key] = options[key];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
this.load = function() {
|
|
35
|
+
return __xMediaFilter.loadSegmenter().then(function() {
|
|
36
|
+
return $this;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
this.process = function(frame) {
|
|
41
|
+
var person = __xMediaFilter.segmentPerson(frame);
|
|
42
|
+
if(!person){
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var width = frame['width'];
|
|
46
|
+
var height = frame['height'];
|
|
47
|
+
var ctx = frame['ctx'];
|
|
48
|
+
if(__sceneCanvas.width !== width || __sceneCanvas.height !== height || !__sceneData){
|
|
49
|
+
__xMediaFilter.resizeCanvas(__sceneCanvas, width, height);
|
|
50
|
+
__sceneData = __sceneOptions['drawStatic'](__sceneCtx, width, height, xMediaScene.createRandom(__sceneOptions['seed'] || 7)) || {};
|
|
51
|
+
}
|
|
52
|
+
__xMediaFilter.resizeCanvas(__personCanvas, width, height);
|
|
53
|
+
__personCtx.globalCompositeOperation = 'copy';
|
|
54
|
+
__personCtx.drawImage(person['canvas'], 0, 0, width, height);
|
|
55
|
+
__personCtx.globalCompositeOperation = 'source-in';
|
|
56
|
+
__personCtx.drawImage(frame['canvas'], 0, 0);
|
|
57
|
+
ctx.globalCompositeOperation = 'copy';
|
|
58
|
+
ctx.drawImage(__sceneCanvas, 0, 0);
|
|
59
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
60
|
+
if(__sceneOptions['drawBack']){
|
|
61
|
+
ctx.save();
|
|
62
|
+
__sceneOptions['drawBack'](ctx, width, height, frame['timestamp'], __sceneData);
|
|
63
|
+
ctx.restore();
|
|
64
|
+
}
|
|
65
|
+
ctx.drawImage(__personCanvas, 0, 0);
|
|
66
|
+
if(__sceneOptions['drawFront']){
|
|
67
|
+
ctx.save();
|
|
68
|
+
__sceneOptions['drawFront'](ctx, width, height, frame['timestamp'], __sceneData);
|
|
69
|
+
ctx.restore();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
this.destroy = function() {
|
|
74
|
+
__sceneData = null;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
(function() {
|
|
78
|
+
__options = __options || {};
|
|
79
|
+
__sceneCanvas = __xMediaFilter.createCanvas();
|
|
80
|
+
__sceneCtx = __sceneCanvas.getContext('2d');
|
|
81
|
+
__personCanvas = __xMediaFilter.createCanvas();
|
|
82
|
+
__personCtx = __personCanvas.getContext('2d');
|
|
83
|
+
})();
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
xMediaScene.createRandom = function(seed) {
|
|
87
|
+
var value = seed % 2147483647 || 1;
|
|
88
|
+
return function() {
|
|
89
|
+
value = value * 16807 % 2147483647;
|
|
90
|
+
return (value - 1) / 2147483646;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
xMediaScene.fillSky = function(ctx, width, height, colorList) {
|
|
95
|
+
var gradient = ctx.createLinearGradient(0, 0, 0, height);
|
|
96
|
+
for(var i = 0; i < colorList.length; i++){
|
|
97
|
+
gradient.addColorStop(i / (colorList.length - 1), colorList[i]);
|
|
98
|
+
}
|
|
99
|
+
ctx.fillStyle = gradient;
|
|
100
|
+
ctx.fillRect(0, 0, width, height);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
xMediaScene.drawStars = function(ctx, width, height, random, count) {
|
|
104
|
+
for(var i = 0; i < count; i++){
|
|
105
|
+
ctx.fillStyle = 'rgba(255, 255, 255, ' + (0.3 + random() * 0.7) + ')';
|
|
106
|
+
ctx.fillRect(random() * width, random() * height * 0.6, random() < 0.9 ? 1 : 2, 1 + (random() < 0.1 ? 1 : 0));
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
xMediaScene.drawMoon = function(ctx, x, y, radius, color, glowColor) {
|
|
111
|
+
var glow = ctx.createRadialGradient(x, y, radius * 0.8, x, y, radius * 3);
|
|
112
|
+
glow.addColorStop(0, glowColor);
|
|
113
|
+
glow.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
|
114
|
+
ctx.fillStyle = glow;
|
|
115
|
+
ctx.fillRect(x - radius * 3, y - radius * 3, radius * 6, radius * 6);
|
|
116
|
+
var body = ctx.createRadialGradient(x - radius * 0.3, y - radius * 0.3, radius * 0.1, x, y, radius);
|
|
117
|
+
body.addColorStop(0, '#ffffff');
|
|
118
|
+
body.addColorStop(0.35, color);
|
|
119
|
+
body.addColorStop(1, color);
|
|
120
|
+
ctx.fillStyle = body;
|
|
121
|
+
ctx.beginPath();
|
|
122
|
+
ctx.arc(x, y, radius, 0, Math.PI * 2);
|
|
123
|
+
ctx.fill();
|
|
124
|
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.08)';
|
|
125
|
+
var craterList = [[-0.3, -0.2, 0.18], [0.25, 0.1, 0.22], [-0.1, 0.4, 0.12], [0.35, -0.35, 0.1]];
|
|
126
|
+
for(var i = 0; i < craterList.length; i++){
|
|
127
|
+
ctx.beginPath();
|
|
128
|
+
ctx.arc(x + craterList[i][0] * radius, y + craterList[i][1] * radius, craterList[i][2] * radius, 0, Math.PI * 2);
|
|
129
|
+
ctx.fill();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
xMediaScene.drawTree = function(ctx, x, y, length, angle, width, depth, random) {
|
|
134
|
+
var endX = x + Math.cos(angle) * length;
|
|
135
|
+
var endY = y + Math.sin(angle) * length;
|
|
136
|
+
ctx.lineWidth = width;
|
|
137
|
+
ctx.lineCap = 'round';
|
|
138
|
+
ctx.beginPath();
|
|
139
|
+
ctx.moveTo(x, y);
|
|
140
|
+
ctx.quadraticCurveTo(x + Math.cos(angle + 0.3) * length * 0.5, y + Math.sin(angle + 0.3) * length * 0.5, endX, endY);
|
|
141
|
+
ctx.stroke();
|
|
142
|
+
if(depth <= 0){
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
var branchCount = 2 + Math.floor(random() * 2);
|
|
146
|
+
for(var i = 0; i < branchCount; i++){
|
|
147
|
+
xMediaScene.drawTree(ctx, endX, endY, length * (0.55 + random() * 0.2), angle + (random() - 0.5) * 1.4, width * 0.62, depth - 1, random);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
xMediaScene.drawBat = function(ctx, x, y, size, flap) {
|
|
152
|
+
ctx.save();
|
|
153
|
+
ctx.translate(x, y);
|
|
154
|
+
ctx.scale(size, size);
|
|
155
|
+
ctx.beginPath();
|
|
156
|
+
for(var side = -1; side <= 1; side += 2){
|
|
157
|
+
ctx.moveTo(0, 0);
|
|
158
|
+
ctx.quadraticCurveTo(side * 0.4, -0.5 * flap - 0.1, side * 1, -0.3 * flap);
|
|
159
|
+
ctx.quadraticCurveTo(side * 0.7, -0.05, side * 0.55, 0.15);
|
|
160
|
+
ctx.quadraticCurveTo(side * 0.35, 0, side * 0.15, 0.15);
|
|
161
|
+
ctx.closePath();
|
|
162
|
+
}
|
|
163
|
+
ctx.ellipse(0, 0.05, 0.12, 0.2, 0, 0, Math.PI * 2);
|
|
164
|
+
ctx.fill();
|
|
165
|
+
ctx.restore();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
xMediaScene.drawFog = function(ctx, width, height, time, y, color, count, speed) {
|
|
169
|
+
for(var i = 0; i < count; i++){
|
|
170
|
+
var radius = width * (0.18 + (i % 3) * 0.06);
|
|
171
|
+
var x = ((i * 0.37 + time * speed / width * (1 + (i % 2) * 0.5)) % 1.4 - 0.2) * width;
|
|
172
|
+
var fogY = y + Math.sin(time / 2000 + i) * height * 0.02;
|
|
173
|
+
var gradient = ctx.createRadialGradient(x, fogY, 0, x, fogY, radius);
|
|
174
|
+
gradient.addColorStop(0, color);
|
|
175
|
+
gradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
|
176
|
+
ctx.fillStyle = gradient;
|
|
177
|
+
ctx.fillRect(x - radius, fogY - radius, radius * 2, radius * 2);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
xMediaScene.createModule = function(name, SceneClass, info) {
|
|
182
|
+
return {
|
|
183
|
+
'name': 'background/' + (info['category'] ? info['category'] + '/' : '') + name,
|
|
184
|
+
'filterList': [{'name': name, 'category': 'background', 'title': info['title'], 'icon': info['icon'], 'filterClass': SceneClass}],
|
|
185
|
+
'dependencyList': []
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
var _drawStatic = function(ctx, width, height, random) {
|
|
190
|
+
xMediaScene.fillSky(ctx, width, height, ['#020504', '#08140f', '#14261d', '#0a120d']);
|
|
191
|
+
var layerList = [['#1a2d24', 0.012, 14], ['#0f1d17', 0.02, 10], ['#060d0a', 0.035, 7]];
|
|
192
|
+
for(var i = 0; i < layerList.length; i++){
|
|
193
|
+
ctx.fillStyle = layerList[i][0];
|
|
194
|
+
for(var j = 0; j < layerList[i][2]; j++){
|
|
195
|
+
var x = random() * width;
|
|
196
|
+
var trunkWidth = height * layerList[i][1] * (0.7 + random() * 0.8) * 3;
|
|
197
|
+
ctx.beginPath();
|
|
198
|
+
ctx.moveTo(x - trunkWidth * 0.6, height);
|
|
199
|
+
ctx.lineTo(x - trunkWidth * 0.3, 0);
|
|
200
|
+
ctx.lineTo(x + trunkWidth * 0.3, 0);
|
|
201
|
+
ctx.lineTo(x + trunkWidth * 0.6, height);
|
|
202
|
+
ctx.closePath();
|
|
203
|
+
ctx.fill();
|
|
204
|
+
}
|
|
205
|
+
ctx.strokeStyle = layerList[i][0];
|
|
206
|
+
for(var k = 0; k < 3; k++){
|
|
207
|
+
xMediaScene.drawTree(ctx, random() * width, height * (0.3 + random() * 0.3), height * 0.12, -Math.PI / 2 + (random() - 0.5), height * layerList[i][1], 3, random);
|
|
208
|
+
}
|
|
209
|
+
var mist = ctx.createLinearGradient(0, height * 0.4, 0, height);
|
|
210
|
+
mist.addColorStop(0, 'rgba(120, 160, 140, 0)');
|
|
211
|
+
mist.addColorStop(1, 'rgba(120, 160, 140, 0.12)');
|
|
212
|
+
ctx.fillStyle = mist;
|
|
213
|
+
ctx.fillRect(0, 0, width, height);
|
|
214
|
+
}
|
|
215
|
+
var eyeList = [];
|
|
216
|
+
for(var m = 0; m < 6; m++){
|
|
217
|
+
eyeList.push({'x': random() * width, 'y': height * (0.3 + random() * 0.45), 'size': height * (0.006 + random() * 0.006), 'phase': random() * 20, 'red': random() < 0.4});
|
|
218
|
+
}
|
|
219
|
+
return {'eyeList': eyeList};
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
var _drawBack = function(ctx, width, height, time, data) {
|
|
223
|
+
var eyeList = data['eyeList'];
|
|
224
|
+
ctx.globalCompositeOperation = 'lighter';
|
|
225
|
+
for(var i = 0; i < eyeList.length; i++){
|
|
226
|
+
var eye = eyeList[i];
|
|
227
|
+
var cycle = (time / 1000 + eye['phase']) % 7;
|
|
228
|
+
if(cycle > 4.5 || (cycle > 2 && cycle < 2.15)){
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
for(var side = -1; side <= 1; side += 2){
|
|
232
|
+
var x = eye['x'] + side * eye['size'] * 2.2;
|
|
233
|
+
var gradient = ctx.createRadialGradient(x, eye['y'], 0, x, eye['y'], eye['size'] * 2.5);
|
|
234
|
+
gradient.addColorStop(0, eye['red'] ? 'rgba(255, 60, 40, 1)' : 'rgba(255, 230, 80, 1)');
|
|
235
|
+
gradient.addColorStop(0.35, eye['red'] ? 'rgba(255, 30, 20, 0.6)' : 'rgba(255, 200, 40, 0.6)');
|
|
236
|
+
gradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
|
237
|
+
ctx.fillStyle = gradient;
|
|
238
|
+
ctx.fillRect(x - eye['size'] * 2.5, eye['y'] - eye['size'] * 2.5, eye['size'] * 5, eye['size'] * 5);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
242
|
+
xMediaScene.drawFog(ctx, width, height, time, height * 0.85, 'rgba(140, 180, 160, 0.14)', 6, 0.012);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
var _drawFront = function(ctx, width, height, time) {
|
|
246
|
+
xMediaScene.drawFog(ctx, width, height, time, height * 1.05, 'rgba(140, 180, 160, 0.1)', 4, 0.02);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
var xMediaDarkForestScene = function(__xMediaFilter, __options) {
|
|
250
|
+
xMediaScene.call(this, __xMediaFilter, __options, {'seed': 59, 'drawStatic': _drawStatic, 'drawBack': _drawBack, 'drawFront': _drawFront});
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
var filterModule = xMediaScene.createModule('darkForest', xMediaDarkForestScene, {'title': 'Dark forest', 'icon': '🌲', 'category': 'halloween'});
|
|
254
|
+
|
|
255
|
+
export { filterModule, xMediaDarkForestScene };
|