Created
March 14, 2019 20:57
-
-
Save SolarLiner/7c673bc60ff300ba732d271b38226a9c to your computer and use it in GitHub Desktop.
Mandelbrodt, but with bigger ints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigDecimal; | |
import java.math.BigInteger; | |
import java.math.MathContext; | |
int digits = 11; | |
MathContext mc = new MathContext(digits*digits + 1); | |
BigDecimal c = new BigDecimal(0.25); | |
BigDecimal hundred = new BigDecimal(100); | |
BigDecimal e = BigDecimal.ONE.divide(hundred.pow(digits-1), mc); | |
BigDecimal z = BigDecimal.ZERO; | |
BigInteger iterations = new BigInteger((int)(pow(2, 32))); | |
BigDecimal two = new BigDecimal(2); | |
void setup() { | |
size(1440, 1080); | |
c = c.add(e, mc); | |
} | |
void draw() { | |
for (int i = 0; i < 10691; i++) { | |
if (z.compareTo(two) == -1) { | |
z = z.multiply(z, mc); | |
z = z.add(c, mc); | |
//if (iterations % 10000 == 0 || z.compareTo(two) == 1) { | |
//println(z.toString()); | |
iterations = iterations.add(BigInteger.ONE); | |
} else { | |
noLoop(); | |
break; | |
} | |
} | |
background(0); | |
fill(255); | |
textSize(48); | |
textAlign(CENTER); | |
text(iterations.toString(), width/2+250, height/2+textDescent()); | |
} | |
String padLeftZeros(String inputString, int length) { | |
if (inputString.length() >= length) { | |
return inputString; | |
} | |
StringBuilder sb = new StringBuilder(); | |
while (sb.length() < length - inputString.length()) { | |
sb.append('0'); | |
} | |
sb.append(inputString); | |
return sb.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment