Last active
March 14, 2019 23:07
-
-
Save shiffman/13e4cdb72bdad5f4f3344552afa44645 to your computer and use it in GitHub Desktop.
PI Day
This file contains hidden or 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 = BigInteger.ZERO; | |
BigDecimal two = new BigDecimal(2); | |
PImage mandel; | |
void setup() { | |
size(1440,1080); | |
frameRate(60); | |
mandel = loadImage("mandelbrot.jpg"); | |
c = c.add(e, mc); | |
} | |
void draw() { | |
for (int i = 0; i < 25691; 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(mandel); | |
fill(255); | |
textSize(48); | |
textAlign(CENTER); | |
String s = iterations.toString(); | |
int diff = digits - s.length(); | |
for (int i = 0; i < diff; i++) { | |
s = '0' + s; | |
} | |
s = s.substring(0,1) + '.' + s.substring(1,s.length()); | |
text(s, width/2+250, height/2+textDescent()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment