{"size": 1809, "ext": "js", "max_stars_repo_path": "demos/protonjs/fire/index.js", "max_stars_repo_name": "W-Qing/spritejs", "max_stars_repo_stars_event_min_datetime": "2017-07-20T06:49:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T18:57:41.000Z", "max_issues_repo_path": "demos/protonjs/fire/index.js", "max_issues_repo_name": "W-Qing/spritejs", "max_issues_repo_issues_event_min_datetime": "2018-02-12T16:07:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T07:25:28.000Z", "max_forks_repo_path": "demos/protonjs/fire/index.js", "max_forks_repo_name": "W-Qing/spritejs", "max_forks_repo_forks_event_min_datetime": "2017-09-14T14:34:36.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:55:52.000Z"}
{"max_stars_count": 4863, "max_issues_count": 242, "max_forks_count": 333, "avg_line_length": 25.8428571429, "max_line_length": 102, "alphanum_fraction": 0.6533996683}
/* globals Proton */
(async function () {
  const {Scene, Sprite, ProtonRenderer} = spritejs;
  const container = document.getElementById('container');

  const scene = new Scene({
    container,
    width: 800,
    height: 800,
    autoRender: false,
    handleEvent: false,
    preserveDrawingBuffer: true,
  });

  const layer = scene.layer();

  function loadImage(src) {
    const image = new Image();
    image.crossOrigin = 'anonymous';
    const promise = new Promise((resolve) => {
      image.onload = function (e) {
        resolve(e.target);
      };
    });

    image.src = src;
    return promise;
  }
  const image = await loadImage('https://p0.ssl.qhimg.com/t018109a4ae06d3e4d0.png');

  const sprite = new Sprite({
    texture: image,
  });

  const gl = layer.renderer.glRenderer.gl;
  gl.blendFunc(gl.ONE, gl.ONE);

  function createProton() {
    const proton = new Proton();
    const emitter = new Proton.Emitter();
    emitter.rate = new Proton.Rate(new Proton.Span(5, 13), 0.1);

    emitter.addInitialize(new Proton.Mass(1));
    emitter.addInitialize(new Proton.Body(sprite));
    emitter.addInitialize(new Proton.P(new Proton.CircleZone(300, 500, 10)));
    emitter.addInitialize(new Proton.Life(5, 7));
    emitter.addInitialize(new Proton.V(new Proton.Span(2, 3), new Proton.Span(0, 30, true), 'polar'));

    emitter.addBehaviour(new Proton.Scale(1, 0.2));
    emitter.addBehaviour(new Proton.Alpha(1, 0.2));

    // emitter.addBehaviour(new Proton.Color('#ff0000'))

    emitter.emit();
    proton.addEmitter(emitter);

    const renderer = new ProtonRenderer(layer);
    proton.addRenderer(renderer);
    return proton;
  }

  const proton = createProton();

  function tick() {
    requestAnimationFrame(tick);
    proton.update();
  }
  tick();
  window.layer = layer;
}());