A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
16
Task/Mandelbrot-set/D/mandelbrot-set-1.d
Normal file
16
Task/Mandelbrot-set/D/mandelbrot-set-1.d
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import std.stdio, std.complex;
|
||||
|
||||
void main() {
|
||||
enum maxIter = 1_000;
|
||||
foreach (y; -39 .. 39) {
|
||||
foreach (x; -39 .. 39) {
|
||||
auto c = complex(y/40.0 - 0.5, x/40.0),
|
||||
z = complex(0),
|
||||
i = 0;
|
||||
for (; i < maxIter && z.abs() < 4; i++)
|
||||
z = z ^^ 2 + c;
|
||||
write(i == maxIter ? '#' : ' ');
|
||||
}
|
||||
writeln();
|
||||
}
|
||||
}
|
||||
27
Task/Mandelbrot-set/D/mandelbrot-set-2.d
Normal file
27
Task/Mandelbrot-set/D/mandelbrot-set-2.d
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import qd;
|
||||
|
||||
double lensqr(cdouble c) { return c.re * c.re + c.im * c.im; }
|
||||
|
||||
const Limit = 150;
|
||||
|
||||
void main() {
|
||||
screen(640, 480);
|
||||
for (int y = 0; y < screen.h; ++y) {
|
||||
flip; events;
|
||||
for (int x = 0; x < screen.w; ++x) {
|
||||
auto
|
||||
c_x = x * 1.0 / screen.w - 0.5,
|
||||
c_y = y * 1.0 / screen.h - 0.5,
|
||||
c = c_y * 2.0i + c_x * 3.0 - 1.0,
|
||||
z = 0.0i + 0.0,
|
||||
i = 0;
|
||||
for (; i < Limit; ++i) {
|
||||
z = z * z + c;
|
||||
if (lensqr(z) > 4) break;
|
||||
}
|
||||
auto value = cast(ubyte) (i * 255.0 / Limit);
|
||||
pset(x, y, rgb(value, value, value));
|
||||
}
|
||||
}
|
||||
while (true) { flip; events; }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue