-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
125 lines (105 loc) · 3.73 KB
/
Program.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace FlakeGen
{
//14x12
class Program
{
private static void drawTextProgressBar(int progress, int total)
{
//draw empty progress bar
Console.CursorLeft = 0;
Console.Write("["); //start
Console.CursorLeft = 32;
Console.Write("]"); //end
Console.CursorLeft = 1;
float onechunk = 30.0f / total;
//draw filled part
int position = 1;
for (int i = 0; i < onechunk * progress; i++)
{
Console.CursorLeft = position++;
Console.Write("=");
}
Console.CursorLeft = position++;
Console.Write(">");
//draw unfilled part
for (int i = position; i <= 31; i++)
{
Console.CursorLeft = position++;
Console.Write(" ");
}
//draw totals
Console.CursorLeft = 35;
Console.Write("Processing line " + progress.ToString() + " of " + total.ToString()); //blanks at the end remove any excess
}
static int[,] d = {
{0,0,0,1,1,1,1,1,1,1,1,0,0,0 },
{0,0,1,1,1,1,1,1,1,1,1,1,0,0 },
{0,0,1,1,1,1,1,1,1,1,1,1,0,0 },
{0,1,1,1,1,1,1,1,1,1,1,1,1,0 },
{0,1,1,1,1,1,1,1,1,1,1,1,1,0 },
{1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{0,1,1,1,1,1,1,1,1,1,1,1,1,0 },
{0,1,1,1,1,1,1,1,1,1,1,1,1,0 },
{0,0,1,1,1,1,1,1,1,1,1,1,0,0 },
{0,0,1,1,1,1,1,1,1,1,1,1,0,0 },
{0,0,0,1,1,1,1,1,1,1,1,0,0,0 }
};
static void Main(string[] args)
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);
Console.CursorVisible = false;
string[] lines = File.ReadAllLines("example.txt");
//string[] lines = new string[4];
//lines[0] = "3";
//lines[1] = "0\t255\t255";
//lines[2] = "255\t255\t255";
//lines[3] = "0\t255\t255";
string ws = lines[0];
int w;
int.TryParse(ws, out w);
Bitmap bm = new Bitmap((int)((w + 0.5) * 12), w * 11 + 3);
Graphics gp = Graphics.FromImage(bm);
gp.Clear(Color.Black);
for (int j = 0; j < w; j++)
{
drawTextProgressBar(j, w);
string[] row = lines[j + 1].Split('\t');
for (int i = 0; i < w; i++)
{
int g;
int.TryParse(row[i], out g);
if (g > 255)
g = 255;
Color col = Color.FromArgb(g, g, g);
int x = i * 12 + (6 * (j % 2));
int y = j * 11;
for (int pj = 0; pj < 14; pj++)
{
for (int pi = 0; pi < 12; pi++)
{
if (d[pi, pj] == 1)
bm.SetPixel(x + pi, y + pj, col);
}
}
}
}
string dt = DateTime.Now.ToString();
dt = dt.Replace(".","");
dt = dt.Replace(":", "");
dt = dt.Replace(" ", "-");
bm.Save("snowflake-"+ dt +".png");
}
static void OnProcessExit(object sender, EventArgs e)
{
Console.CursorVisible = true;
}
}
}