Monday, February 2, 2015

Fade.java in pgm



Fade.java

import java.awt.Color;
 public class Fade
{
             public static Color combine(Color c1, Color c2, double alpha)
    {
        int r = (int) (alpha * c1.getRed()   + (1 - alpha) * c2.getRed());
        int g = (int) (alpha * c1.getGreen() + (1 - alpha) * c2.getGreen());
        int b = (int) (alpha * c1.getBlue()  + (1 - alpha) * c2.getBlue());
        return new Color(r, g, b);
    }

    public static void main(String[] args)
            {
        int N = Integer.parseInt(args[0]);    
        Picture pic1 = new Picture(args[1]);  
        Picture pic2 = new Picture(args[2]);  
        int width  = pic1.width();
        int height = pic1.height();
        Picture pic = new Picture(width, height);
        for (int n = 0; n <= N; n++)
            {
            double alpha = 1.0 * n / N;
                 for (int i = 0; i < width; i++)
            {
                 for (int j = 0; j < height; j++)
            {
                    Color c1 = pic1.get(i, j);
                    Color c2 = pic2.get(i, j);
                    pic.set(i, j, combine(c2, c1, alpha));
                }
            }
            pic.show();
        }
    }
}

No comments:

Post a Comment