1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
void slice(int minY, int maxY) {
long double newReal, newImaginary, oldReal, oldImaginary;
long double pixelX, pixelY;
int iter, x, y;
Info.bmiHeader.biHeight = SliceSize;
COLORREF Colour;//Working colour
HDC threadDC = CreateCompatibleDC(hdc);
void *data;
HBITMAP hBitmap = CreateDIBSection(threadDC, &Info, DIB_RGB_COLORS, (void**)&data, 0, 0);
SelectObject(threadDC, hBitmap);// Select it into the alternate (threading) DC
for (y = minY; y < maxY; y++) {
pixelY = (y - halfheight) / (zoom * halfheight) + moveY;
for (x = 0; x < width; x++) {
pixelX = 1.5 * (x - halfwidth) / (zoom * halfwidth) + moveX;
newReal = newImaginary = 0; //these should start at zero Z = Z * Z + C
for (iter = 0; iter < maxIterations; iter++) {
oldReal = newReal; oldImaginary = newImaginary;
newReal = oldReal * oldReal - oldImaginary * oldImaginary + pixelX;
newImaginary = 2 * oldReal * oldImaginary + pixelY;
if ((newReal * newReal + newImaginary * newImaginary) > 4) {
break;
}
}
if (iter < maxIterations) {
Colour = Colours[iter % 306];
} else {
Colour = BLACK;
}
SetPixel(threadDC, x, y % SliceSize, Colour);
}//End of for(x (width loop).
MSG msg;
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}//End of for(y (height loop)
BitBlt(hdc, 0, minY, width, maxY, threadDC, 0, 0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(threadDC);
}
|