// Copyright 2004, Boutell.Com, Inc. // Released under the terms of the GNU General Public License, // version 2 or later. import java.awt.image.BufferedImage; import java.awt.image.WritableRaster; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class FracsterCL { // creates a new image of the given width and height from the // given array of bytes public static BufferedImage makeImage(int[] pix, int width, int height) { BufferedImage bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); WritableRaster wr = bim.getWritableTile(0, 0); wr.setDataElements(0, 0, width, height, pix); bim.releaseWritableTile(0, 0); return bim; } public static void main(String[] args) { if(args.length != 7) { System.err.println("usage: FracsterCL w h x y d i filename.png"); System.exit(1); } try { int w = Integer.valueOf(args[0]).intValue(); int h = Integer.valueOf(args[1]).intValue(); MandelbrotSet mset = new MandelbrotSet(null, w * 2, h * 2, Double.valueOf(args[2]).doubleValue(), Double.valueOf(args[3]).doubleValue(), Double.valueOf(args[4]).doubleValue(), Integer.valueOf(args[5]).intValue()); mset.renderSet(); // create the new image, antialiased int pix[] = new int[w * h]; int y; for (y = 0; (y < h); y++) { int my = y << 1; int x; int mr = w * 2; for (x = 0; (x < w); x++) { int mx = x << 1; int red = ((mset.pix[my * mr + mx] & 0x00FF0000) + (mset.pix[my * mr + mx + 1] & 0x00FF0000) + (mset.pix[(my + 1) * mr + mx] & 0x00FF0000) + (mset.pix[(my + 1) * mr + mx + 1] & 0x00FF0000)) >> 18; int green = ((mset.pix[my * mr + mx] & 0x0000FF00) + (mset.pix[my * mr + mx + 1] & 0x0000FF00) + (mset.pix[(my + 1) * mr + mx] & 0x0000FF00) + (mset.pix[(my + 1) * mr + mx + 1] & 0x0000FF00)) >> 10; int blue = ((mset.pix[my * mr + mx] & 0x000000FF) + (mset.pix[my * mr + mx + 1] & 0x000000FF) + (mset.pix[(my + 1) * mr + mx] & 0x000000FF) + (mset.pix[(my + 1) * mr + mx + 1] & 0x000000FF)) >> 2; pix[y * w + x] = 0xFF000000 + (red << 16) + (green << 8) + blue; } } BufferedImage destIm = makeImage(pix, w, h); // save the result ImageIO.write(destIm, "png", new File(args[6])); } catch(IOException ie) { ie.printStackTrace(); } } }