Jump to content

Pythagoras tree: Difference between revisions

m (→‎Drawing in Flutter: mini refactoring)
(→‎Drawing in Flutter: refactoring)
Line 476:
 
@override
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 ⟶ 483:
@override
void paint(Canvas canvas, Size size) {
canvas.translate(size.width / 2, size.height);
canvas.drawColor(Colors.white, BlendMode.src);
final stroke = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 0.9
..color = Colors.white;
 
final fill = Paint()..style = PaintingStyle.fill;
canvas.drawColor(Colors.white, BlendMode.src);
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++) {
final path = Path();
Line 503 ⟶ 497:
basis = [];
for (var (a, b) in basis0) {
final v = Offset((b.dx - a).dxdy, b.dy(a - ab).dydx);
final [(c, d, w] = [a, b, v].map((p) => Offset(p.dxa + v.dy, p.dyb -+ v.dx)).toList();
final e = Offset(c.dx + w.dx / 2, c.dyd + w.dyv) / 2);
basis.addAll([(c, e), (e, d)]);
path.addPolygon([a, c, e, d, c, d, b], true);
}
rg(int step) => (80 + (lvl - 2) * step) & 255;
),canvas
fill.color = Color.fromARGB(255, rg(20), rg(30), 18);
canvas ..drawPath(path, fill..color = Color.fromARGB(255, rg(20), rg(30), 18));
canvas ..drawPath(path, stroke);
}
}
106

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.