forked from interl0per/Console-Graphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASCIIRender.cs
More file actions
60 lines (56 loc) · 1.91 KB
/
ASCIIRender.cs
File metadata and controls
60 lines (56 loc) · 1.91 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Drawing;
using System.IO;
namespace ConsoleGraphics
{
class ASCIIRender
//convert textures
{
public static char[] levels;
public static Bitmap image1;
public static byte[,] bitmapColorsCached;
public static void bt()
{
StreamReader r = new StreamReader("levels.txt");
levels = new char[256];
int index = 0;
while (!r.EndOfStream && index < 256)
{
string e1 = r.ReadLine();
levels[index] = Char.Parse(e1);
index++;
}
image1 = (Bitmap)Image.FromFile(@"Lenna.bmp", true);//load character set (digits 1->9..)
const int WIDTH = 1;
const int HEIGHT = 1;
bitmapColorsCached = new byte[image1.Width, image1.Height];
char[,] shaded = new char[40, 50];
for (int i = 0; i < image1.Width; i += WIDTH)
{
for (int j = 0; j < image1.Height; j += HEIGHT)
{
int sum = 0;
for (int i1 = i; i1 < i + WIDTH; i1++)
{
for (int j1 = j; j1 < j + HEIGHT; j1++)
{
Color c = image1.GetPixel(i1, j1);
sum += c.R + c.B + c.G;
}
}
sum /= WIDTH * HEIGHT * 3;
// Console.Write(levels[sum]);
}
// Console.WriteLine();
}
for (int i = 0; i < image1.Width; i++)
for (int j = 0; j < image1.Height; j++)
{
Color c = image1.GetPixel(i, j);
bitmapColorsCached[i, j] = (byte)((c.R + c.B + c.G) / 3);
}
}
}
}