前言:記得10年的時候我還在上學,有一天逛csdn看到了字符版的badapple,感受這東西好NB啊,而後就下載了一份,最近整理博客就把他整理博客,原做者是誰真心不知道,這是在果殼看到的.php
Bad Apple最初是做爲日本同人遊戲社團「上海愛莉絲幻樂團」所製做的「東方Project」系列遊戲背景音樂出現的。後來在日本著名視頻站點NicoVideo上有人萌發了爲此係列製做MADMovie的想法,最後有了這段3D製做的影繪風格視頻:編程
這段視頻由不斷變換的影繪風格遊戲人物組成,徹底黑白,視覺震撼力十足。此視頻在網絡上引起了一場宏大的運動,各類技術宅使用了各類方法來演奏這段三分多鐘長的視頻。網絡
看完本文後,你將能作出以下效果的視頻:
而輸出的字符須要從原始視頻獲取,將原始視頻壓縮成一個較低的分辨率,再獲取到每一幀上的全部像素點,轉換成對應的字符串。app
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 //獲取in目錄下全部文件 未做異常處理 6 string[] path = Directory.GetFileSystemEntries("in"); 7 8 //保存爲Gzip壓縮的文本流 9 FileStream fileStream = new FileStream("badapple.dat", FileMode.Create, FileAccess.Write); 10 GZipStream compressionStream = new GZipStream(fileStream, CompressionMode.Compress); 11 StreamWriter sw = new StreamWriter(compressionStream); 12 13 //遍歷每一個像素點 14 for (int x=0;x<path.Length;x++) 15 { 16 //Console.WriteLine(path[x]); 17 Bitmap bitmap = new Bitmap(path[x]); 18 19 for (int i = 0; i < bitmap.Height; i++) 20 { 21 for (int j = 0; j < bitmap.Width; j++) 22 { 23 Color color = bitmap.GetPixel(j, i); 24 if (color.R > 200) 25 { 26 //Console.Write("1"); 27 sw.Write(" "); 28 } 29 else 30 { 31 //Console.Write("0"); 32 sw.Write("#"); 33 } 34 } 35 //Console.WriteLine(); 36 sw.WriteLine(); 37 Console.Clear(); 38 Console.WriteLine("{0} of {1} completed! ",x,path.Length); 39 } 40 bitmap.Dispose(); 41 } 42 sw.Dispose(); 43 } 44 45 }
1 class Program 2 { 3 private static StreamReader reader; 4 static void Main(string[] args) 5 { 6 //打開壓縮文本流 7 FileStream fileStream = new FileStream("badapple.dat", FileMode.Open, FileAccess.Read); 8 GZipStream compressionStream = new GZipStream(fileStream, CompressionMode.Decompress); 9 reader = new StreamReader(compressionStream); 10 11 //初始化控制檯參數 12 Console.Title = "BadAppleSharp 0.1"; 13 Console.WindowWidth = 80; 14 Console.WindowHeight = 31; 15 16 //調用播放器播放背景音樂 17 WaveStream mp3Reader = new Mp3FileReader(@"BadApple.mp3"); 18 WaveStream pcmStreamer = WaveFormatConversionStream.CreatePcmStream(mp3Reader); 19 WaveStream blockAlignedStream = new BlockAlignReductionStream(pcmStreamer); 20 WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); 21 waveOut.Init(blockAlignedStream); 22 waveOut.Play(); 23 24 //初始化定時器 25 Timer timer = new Timer(55); 26 timer.Elapsed+=new ElapsedEventHandler(Render); 27 timer.Enabled = true; 28 29 Console.ReadKey(); 30 waveOut.Dispose(); 31 blockAlignedStream.Dispose(); 32 pcmStreamer.Dispose(); 33 mp3Reader.Dispose(); 34 } 35 36 //渲染一幀 37 public static void Render(Object sender,ElapsedEventArgs e) 38 { 39 { 40 Console.Clear(); 41 StringBuilder data=new StringBuilder(2500); 42 for (int i = 0; i < 30; i++) 43 { 44 data.Append(reader.ReadLine()); 45 } 46 Console.Write(data.ToString()); 47 } 48 49 } 50 }
程序及源代碼下載 (須要本機安裝.net2.0或以上運行環境)編程語言
轉載自果殼艾斯昆ide