私のプロンプトは次のとおりです。
いくつかの画像ファイルの名前をコマンド ライン引数として受け取り、それらをスライド ショー (2 秒ごとに 1 つずつ) で表示するプログラムを作成し、画像間の黒へのフェード効果と黒からのフェード効果を使用します。
画像がフェードする部分がありますが、すべての画像を 1 つのウィンドウの下に保持するという問題があります。たとえば、プログラムを実行すると、新しいウィンドウが開きます-画像Aが黒い画像にフェードします。黒い画像で新しいウィンドウを開き、画像 c にフェードします。写真Aから始めて黒くフェードし、新しいウィンドウを開かずに新しい写真にフェードインしようとしています。pic.show() コードに関係していることはわかっていますが、これを修正する方法がわかりません。
これが私のコードです:
package fade;
import edu.princeton.cs.introcs.Picture;
import java.awt.Color;
public class Fade {
public static Color blend(Color c, Color d, double alpha) {
double r = (1 - alpha) * c.getRed() + alpha * d.getRed();
double g = (1 - alpha) * c.getGreen() + alpha * d.getGreen();
double b = (1 - alpha) * c.getBlue() + alpha * d.getBlue();
return new Color((int) r, (int) g, (int) b);
}
public static void pause(int t) {
try { Thread.sleep(t); }
catch (InterruptedException e) { System.out.println("Error sleeping"); }
}
public static void main(String[] args) {
for (int k = 1; k < args.length; k++) {
Picture source = new Picture(args[k]);
Picture target = new Picture(args[0]);
int M = 100;
int width = source.width();
int height = source.height();
Picture pic = new Picture(width, height);
for (int t = 0; t <= M; t++) {
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
Color c0 = source.get(i, j);
Color cM = target.get(i, j);
Color c = blend(c0, cM, (double) t / M);
pic.set(i, j, c);
}
}
pic.show();
}
}
}
}