import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class SaveToGIF {
final static int WIDTH = 50;
final static int HEIGHT = 50;
final static int NUM_ITER = 1500;
public static void main(String[] args) throws Exception {
BufferedImage bi;
bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
for (int i = 0; i < NUM_ITER; i++) {
g.setColor(Color.RED);
g.drawLine(1, 2, i, i + 1);
}
g.dispose();
ImageIO.write(bi, "gif", new File("image.gif"));
}
}