1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

初めに

前回の記事で画像をアスキーアートに変換することができた。
これを応用すればコマンドプロプントで動画を見ることができるのでは?
と思い、前回作ったプログラムを改造してコマンドプロプントで動画を見れるようにしました。
前回の記事
https://qiita.com/syougo-916/items/0d63a5a90a94269a984a

このプログラムって何に役立つの?

何にも役に立ちません!ロマンです!!!

早速ソースコードどーん!

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


public class img2 {
	
	public static void printASCLL(String fileName) throws IOException{//ここの詳しいことは前回の記事参照
		BufferedImage bufferedImage  = ImageIO.read(new File(fileName));
		
		for(int i = 0; i < bufferedImage.getHeight();i = i + 2) {
			String str = "";
			for(int j = 0; j < bufferedImage.getWidth();j++) {
				int rgb = bufferedImage.getRGB(j, i);
				int red = (rgb >> 16) & 0xff;
				int gleen = (rgb >> 8) & 0xff;
				int blue = (rgb) & 0xff;
				
				double Y = red*0.299 + gleen*0.587 + blue*0.114;
				if(Y >= 200) {
					str += ".";
				}else if (Y >= 130){
					str += "^";
				}else if(Y >= 100){
					str += "*";
				}else {
					str += "#";
				}
			}
			System.out.println(str);
		}
	}
	public static void main(String[]args) throws IOException,InterruptedException{
		int frame = 441;//画像の枚数を指定
			for(int i = 1; i <= frame;i++) {
				String str = String.format("%04d", i) + ".png";//4桁の0埋めと拡張子
				img2.printASCLL(str);//上に書いてあるメソッド呼び出し
				Thread.sleep(16);//1 / フレームレート * 1000 ミリ秒時間を止める(この場合は60fps)
				if(i != frame) {
					System.out.printf("\033[2J");//コンソールクリア(最後のフレームはクリアしない)
				}


			}
		}
}

注意点

ソースコードを見て気が付いた人もいると思いますが、このプログラム動画ファイルには対応していません。
0001から始まるpng形式の連番にしないとこのプログラムは動きません。(動画編集ソフトでこんな感じに書き出しする必要あり)
image.png

うp主の技術力が向上すればこの問題は解決します。
あと、コマンドプロプントに文字を出力する処理がボトルネックになっているみたいで、小さい画像じゃないときれいに見えません。

実行結果

image.png
うp主がCGで作ったUbuntuのアニメーションをコマンドプロプントで再生してみました。
384*216ピクセルの60fpsです。
描画の遅れがすごく目立ち、画面がチカチカするので長時間見るのはお勧めしない。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?