Pythagoras tree: Difference between revisions
Content added Content deleted
m (→Drawing in Flutter: mini refactoring) |
(→Drawing in Flutter: refactoring) |
||
Line 476: | Line 476: | ||
@override |
@override |
||
Widget build(BuildContext context) |
Widget build(BuildContext context) => FittedBox( |
||
child: CustomPaint(painter: TreePainter(), size: const Size(2400, 1600))); |
|||
return FittedBox( |
|||
child: CustomPaint( |
|||
size: const Size(2360, 1580), |
|||
painter: TreePainter(), |
|||
⚫ | |||
); |
|||
} |
|||
} |
} |
||
Line 489: | Line 483: | ||
@override |
@override |
||
void paint(Canvas canvas, Size size) { |
void paint(Canvas canvas, Size size) { |
||
canvas.translate(size.width / 2, size.height); |
|||
⚫ | |||
final stroke = Paint() |
final stroke = Paint() |
||
..style = PaintingStyle.stroke |
..style = PaintingStyle.stroke |
||
..strokeWidth = 0.9 |
..strokeWidth = 0.9 |
||
..color = Colors.white; |
..color = Colors.white; |
||
final fill = Paint()..style = PaintingStyle.fill; |
final fill = Paint()..style = PaintingStyle.fill; |
||
⚫ | |||
var basis = [const (Offset(-200, 0), Offset(200, 0))]; |
|||
const halfBase = Offset(200, 0); |
|||
var basis = [(size.bottomCenter(-halfBase), size.bottomCenter(halfBase))]; |
|||
for (var lvl = 0; lvl < 12; lvl++) { |
for (var lvl = 0; lvl < 12; lvl++) { |
||
final path = Path(); |
final path = Path(); |
||
Line 503: | Line 497: | ||
basis = []; |
basis = []; |
||
for (var (a, b) in basis0) { |
for (var (a, b) in basis0) { |
||
final v = Offset(b |
final v = Offset((b - a).dy, (a - b).dx); |
||
final |
final (c, d) = (a + v, b + v); |
||
final e = |
final e = (c + d + v) / 2; |
||
basis.addAll([(c, e), (e, d)]); |
basis.addAll([(c, e), (e, d)]); |
||
path.addPolygon([a, c, e, d, c, d, b], true); |
path.addPolygon([a, c, e, d, c, d, b], true); |
||
} |
} |
||
rg(int step) => (80 + (lvl - 2) * step) & 255; |
rg(int step) => (80 + (lvl - 2) * step) & 255; |
||
⚫ | |||
fill.color = Color.fromARGB(255, rg(20), rg(30), 18); |
|||
..drawPath(path, fill..color = Color.fromARGB(255, rg(20), rg(30), 18)) |
|||
..drawPath(path, stroke); |
|||
} |
} |
||
} |
} |