Jump to content

Pythagoras tree: Difference between revisions

m
→‎Dart: renaming
(→‎{{header|Dart}}: added Drawing in Flutter)
m (→‎Dart: renaming)
Line 446:
 
void main() {
var basebasis = [((x: -200.0, y: 0.0), (x: 200.0, y: 0.0))];
final groups = Iterable.generate(12, (lvl) {
final base0basis0 = basebasis;
basebasis = [];
final lvlPolygons = base0basis0.map((pp) {
final (a, b) = pp;
final v = (x: b.x - a.x, y: b.y - a.y);
final [c, d, w] = [a, b, v].map((p) => (x: p.x + v.y, y: p.y - v.x)).toList();
final e = (x: c.x + w.x / 2, y: c.y + w.y / 2);
basebasis.addAll([(c, e), (e, d)]);
return '<polygon points="${[a, c, e, d, c, d, b].expand((p) => [p.x, p.y]).join(' ')}"/>';
}).join('\n');
Line 461:
return '<g fill="#${rg(20)}${rg(30)}18">\n$lvlPolygons\n</g>';
}).join('\n');
final (x, y) = basebasis.fold((0.0, 0.0), (p, pp) => (min(p.$1, pp.$1.x), min(p.$2, pp.$1.y)));
final attrs = 'viewBox="$x $y ${-x - x} ${-y}" stroke="white" xmlns="http://www.w3.org/2000/svg"';
File('Pythagor_tree.svg').writeAsString('<svg $attrs>\n$groups\n</svg>');
Line 498:
 
final fill = Paint()..style = PaintingStyle.fill;
var basebasis = [const (Offset(-200, 0), Offset(200, 0))];
for (var lvl = 0; lvl < 12; lvl++) {
final path = Path();
final base0basis0 = basebasis;
basebasis = [];
for (var (a, b) in base0basis0) {
final v = Offset(b.dx - a.dx, b.dy - a.dy);
final [c, d, w] = [a, b, v].map((p) => Offset(p.dx + v.dy, p.dy - v.dx)).toList();
final e = Offset(c.dx + w.dx / 2, c.dy + w.dy / 2);
basebasis.addAll([(c, e), (e, d)]);
path.addPolygon([a, c, e, d, c, d, b], true);
}
106

edits

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