Pythagoras tree: Difference between revisions

Content added Content deleted
(→‎Drawing in Flutter: refactoring)
Line 446: Line 446:


void main() {
void main() {
var basis = [((x: -200.0, y: 0.0), (x: 200.0, y: 0.0))];
var basis = [(Point(-200.0, 0.0), Point(200.0, 0.0))];
final groups = Iterable.generate(12, (lvl) {
final groups = Iterable.generate(12, (lvl) {
final basis0 = basis;
final basis0 = basis;
Line 452: Line 452:
final lvlPolygons = basis0.map((pp) {
final lvlPolygons = basis0.map((pp) {
final (a, b) = pp;
final (a, b) = pp;
final v = (x: b.x - a.x, y: b.y - a.y);
final v = Point((b - a).y, (a - b).x);
final [c, d, w] = [a, b, v].map((p) => (x: p.x + v.y, y: p.y - v.x)).toList();
final (c, d) = (a + v, b + v);
final e = (x: c.x + w.x / 2, y: c.y + w.y / 2);
final e = (c + d + v) * 0.5;
basis.addAll([(c, e), (e, d)]);
basis.addAll([(c, e), (e, d)]);
return '<polygon points="${[a, c, e, d, c, d, b].expand((p) => [p.x, p.y]).join(' ')}"/>';
return '<polygon points="${[a, c, e, d, c, d, b].expand((p) => [p.x, p.y]).join(' ')}"/>';