-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
40 lines (34 loc) · 1.06 KB
/
Program.cs
File metadata and controls
40 lines (34 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Drawing;
class Program
{
static void Main(string[] args)
{
string imagePath = "5382153446129525112_99.jpg";
Bitmap bitmap = new Bitmap(imagePath);
for (int y = 0; y < bitmap.Height; y += 6)
{
for (int x = 0; x < bitmap.Width; x += 3)
{
Color pixelColor = bitmap.GetPixel(x, y);
char asciiChar = GetAsciiChar(pixelColor);
SetConsoleColor(pixelColor);
Console.Write(asciiChar);
}
Console.WriteLine();
}
Console.ResetColor();
}
static char GetAsciiChar(Color color)
{
int brightness = (int)(0.2126 * color.R + 0.7152 * color.G + 0.0722 * color.B);
string chars = "@%#*+=-:. ";
int index = (brightness * (chars.Length - 1)) / 255;
return chars[chars.Length - 1 - index];
}
static void SetConsoleColor(Color color)
{
string ansiColor = $"\x1b[38;2;{color.R};{color.G};{color.B}m";
Console.Write(ansiColor);
}
}