Skip to content

Instantly share code, notes, and snippets.

@j-mcc1993
Created June 27, 2014 05:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-mcc1993/ef75a9227eeac139ee94 to your computer and use it in GitHub Desktop.
Save j-mcc1993/ef75a9227eeac139ee94 to your computer and use it in GitHub Desktop.
Java Fractal Image Generator
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
public class Fractal {
public static void main(String[] args) {
int width = 2048/2;
int height = 1536/2;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, (x-y)*(x+y)&(x|y));
}
}
File img = new File("Desktop.png");
try {
ImageIO.write(image, "png", img);
} catch (IOException e) {}
}
}
@j-mcc1993
Copy link
Author

Play around with line 13 to generate different fractals, the idea here is that allowing the color at each pixel to be determined by performing a bitwise boolean operation on the coordinates of that pixel generates a fractal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment