-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolor2.c
51 lines (42 loc) · 1.33 KB
/
color2.c
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
int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
void api_closewin(int win);
void api_refreshwin(int win, int x0, int y0, int x1, int y1);
void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
void api_linewin(int win, int x0, int y0, int x1, int y1, int col);
int api_getkey(int mode);
void api_initmalloc(void);
char *api_malloc(int size);
void api_free(char *addr, int size);
void api_end(void);
unsigned char rgb2pal(int r, int g, int b, int x, int y);
void HariMain(void)
{
char *buf;
int win, x, y, r, g, b;
api_initmalloc();
buf = api_malloc(144 * 164);
win = api_openwin(buf, 144, 164, -1, "color2");
for (y = 0; y < 128; y++) {
for (x = 0; x < 128; x++) {
buf[(x + 8) + (y + 28) * 144] = rgb2pal(x * 2, y * 2, 0, x, y);
}
}
api_refreshwin(win, 8, 28, 136, 156);
api_getkey(1); /* キー入力でアプリ終了 */
api_end();
}
unsigned char rgb2pal(int r, int g, int b, int x, int y)
{
static int table[4] = {3, 1, 0, 2};
int i;
x &= 1; /* 偶数か奇数か */
y &= 1;
i = table[x + y * 2]; /* 中間色を作るための定数 */
r = (r * 21) / 256; /* これで 0〜20になる */
g = (g * 21) / 256;
b = (b * 21) / 256;
r = (r + i) / 4; /* これで 0〜5になる */
g = (g + i) / 4;
b = (b + i) / 4;
return 16 + r + g * 6 + b * 36;
}