/**
   * Create a new emitter configurable externally
   *
   * @param name The name of emitter
   */
  public ConfigurableEmitter(String name) {
    this.name = name;
    leftToEmit = (int) emitCount.random();
    timeout = (int) (length.random());

    colors.add(new ColorRecord(0, Color.white));
    colors.add(new ColorRecord(1, Color.red));

    ArrayList<Vector2f> curve = new ArrayList<>();
    curve.add(new Vector2f(0.0f, 0.0f));
    curve.add(new Vector2f(1.0f, 255.0f));
    alpha = new LinearInterpolator(curve, 0, 255);

    curve = new ArrayList<>();
    curve.add(new Vector2f(0.0f, 0.0f));
    curve.add(new Vector2f(1.0f, 255.0f));
    size = new LinearInterpolator(curve, 0, 255);

    curve = new ArrayList<>();
    curve.add(new Vector2f(0.0f, 0.0f));
    curve.add(new Vector2f(1.0f, 1.0f));
    velocity = new LinearInterpolator(curve, 0, 1);

    curve = new ArrayList<>();
    curve.add(new Vector2f(0.0f, 0.0f));
    curve.add(new Vector2f(1.0f, 1.0f));
    scaleY = new LinearInterpolator(curve, 0, 1);
  }
 /** Cause the emitter to replay it's circle */
 public void replay() {
   reset();
   nextSpawn = 0;
   leftToEmit = (int) emitCount.random();
   timeout = (int) (length.random());
 }
  /**
   * @see
   *     org.newdawn.slick.particles.ParticleEmitter#update(org.newdawn.slick.particles.ParticleSystem,
   *     int)
   */
  @Override
  public void update(ParticleSystem system, int delta) {
    this.engine = system;

    if (!adjust) {
      adjustx = 0;
      adjusty = 0;
    } else adjust = false;

    if (updateImage) {
      updateImage = false;
      try {
        image = new Image(relativePath + imageName);
      } catch (SlickException e) {
        image = null;
        Log.error(e);
      }
    }

    if (((wrapUp)
            || ((length.isEnabled()) && (timeout < 0))
            || ((emitCount.isEnabled() && (leftToEmit <= 0))))
        && (particleCount == 0)) {
      completed = true;
    }
    particleCount = 0;

    if (wrapUp) return;

    if (length.isEnabled()) {
      if (timeout < 0) return;
      timeout -= delta;
    }
    if (emitCount.isEnabled() && leftToEmit <= 0) return;

    nextSpawn -= delta;
    if (nextSpawn < 0) {
      nextSpawn = (int) spawnInterval.random();
      int count = (int) spawnCount.random();

      for (int i = 0; i < count; i++) {
        Particle p = system.getNewParticle(this, initialLife.random());
        p.setSize(initialSize.random());
        p.setPosition(x + xOffset.random(), y + yOffset.random());
        p.setVelocity(0, 0, 0);

        float dist = initialDistance.random();
        float power = speed.random();
        if ((dist != 0) || (power != 0)) {
          float s = spread.getValue(0);
          float ang = (s + angularOffset.getValue(0) - (spread.getValue() / 2)) - 90;
          float xa = (float) FastTrig.cos(Math.toRadians(ang)) * dist;
          float ya = (float) FastTrig.sin(Math.toRadians(ang)) * dist;
          p.adjustPosition(xa, ya);

          float xv = (float) FastTrig.cos(Math.toRadians(ang));
          float yv = (float) FastTrig.sin(Math.toRadians(ang));
          p.setVelocity(xv, yv, power * 0.001f);
        }

        if (image != null) p.setImage(image);

        ColorRecord start = colors.get(0);
        p.setColor(start.col.r, start.col.g, start.col.b, startAlpha.getValue(0) / 255.0f);
        p.setUsePoint(usePoints);
        p.setOriented(useOriented);

        if (emitCount.isEnabled()) {
          leftToEmit--;
          if (leftToEmit <= 0) break;
        }
      }
    }
  }