Mandelbrot set: Difference between revisions

m
→‎{{header|Dart}}: Minor updates to reflect current Dart usage.
m (Replace deprecated functions)
m (→‎{{header|Dart}}: Minor updates to reflect current Dart usage.)
Line 5,016:
 
=={{header|Dart}}==
Implementation in Google Dart, works on httphttps://try.dartlang.org/ (as of 10/18/2011) since the language is very new, it may break in the futuredartpad.dev
The implementation uses aan incomplete Complex class supporting operator overloading.
<syntaxhighlight lang="dart">class Complex {
class Complex {
double _r, _i;
 
Complex(this._r, this._i);
double get r => _r;
double get i => _i;
String toString() => "($r,$i)";
 
Complex operator +(Complex other) => new Complex(r + other.r, i + other.i);
Complex operator *(Complex other) =>
new Complex(r * other.r - i * other.i, r * other.i + other.r * i);
double abs() => r * r + i * i;
}
 
void main() {
doubleconst startX start_x= -1.5;
doubleconst startY start_y= -1.0;
doubleconst stepX step_x= 0.03;
doubleconst stepY step_y= 0.1;
 
for (int y = 0; y < 20; y++) {
String line = "";
for (int x = 0; x < 70; x++) {
Complexvar c =new Complex(start_xstartX +step_x stepX * x,start_y startY +step_y stepY * y);
Complexvar z =new Complex(0.0, 0.0);
for (int i = 0; i < 100; i++) {
z = z *( z) + c;
if (z.abs() > 2) {
break;
}
}
line += z.abs() > 2 ? " " : "*";
}
print(line);
}
}
}</syntaxhighlight>
 
}</syntaxhighlight>
 
=={{header|Dc}}==
158

edits