@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;
            }
        }
    }
@Override
    public void run(Engine.Negative negative) {
        for (int i = 1; i <= TASK_SAMPLE_SIZE; i++) {
            int j, bufferX, bufferY;
            double cR, cI, zR, zI, p;
           
            cR = zR = minX + ThreadLocalRandom.current().nextDouble(rangeX);
            cI = zI = minY + ThreadLocalRandom.current().nextDouble(rangeY);
           
            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) {
                continue;
            }
            zR = cR;
            zI = cI;
            for (j = 0; j < iterationLimit; j++) {
               
                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;
            }
        }
    }
@override public void run(engine.negative negative) { for (int i = 1; i <= task_sample_size; i++) { int j, bufferx, buffery; double cr, ci, zr, zi, p; cr = zr = minx + threadlocalrandom.current().nextdouble(rangex); ci = zi = miny + threadlocalrandom.current().nextdouble(rangey); 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) { continue; } zr = cr; zi = ci; for (j = 0; j < iterationlimit; j++) { 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; } } }