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 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
void slice(int minY, int maxY) {//Routine now set to do a horizontal "slice" for multhreading :)
long double newReal, newImaginary, oldReal, oldImaginary;//real and imaginary parts of new and old
long double pixelX, pixelY;//real and imaginary parts of the pixel p
int iter, y, x;
COLORREF Colour;//Working colour
for (y = minY; y < maxY; y++) {//Change this to a slice - 180 horizontal lines....
pixelY = (y - halfheight) / (zoom * halfheight) + moveY;//calculate (Only ONCE per y) the real part of Z, based on the pixel location, zoom and position values
for (x = 0; x < width; x++) {
pixelX = 1.5 * (x - halfwidth) / (zoom * halfwidth) + moveX; //calculate the imaginary part of Z, based on the pixel location, zoom and position values
newReal = newImaginary = 0; //these should start at zero
for (iter = 0; iter < maxIterations; iter++) {//start the iteration (escape) process
oldReal = newReal; oldImaginary = newImaginary;//remember value of previous iteration
newReal = oldReal * oldReal - oldImaginary * oldImaginary + pixelX;//The real and imaginary
newImaginary = 2 * oldReal * oldImaginary + pixelY; //parts are calculated
if ((newReal * newReal + newImaginary * newImaginary) > 4) {//if the point is outside the circle with radius 2, it is escaping - stop
break;
}
}
if (iter < maxIterations) {// Escaped?
Colour = Colours[iter % 306];
} else {
Colour = BLACK; //Else BLACK
}
SetPixel(hdc, x, y, Colour);
}//End of for(x (width loop)
}//End of for(y (height loop)
}
void Mandelbrot() {
int maxIterations = 2000;//is about the best for zoom 1?
long double zoom = 1.0E11;//These are correctly defined as "global" "read" only
long double moveX = 0.2574028981414269373;
long double moveY = 0.49283797442133693981;
begintime = clock();//Start the clock
thread t1(slice, 0, 1080);//Single thread works
//thread t1(slice, 0, 180);
//thread t2(slice, 180, 360);
//thread t3(slice, 360, 540);//If more than 1 thread
//thread t4(slice, 540, 720);//activated - corrupt display
//thread t5(slice, 720, 900);
//thread t6(slice, 900, 1080);
t1.join();
//t2.join();
//t3.join();
//t4.join();
//t5.join();
//t6.join();
//slice(0, 180);
//slice(180, 360);
//slice(360, 540);//Straight methods
//slice(540, 720);//not threaded - works
//slice(720, 900);
//slice(900, 1080);
}
|