// A straight Dart transliteration of the Nim kernel in src/nimflutter.v. // // It exists purely so the example can render the *same* image both ways and // put a number on the difference. Keep it in sync with the Nim version — if the // two drift, the comparison stops being honest. import 'dart:math' as math; import 'dart:typed_data'; import 'package:nimflutter_ffi/nimflutter_ffi.dart' as v; Uint8List renderDart(v.FractalView view) { final out = Uint8List(view.width * view.height * 4); final aspect = view.width / view.height; final invW = 1.0 / view.width; final invH = 1.0 / view.height; final ln2 = math.log(2.0); for (var y = 0; y < view.height; y++) { final im = view.centerY + (y * invH - 0.5) * view.scale; final row = y * view.width * 4; for (var x = 0; x < view.width; x++) { final re = view.centerX + (x * invW - 0.5) * view.scale * aspect; var zr = 0.0, zi = 0.0, zr2 = 0.0, zi2 = 0.0; var i = 0; while (i < view.maxIter) { zr2 = zr * zr; zi2 = zi * zi; if (zr2 + zi2 > 4.0) break; zi = 2.0 * zr * zi + im; zr = zr2 - zi2 + re; i++; } final idx = row + x * 4; if (i >= view.maxIter) { out[idx + 3] = 255; continue; } final mag = math.sqrt(zr2 + zi2); var nu = i.toDouble(); if (mag > 1.0) { nu = i + 1.0 - math.log(math.log(mag) / ln2) / ln2; } final t = nu / view.maxIter; out[idx] = (255.0 * (0.5 + 0.5 * math.sin(3.0 + t * 18.0))).toInt(); out[idx + 1] = (255.0 * (0.5 + 0.5 * math.sin(3.6 + t * 18.0))).toInt(); out[idx + 2] = (255.0 * (0.5 + 0.5 * math.sin(4.2 + t * 18.0))).toInt(); out[idx + 3] = 255; } } return out; }