-
-
Save SolarLiner/d9e9cd241d44068e3f443159743eed1a to your computer and use it in GitHub Desktop.
PI Day
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.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; | |
int iterations = 0; | |
BigDecimal two = new BigDecimal(2); | |
PImage mandel; | |
void setup() { | |
size(1440,1080); | |
mandel = loadImage("mandelbrot.jpg"); | |
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++; | |
} else { | |
noLoop(); | |
break; | |
} | |
} | |
background(mandel); | |
fill(255); | |
textSize(48); | |
textAlign(CENTER); | |
text(nf(iterations,digits), width/2+250, height/2+textDescent()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment