drawLight method

void drawLight(
  1. Canvas canvas,
  2. Size size
)
override

Implementation

void drawLight(Canvas canvas, Size size) {
  Color currentColor = color.getCurrentColor();
  //this does the glowing effect
  RadialGradient rg = RadialGradient(colors: [
    Color.fromARGB(
        10, currentColor.red, currentColor.green, currentColor.blue),
    Color.fromARGB(0, currentColor.red, currentColor.green, currentColor.blue)
  ]);
  for (EVector2D pathPoint in _pathPoint) {
    Rect rect = Rect.fromCircle(
        center: pathPoint.getOffset(),
        radius: glow.getAbsoluteValue(size) * width.getAbsoluteValue(size));
    Paint paint = Paint()
      ..shader = rg.createShader(rect)
      ..blendMode = BlendMode.screen;
    if (glow.getAbsoluteValue(size) > 0) {
      paint.maskFilter =
          MaskFilter.blur(BlurStyle.normal, glow.getAbsoluteValue(size));
    }
    canvas.drawCircle(
        pathPoint.getOffset(), 5 * width.getAbsoluteValue(size), paint);
  }
  if (!throwsLight) {
    return;
  }
  //this does the actual lighting
  for (int i = 1; i < 10; i++) {
    rg = RadialGradient(colors: [
      Color.fromARGB((6 - i / 2).toInt(), currentColor.red,
          currentColor.green, currentColor.blue),
      Color.fromARGB(
          0, currentColor.red, currentColor.green, currentColor.blue)
    ]);
    for (EVector2D pathPoint in _pathPoint) {
      if (Random().nextInt(i + 4) > 0) {
        continue;
      }
      Rect rect = Rect.fromCircle(
          center: pathPoint.getOffset(),
          radius: 10 * i * width.getAbsoluteValue(size));
      Paint paint = Paint()
        ..shader = rg.createShader(rect)
        ..blendMode = BlendMode.screen;
      if (glow.getAbsoluteValue(size) * i > 0) {
        paint.maskFilter = MaskFilter.blur(
            BlurStyle.normal, glow.getAbsoluteValue(size) * i);
      }
      canvas.drawCircle(pathPoint.getOffset(),
          10 * i * width.getAbsoluteValue(size), paint);
    }
  }
}