48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System.Drawing;
|
|
// Note: You have to add the System.Drawing assembly
|
|
// (right-click "references," Add Reference, Assemblies, Framework,
|
|
// System.Drawing, OK)
|
|
using System.Linq;
|
|
|
|
namespace RosettaJuliaSet
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
const int w = 800;
|
|
const int h = 600;
|
|
const int zoom = 1;
|
|
const int maxiter = 255;
|
|
const int moveX = 0;
|
|
const int moveY = 0;
|
|
const double cX = -0.7;
|
|
const double cY = 0.27015;
|
|
double zx, zy, tmp;
|
|
int i;
|
|
|
|
var colors = (from c in Enumerable.Range(0, 256)
|
|
select Color.FromArgb((c >> 5) * 36, (c >> 3 & 7) * 36, (c & 3) * 85)).ToArray();
|
|
|
|
var bitmap = new Bitmap(w, h);
|
|
for (int x = 0; x < w; x++)
|
|
{
|
|
for (int y = 0; y < h; y++)
|
|
{
|
|
zx = 1.5 * (x - w / 2) / (0.5 * zoom * w) + moveX;
|
|
zy = 1.0 * (y - h / 2) / (0.5 * zoom * h) + moveY;
|
|
i = maxiter;
|
|
while (zx * zx + zy * zy < 4 && i > 1)
|
|
{
|
|
tmp = zx * zx - zy * zy + cX;
|
|
zy = 2.0 * zx * zy + cY;
|
|
zx = tmp;
|
|
i -= 1;
|
|
}
|
|
bitmap.SetPixel(x, y, colors[i]);
|
|
}
|
|
}
|
|
bitmap.Save("julia-set.png");
|
|
}
|
|
}
|
|
}
|