BadApple 아스키아트 만들기 with C#

Osori·2021년 4월 13일
0

심심해서 만들어보았다. 코드는 아래 첨부. 일본어 노래가 나오니 싫어하시는 분들은 주의!

팟플레이어를 이용해 영상을 1프레임씩 캡쳐해서 이를 읽어서 아스키아트로 만드는 내용이다.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            const String path = "C:\\badapple";
            String [] buf = new String[6543];
            int size = 0;
            Console.SetWindowSize(160, 60);
            Parallel.For(0, 6542, (i) =>
            {
                StringBuilder builder = new StringBuilder("", 6300);
                Bitmap old = new Bitmap(path + "\\1 (" + (i + 1).ToString() + ").jpg");
                Bitmap bitmap = new Bitmap(old, new Size(80, 60));
                for (int y = 0; y < bitmap.Height; y++)
                {
                    for (int x = 0; x < bitmap.Width; x++)
                    {
                        Color color = bitmap.GetPixel(x, y);
                        if (color.R >= 180) //흰색 
                        {
                            builder.Append("00");
                        }
                        else if(color.R>=90)
                        {
                            builder.Append("//");
                        }
                        else if(color.R>=40)
                        {
                            builder.Append("..");
                        }
                        else
                        {
                            builder.Append("  ");
                        }
                    }
                    builder.Append('\n');
                }
                buf[i] = builder.ToString();
                old.Dispose();
                bitmap.Dispose();
                size += buf[i].Length;
            });
           

            Console.WriteLine("Press Any Key To Start!");
            Console.WriteLine("Size : " + size);
            Console.ReadLine();
            Stopwatch sw = new Stopwatch();
            sw.Start();
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;

            while (true)
            {
                sw.Stop();
                int a = (int)(sw.ElapsedMilliseconds * 0.03); //프레임 맞추기용
                sw.Start();
                
                if (a >= buf.Length)
                    break;
                Console.WriteLine(buf[a]);
                Console.SetCursorPosition(0, 0);
            }
           
        }
    }
}
profile
해킹, 리버싱, 게임 좋아합니다

0개의 댓글