-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathascii.c
More file actions
116 lines (100 loc) · 2.36 KB
/
ascii.c
File metadata and controls
116 lines (100 loc) · 2.36 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
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define sz 1024
static char image [sz] [sz];
static void clear (void)
{
int x, y;
for (y = 0; y < sz; y ++)
for (x = 0; x < sz; x ++)
image [y] [x] = ' ';
}
static void print (void)
{
int x, y;
int minx = sz, miny = sz, maxx = -1, maxy = -1;
for (y = 0; y < sz; y ++)
for (x = 0; x < sz; x ++)
if (image [y] [x] != ' ')
{
if (x < minx)
minx = x;
if (y < miny)
miny = y;
if (x > maxx)
maxx = x;
if (y > maxy)
maxy = y;
}
for (y = maxy; y >= miny; y --)
{
printf ("; ");
for (x = minx; x <= maxx; x ++)
printf ("%c", image [y] [x]);
printf ("\n");
}
}
static void putpixel (int x, int y, int c)
{
//printf ("%d %d %d\n", x, y, c);
int xp = x + sz / 2;
int yp = y + sz / 2;
if (xp < 0 || xp >= sz || yp < 0 || yp >= sz)
printf ("%d %d %d\n", x, y, c);
else
image [yp] [xp] = '*';
}
static void draw (int x1, int y1, int x2, int y2, int c)
{
float x, y, xinc, yinc, dx, dy;
int k;
int step;
dx = x2 - x1;
dy = y2 - y1;
if (abs (dx) > abs (dy))
step = abs (dx);
else
step = abs (dy);
xinc = dx / step;
yinc = dy / step;
x = x1;
y = y1;
putpixel (x, y, c);
for (k = 1; k <= step; k++)
{
x = x + xinc;
y = y + yinc;
putpixel (x, y, c);
}
}
int main (int argc, char * argv [])
{
char buf [256], cmd [256];
int p1, p2, p3;
int x = 0, y = 0;
int scale = 1;
char * cp;
if (argc == 2)
scale = atoi (argv [1]);
printf ("%d\n", scale);
clear ();
while (! feof (stdin))
{
fgets (buf, 256, stdin);
if ((cp = strstr (buf, "stat")))
strncpy (cp, " 2", 4);
sscanf (buf, "%s%d,%d,%d", cmd, & p1, & p2, &p3);
//printf ("<%s> <%d> <%d> <%d>\n", cmd, p1, p2, p3);
if (strcmp (cmd, "vsdraw") == 0 || strcmp (cmd, "vldraw") == 0)
{
//printf ("draw %d %d %d\n", p1, p2, p3);
if (p3)
draw (x/scale, y/scale, (x + p1)/scale, (y + p2)/scale, p3);
x = x + p1;
y = y + p2;
}
}
print ();
return 0;
}