public void exportAnimation(File file, int delay) {
        AnimatedGifEncoder encoder = new AnimatedGifEncoder();
        encoder.setRepeat(0);
        encoder.setDelay(delay);
        Color transparentColour = new Color(255, 0, 128);
        encoder.setTransparent(transparentColour);
        encoder.start(file.getPath());
        BufferedImage[] renderedImages = renderFrames();
        for (BufferedImage image : renderedImages) {
            BufferedImage frame = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
            for (int x = 0; x < image.getWidth(); x++) {
                for (int y = 0; y < image.getHeight(); y++) {
                    int pixel = image.getRGB(x, y);
                    int alpha = (pixel >> 24) & 0xff;
                    int red = (pixel >> 16) & 0xff;
                    int green = (pixel >> 8) & 0xff;
                    int blue = pixel & 0xff;
                    if (alpha == 0) {
                        frame.setRGB(x, y, (transparentColour.getRed() << 16) | (transparentColour.getGreen() << 8) | transparentColour.getBlue());
                    } else {
                        frame.setRGB(x, y, (red << 16) | (green << 8) | blue);
                    }
                }
            }
            encoder.addFrame(frame);
        }
        encoder.finish();
        for (BufferedImage image : renderedImages) {
            image.flush();
        }
    }