|
|
|
|
|
by munificent
2529 days ago
|
|
I first saw that beautiful bifurcation diagram as a teenager in this book called "Fractals" that showed a bunch of fractals as well as programs to draw them. I was amazed that such simple arithmetic could lead to such weird, organic results. The code to draw it is astonishingly simple. Here's an implementation in Dart that prints it to your console: import 'dart:math' as math;
const min = 2.4;
const max = 4.0;
const width = 120;
const height = 100;
main() {
for (var r = min; r < max; r += (max - min) / height ) {
var x = 0.5;
var counts = [for (var i = 0; i < width; i++) 0];
var greatest = 0;
for (var i = 0; i < 200; i++) {
x = r * x * (1 - x);
var i = (x * width).toInt();
counts[i]++;
greatest = math.max(greatest, counts[i]);
}
print(counts.map((n) => n > greatest / 10 ? "*" : " ").join(""));
}
}
|
|
https://tio.run/##HYzBCoJAFEX3fsWhKGcmer4n1UJU/I@YNhFkG8GNi8...