// does the sequence escape?
@Override
    public void run(Engine.Negative negative) { // TODO: Use "advanced probabilistic techniques".
        for (int i = 1; i <= TASK_SAMPLE_SIZE; i++) {
            int j, bufferX, bufferY; // location of (zR, zI) in histogram
            double cR, cI, zR, zI, p;
            // use ThreadLocalRandom for improved performance
            cR = zR = minX + ThreadLocalRandom.current().nextDouble(rangeX);
            cI = zI = minY + ThreadLocalRandom.current().nextDouble(rangeY);
            // check if the sequence generated by (cR, cI) escapes
            for (j = 0; j < iterationLimit; j++) {
                for (int k = 1; k < degree; k++) {
                    p = zR;
                    zR = zR * zR - zI * zI;
                    zI = 2 * p * zI;
                }
                zR += cR;
                zI += cI;
                if (zR * zR + zI * zI > escapeDistance * escapeDistance) {
                    break;
                }
            }
            if (j == iterationLimit) { // does the sequence escape?
                continue;
            }
            zR = cR;
            zI = cI;
            for (j = 0; j < iterationLimit; j++) {
                // Is the point within the rendering region?
                if (zR >= minX && zR - minX <= rangeX && zI >= minY && zI - minY <= rangeY) {
                    bufferX = (int) (((zR - minX) / rangeX) * negative.size.width);
                    bufferY = (int) (((zI - minY) / rangeY) * negative.size.height);
                    negative.buffer.setElem(bufferY * negative.size.width + bufferX,
                            negative.buffer.getElem(bufferY * negative.size.width + bufferX) + 1);
                }
                for (int k = 1; k < degree; k++) {
                    p = zR;
                    zR = zR * zR - zI * zI;
                    zI = 2 * p * zI;
                }
                zR += cR;
                zI += cI;
            }
        }
    }
}
}
if (j == iterationLimit) { // does the sequence escape?
continue;
}
p = zR;
zR = zR * zR - zI * zI;
zI = 2 * p * zI;
}
zR += cR;
zI += cI;
if (zR * zR + zI * zI > escapeDistance * escapeDistance) {
break;
}
}
if (j == iterationLimit) { // does the sequence escape?
continue;
}
zR = cR;
zI = cI;
for (j = 0; j < iterationLimit; j++) {
// Is the point within the rendering region?
if (zR >= minX && zR - minX <= rangeX && zI >= minY && zI - minY <= rangeY) {
bufferX = (int) (((zR - minX) / rangeX) * negative.size.width);
bufferY = (int) (((zI - minY) / rangeY) * negative.size.height);
negative.buffer.setElem(bufferY * negative.size.width + bufferX,
public void run(Engine.Negative negative) { // TODO: Use "advanced probabilistic techniques".
for (int i = 1; i <= TASK_SAMPLE_SIZE; i++) {
int j, bufferX, bufferY; // location of (zR, zI) in histogram
double cR, cI, zR, zI, p;
// use ThreadLocalRandom for improved performance
cR = zR = minX + ThreadLocalRandom.current().nextDouble(rangeX);
cI = zI = minY + ThreadLocalRandom.current().nextDouble(rangeY);
// check if the sequence generated by (cR, cI) escapes
for (j = 0; j < iterationLimit; j++) {
for (int k = 1; k < degree; k++) {
p = zR;
zR = zR * zR - zI * zI;
zI = 2 * p * zI;
}
zR += cR;
zI += cI;
if (zR * zR + zI * zI > escapeDistance * escapeDistance) {
break;
}
}
if (j == iterationLimit) { // does the sequence escape?
continue;
}
zR = cR;
zI = cI;
for (j = 0; j < iterationLimit; j++) {
// Is the point within the rendering region?
if (zR >= minX && zR - minX <= rangeX && zI >= minY && zI - minY <= rangeY) {
bufferX = (int) (((zR - minX) / rangeX) * negative.size.width);
bufferY = (int) (((zI - minY) / rangeY) * negative.size.height);
negative.buffer.setElem(bufferY * negative.size.width + bufferX,
negative.buffer.getElem(bufferY * negative.size.width + bufferX) + 1);
}
for (int k = 1; k < degree; k++) {
p = zR;
zR = zR * zR - zI * zI;
zI = 2 * p * zI;
}
zR += cR;
zI += cI;
}