Add random to the Color and Paint extensions (#1081)

* Add `randomColor` to the `Color` extension

* Add flame rive package to monorepo (#1048)

Add flame rive package to monorepo

* Add random to PaintExtension

* Update examples/pubspec.yaml

Co-authored-by: Erick <erickzanardoo@gmail.com>

Co-authored-by: Renan <6718144+renancaraujo@users.noreply.github.com>
Co-authored-by: Erick <erickzanardoo@gmail.com>
This commit is contained in:
Lukas Klingsbo
2021-11-10 13:09:12 +01:00
committed by GitHub
parent 92f3346966
commit 32bf19b91c
9 changed files with 115 additions and 56 deletions

View File

@ -1,6 +1,5 @@
import 'dart:math';
import 'package:flame/components.dart';
import 'package:flame/extensions.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flame/palette.dart';
@ -85,7 +84,7 @@ class Square extends PositionComponent with HasGameRef<RiveExampleGame> {
Square(Vector2 position) {
this.position.setFrom(position);
size.setValues(100, 100);
paint = _randomPaint();
paint = PaintExtension.random(withAlpha: 0.9, base: 100);
}
@override
@ -93,15 +92,4 @@ class Square extends PositionComponent with HasGameRef<RiveExampleGame> {
super.render(canvas);
canvas.drawRect(size.toRect(), paint);
}
static Paint _randomPaint() {
final rng = Random();
final color = Color.fromRGBO(
rng.nextInt(256),
rng.nextInt(256),
rng.nextInt(256),
0.9,
);
return PaletteEntry(color).paint();
}
}