| Parameter | Description | Range |
|---|---|---|
| width | Number of output image pixel width. | Limited to at least 50 and at most 2000. |
| height | Number of output image pixel height. | Limited to at least 50 and at most 2000. |
| mod | In modes product and sum fixed modulus for new composite number.In mode jacobi the parameter mod is the fixed number n in jacobi-symbol |
Limited to at least 1 and at most 10000 for all three modes. |
| norm | Mapping of input pixel (x,y) → norm(x,y) | Does not create a fractal image for (x,y) → x ⋅ y in modes product and sum. |
productpublic Color[][] product(final BiFunction<Long, Long, Long> fun, final long mod) {
final long[][] colors = new long[pixelWidth][pixelHeight];
java.util.stream.IntStream.range(1, pixelWidth + 1).parallel().forEach(i -> {
for(int j = 1; j <= pixelHeight; j++) {
final List<Long> primeFactors = new ArrayList<>();
final List<Integer> expFactors = new ArrayList<>(), preSortExpFactors = new ArrayList<>();
final Set<Long> visited = new HashSet<>();
final long normBuf = fun.apply((long)i, (long)j);
Map<Long, Integer> factors;
long oldNorm = normBuf, happy = 0;
if (normMap.containsKey(normBuf)) {
colors[i - 1][j - 1] = normMap.get(normBuf);
continue;
}
while (true) {
final long oldNormMod = Math.floorMod(oldNorm, mod);
if (visited.contains(oldNormMod)) {
happy = -1; // BLACK
break;
}
long norm = 1, normNoMod;
boolean modHit = false;
factors = factors(oldNormMod);
primeFactors.addAll(factors.keySet());
expFactors.addAll(factors.values());
preSortExpFactors.addAll(factors.values());
visited.add(oldNormMod);
Collections.sort(primeFactors);
Collections.sort(expFactors);
for (int k = 0; k < primeFactors.size(); k++) {
normNoMod = norm * pow(primeFactors.get(k), expFactors.get(k));
norm = Math.floorMod(norm * pow(primeFactors.get(k), expFactors.get(k)), mod);
if (normNoMod < norm) {
modHit = true;
}
}
if (norm == 0) {
happy = -3; // GRAY
break;
}
if (isPrime(norm)) {
happy = norm;
break;
}
if (preSortExpFactors.equals(expFactors)) {
happy = -2; // WHITE
break;
}
if (!modHit) { // mod did not hit -> cheat to get new prime factors
oldNorm = norm + 1;
primeFactors.clear();
expFactors.clear();
preSortExpFactors.clear();
continue;
}
oldNorm = norm;
primeFactors.clear();
expFactors.clear();
preSortExpFactors.clear();
}
colors[i - 1][j - 1] = happy;
normMap.put(normBuf, happy);
}
});
normMap.clear();
System.out.println(factors(mod));
return getSmoothColors(colors);
}
sumpublic Color[][] sum(final BiFunction<Long, Long, Long> fun, final long mod) {
final long[][] colors = new long[pixelWidth][pixelHeight];
final DoubleAdder progress = new DoubleAdder();
java.util.stream.IntStream.range(1, pixelWidth + 1).parallel().forEach(i -> {
for(int j = 1; j <= pixelHeight; j++) {
final List<Long> primeFactors = new ArrayList<>();
final List<Integer> expFactors = new ArrayList<>(), preSortExpFactors = new ArrayList<>();
final long normBuf = fun.apply((long)i, (long)j);
final Set<Long> visited = new HashSet<>();
Map<Long, Integer> factors;
long oldNorm = normBuf, happy = 0;
if (normMap.containsKey(normBuf)) {
colors[i - 1][j - 1] = normMap.get(normBuf);
continue;
}
while (true) {
final long oldNormMod = Math.floorMod(oldNorm, mod);
if (visited.contains(oldNormMod)) {
happy = -1; // BLACK
break;
}
long norm = 1;
factors = factors(oldNormMod);
primeFactors.addAll(factors.keySet());
expFactors.addAll(factors.values());
preSortExpFactors.addAll(factors.values());
visited.add(oldNormMod);
Collections.sort(primeFactors);
Collections.sort(expFactors);
for (int k = 0; k < primeFactors.size(); k++) {
norm += Math.floorMod(pow(primeFactors.get(k), expFactors.get(k)), mod);
}
if (norm == 0) {
happy = -3; // GRAY
break;
}
if (isPrime(norm)) {
happy = norm;
break;
}
if (preSortExpFactors.equals(expFactors)) {
happy = -2; // WHITE
break;
}
oldNorm = norm;
primeFactors.clear();
expFactors.clear();
preSortExpFactors.clear();
}
colors[i - 1][j - 1] = happy;
normMap.put(normBuf, happy);
}
});
normMap.clear();
System.out.println(factors(mod));
return getSmoothColors(colors);
}
jacobi This mode calculates the jacobi-symbol for pixel (x,y) and fixed (odd) modulus n =
https://en.wikipedia.org/wiki/Jacobi_symbol