void threadTileGenerator_main(object tileObject) { Tile tile = tileObject as Tile; if (!tile.TexturePainter.Lock(TextureLockMode.WriteOnly)) return; try { // generate Mandelbrot set int w = tile.TexturePainter.MipMapLevelWidth; double rx = tile.WindowRect.UpperLeftCorner.X; double rxu = tile.WindowRect.Width / w; int h = tile.TexturePainter.MipMapLevelHeight; double ry = tile.WindowRect.UpperLeftCorner.Y; double ryu = tile.WindowRect.Height / h; Color c = new Color(); int i; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { double ax0 = rx + x * rxu; double ay0 = ry + y * ryu; double ax1 = ax0; double ay1 = ay0; double ac = ax0 * ax0 + ay0 * ay0; for (i = 0; i < tile.MaxIterations && ac < 16; i++) { double ax2 = ax1 * ax1 - ay1 * ay1 + ax0; ay1 = 2 * ax1 * ay1 + ay0; ax1 = ax2; ac = ax1 * ax1 + ay1 * ay1; } if (i < tile.MaxIterations) c.Set((uint)(i * 0x0102f4)); else c.Set(0); tile.TexturePainter.SetPixel(x, y, c); } } } finally { tile.TexturePainter.Unlock(); tile.TextureIsReady = true; } }