Mandelbrot set: Difference between revisions

Content added Content deleted
m (Replace deprecated functions)
m (→‎{{header|Dart}}: Minor updates to reflect current Dart usage.)
Line 5,016: Line 5,016:


=={{header|Dart}}==
=={{header|Dart}}==
Implementation in Google Dart works on http://try.dartlang.org/ (as of 10/18/2011) since the language is very new, it may break in the future.
Implementation in Dart, works on https://dartpad.dev
The implementation uses a incomplete Complex class supporting operator overloading.
The implementation uses an incomplete Complex class supporting operator overloading.
<syntaxhighlight lang="dart">class Complex {
<syntaxhighlight lang="dart">
class Complex {
double _r,_i;
double _r, _i;


Complex(this._r,this._i);
Complex(this._r, this._i);
double get r => _r;
get r => _r;
double get i => _i;
get i => _i;
String toString() => "($r,$i)";
toString() => "($r,$i)";


Complex operator +(Complex other) => new Complex(r+other.r,i+other.i);
operator +(Complex other) => Complex(r + other.r, i + other.i);
Complex operator *(Complex other) =>
operator *(Complex other) =>
new Complex(r*other.r-i*other.i,r*other.i+other.r*i);
Complex(r * other.r - i * other.i, r * other.i + other.r * i);
double abs() => r*r+i*i;
abs() => r * r + i * i;
}
}


void main() {
void main() {
double start_x=-1.5;
const startX = -1.5;
double start_y=-1.0;
const startY = -1.0;
double step_x=0.03;
const stepX = 0.03;
double step_y=0.1;
const stepY = 0.1;


for(int y=0;y<20;y++) {
for (int y = 0; y < 20; y++) {
String line="";
String line = "";
for(int x=0;x<70;x++) {
for (int x = 0; x < 70; x++) {
Complex c=new Complex(start_x+step_x*x,start_y+step_y*y);
var c = Complex(startX + stepX * x, startY + stepY * y);
Complex z=new Complex(0.0, 0.0);
var z = Complex(0.0, 0.0);
for(int i=0;i<100;i++) {
for (int i = 0; i < 100; i++) {
z=z*(z)+c;
z = z * z + c;
if(z.abs()>2) {
if (z.abs() > 2) {
break;
break;
}
}
}
}
line+=z.abs()>2 ? " " : "*";
line += z.abs() > 2 ? " " : "*";
}
}
print(line);
print(line);
}
}
}
}</syntaxhighlight>

</syntaxhighlight>


=={{header|Dc}}==
=={{header|Dc}}==