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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
import { Graphics } from 'pixi.js';
/**
* Factory object that contains many methods to create prefab pixi
* objects
*
* @type object
* @name PixiFactory
*/
export default {
/**
* Creates a sumo container
*
* @function createSumo
* @memberof PixiFactory
* @return {external:CreateJs.Container} the created container
*/
createSumo(config) {
const radius = config.radius;
const sumoColor = config.color || 0x87c5ea;
// The body
const body = new Graphics();
body.beginFill(sumoColor)
.drawCircle(0, 0, radius)
.endFill();
// The mouth
const smile = new Graphics();
smile.name = 'smile';
smile.lineStyle(10, 0xff0080, 1)
.arc(
0, 0, // center
radius * 0.6,
Math.PI / 6,
5 * Math.PI / 6
);
const frown = new Graphics();
frown.name = 'frown';
frown.visible = false;
frown.lineStyle(10, 0xff0080, 1)
.arc(
0, radius,
radius * 0.6,
-Math.PI / 5,
-4 * Math.PI / 5,
true
);
const leftEye = new Graphics();
leftEye.beginFill(0xffffff)
.drawCircle(-radius / 3 - radius / 8, -radius / 4, radius / 5)
.endFill();
const rightEye = new Graphics();
rightEye.beginFill(0xffffff)
.drawCircle(radius / 3 + radius / 8, -radius / 4, radius / 5);
const leftPupil = new Graphics();
leftPupil.beginFill(0x11)
.drawCircle(-radius / 3 - radius / 8, -radius / 4, radius / 10);
const rightPupil = new Graphics();
leftPupil.beginFill(0x11)
.drawCircle(radius / 3 + radius / 8, -radius / 4, radius / 10);
body.addChild(this.createBlush({ radius }));
body.addChild(this.createEffortMark({ radius }));
body.addChild(this.createShadow({ radius }));
// The group
body.addChild(smile);
body.addChild(frown);
body.addChild(leftEye);
body.addChild(rightEye);
body.addChild(leftPupil);
body.addChild(rightPupil);
return body;
},
/**
* Creates an empty graphic
*
* @function createEmptyGraphic
* @memberof PixiFactory
* @return {external:CreateJs.Container} the created container
*/
createEmptyGraphic(config) {
return new Graphics();
},
/**
* Creates a harness graphic
*
* @function createHarness
* @memberof PixiFactory
* @return {external:CreateJs.Container} the created container
*/
createHarness(config) {
const radius = config.radius;
const lineThickness = 10;
// The body
const body = new Graphics();
body.lineStyle(lineThickness, 0xe1e1e1, 1)
.drawCircle(0, 0, radius);
const center = new Graphics();
center.beginFill(0xf1f1f1)
.drawCircle(0, 0, radius - lineThickness / 2)
.endFill();
body.addChild(center);
return body;
},
/**
* Creates an arena graphic
*
* @function createArena
* @memberof PixiFactory
* @return {external:CreateJs.Container} the created container
*/
createArena(config) {
const radius = config.radius;
const lineThickness = 20;
// The body
const arena = new Graphics();
arena.lineStyle(lineThickness, 0xdfd4b2, 1)
.drawCircle(0, 0, radius);
const leftLine = new Graphics();
leftLine.lineStyle(20, 0xbdb08b, 1)
.moveTo(-radius / 4, -radius / 8)
.lineTo(-radius / 4, radius / 8);
const rightLine = new Graphics();
rightLine.lineStyle(20, 0xbdb08b, 1)
.moveTo(radius / 4, -radius / 8)
.lineTo(radius / 4, radius / 8);
arena.addChild(leftLine);
arena.addChild(rightLine);
return arena;
},
/**
* Creates a blush for the face
*
* @function createBlush
* @memberof PixiFactory
* @return {external:CreateJs.Container} the created container
*/
createBlush(config) {
const radius = config.radius;
const blush = new Graphics();
blush.name = 'blush';
blush.visible = false;
const leftEyebrow = new Graphics();
leftEyebrow.lineStyle(4, 0x11, 1)
.arc(
-radius / 3 - radius / 4, -radius / 2 - radius / 4,
radius / 3,
Math.PI / 8,
2 * Math.PI / 3
);
const leftBlush = new Graphics();
leftBlush.lineStyle(4, 0xe7bfe6, 1)
.moveTo(-radius / 3 - radius / 4, radius / 10)
.lineTo(-radius / 3, 0);
const rightEyebrow = new Graphics();
rightEyebrow.lineStyle(4, 0x11, 1)
.arc(
radius / 3 + radius / 4, -radius / 2 - radius / 4,
radius / 3,
Math.PI / 3,
7 * Math.PI / 8
);
const rightBlush = new Graphics();
rightBlush.lineStyle(4, 0xe7bfe6, 1)
.moveTo(radius / 3 + radius / 4, radius / 10)
.lineTo(radius / 3, 0);
blush.addChild(leftEyebrow);
blush.addChild(leftBlush);
blush.addChild(rightEyebrow);
blush.addChild(rightBlush);
return blush;
},
/**
* Creates an effort mark
*
* @function createEffortMark
* @memberof PixiFactory
* @return {external:CreateJs.Container} the created container
*/
createEffortMark(config) {
const radius = config.radius;
const effortMark = new Graphics();
const centerX = -3 * radius / 4;
const centerY = -3 * radius / 4;
effortMark.name = 'effort';
effortMark.visible = false;
const color = 0xff00ff;
const lineWidth = 2;
const topRightArch = new Graphics();
topRightArch.lineStyle(lineWidth, color, 1)
.arc(
centerX + 2 * radius / 7, centerY - 2 * radius / 7,
radius / 5,
Math.PI / 2,
Math.PI
);
const topLeftArch = new Graphics();
topLeftArch.lineStyle(lineWidth, color, 1)
.arc(
centerX - 2 * radius / 7, centerY - radius / 4,
radius / 5,
0,
Math.PI / 2
);
const bottomRightArch = new Graphics();
bottomRightArch.lineStyle(lineWidth, color, 1)
.arc(
centerX + 2 * radius / 7, centerY + radius / 4,
radius / 5,
Math.PI,
3 * Math.PI / 2
);
const bottomLeftArch = new Graphics();
bottomLeftArch.lineStyle(lineWidth, color, 1)
.arc(
centerX - 2 * radius / 7, centerY + 2 * radius / 7,
radius / 5,
3 * Math.PI / 2,
0
);
effortMark.addChild(topRightArch);
effortMark.addChild(topLeftArch);
effortMark.addChild(bottomRightArch);
effortMark.addChild(bottomLeftArch);
return effortMark;
},
/**
* Creates a shadow for the eye
*
* @function createShadow
* @memberof PixiFactory
* @return {external:CreateJs.Container} the created container
*/
createShadow(config) {
const radius = config.radius;
const shadow = new Graphics();
const centerX = radius / 2;
const centerY = -3 * radius / 4;
shadow.name = 'shadow';
shadow.visible = false;
const color = 0x9900ff;
const lineWidth = 2;
shadow.lineStyle(lineWidth, color, 1)
.moveTo(centerX - radius / 4, centerY - radius / 3)
.lineTo(centerX - radius / 4, centerY + radius / 5)
.moveTo(centerX - radius / 8, centerY - radius / 4)
.lineTo(centerX - radius / 8, centerY + radius / 5)
.moveTo(centerX, centerY - radius / 5)
.lineTo(centerX, centerY + radius / 5)
.moveTo(centerX + radius / 8, centerY - radius / 6)
.lineTo(centerX + radius / 8, centerY + radius / 6)
.moveTo(centerX + radius / 4, centerY - radius / 5)
.lineTo(centerX + radius / 4, centerY + radius / 5);
return shadow;
}
};
|