aboutsummaryrefslogtreecommitdiff
path: root/lib/factories/pixi.js
blob: 851a07459b11e7ff6db427b956c461f86cc63d90 (plain)
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
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;

    // The body
    const body = new Graphics();
    body.beginFill(0x87c5ea)
      .drawCircle(0, 0, radius)
      .endFill();

    // The mouth
    const mouth = new Graphics();
    mouth.lineStyle(10, 0xff0080, 1)
      .arc(
        0, 0, // center
        radius * 0.6,
        Math.PI / 6,
        5 * Math.PI / 6
      );

    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);

    // The group
    body.addChild(mouth);
    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();
  }
};