Created
September 20, 2015 05:29
-
-
Save rockdrigo/9a8ead06a0f50f40b2fa to your computer and use it in GitHub Desktop.
Programa que genera imagen con fractal de Mandelbrot
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.awt.Color; | |
import java.io.File; | |
import java.awt.image.BufferedImage; | |
import javax.imageio.ImageIO; | |
public class MandelbrotColor { | |
public static void main(String[] args) throws Exception { | |
int width = 1920, height = 1080, max = 1000; | |
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); | |
int black = 0; | |
int[] colors = new int[max]; | |
for (int i = 0; i<max; i++) { | |
colors[i] = Color.HSBtoRGB(i/256f, 1, i/(i+8f)); | |
} | |
for (int row = 0; row < height; row++) { | |
for (int col = 0; col < width; col++) { | |
double c_re = (col - width/2)*4.0/width; | |
double c_im = (row - height/2)*4.0/width; | |
double x = 0, y = 0; | |
double r2; | |
int iteration = 0; | |
while (x*x+y*y < 4 && iteration < max) { | |
double x_new = x*x-y*y+c_re; | |
y = 2*x*y+c_im; | |
x = x_new; | |
iteration++; | |
} | |
if (iteration < max) image.setRGB(col, row, colors[iteration]); | |
else image.setRGB(col, row, black); | |
} | |
} | |
ImageIO.write(image, "png", new File("mandelbrot.png")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fail
https://github.com/fogleman/Fractal/blob/master/fractal.c