3 ms·
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
by munificent 7y 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(""));
}
}
- jonahx 7y agoTranslated into J: w=. 120 row=. [: (' *' {~ ] > 10 %~ >./) [: (1 #. i.@w =/ ]) [: <. w * (* ] * -.@])^:(<200)&0.5 echo (row"0) 2.4 + 1.6r100 * i.101 Live: https://tio.run/##HYzBCoJAFEX3fsWhKGcmer4n1UJU/I@YNhFkG8GNi8BfnyZ3l3MO95PS0glWazFP/3VvcCWh5LsS6THlsNJL5Tdl7IVRhoWuIm6sFRYCLuQ@cJYh@kfj2lrVH1Wuxev5nnD5faeeWi6cMLnNpprzUUwtpR8 https://tio.run/##HYzBCoJAFEX3fsWhKGcmer4n1UJU/I@YNhFkG8GNi8...