summaryrefslogtreecommitdiff
path: root/colgrad.c
blob: a122a4937b238e379cbece60532acd75ac361f83 (plain)
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
#include <u.h>
#include <libc.h>
#include <draw.h>

enum { SEC = 1000 };

enum {
	Cred,
	Cgrn,
	Cblu,

	Cgx,
	Cgy,
	Cend
};
Image *col[Cend];

int dx, dy;

void *
emalloc(ulong n)
{
	void *p;

	p = malloc(n);
	if(p == nil)
		sysfatal("malloc: %r");
	memset(p, 0, n);
	setmalloctag(p, getcallerpc(&n));
	return p;
}

Image *
eallocimage(Display *d, Rectangle r, ulong chan, int repl, ulong col)
{
	Image *i;

	i = allocimage(d, r, chan, repl, col);
	if(i == nil)
		sysfatal("allocimage: %r");
	return i;
}

void
usage(void)
{
	fprint(2, "usage: colgrad\n");
	exits("usage");
}

void
main(int argc, char *argv[])
{
	int i;
	uchar *gx, *gy;

	ARGBEGIN{
	default: usage();
	}ARGEND;

	if(initdraw(nil, nil, "colgrad") < 0)
		sysfatal("initdraw: %r");
	dx = Dx(screen->r), dy = Dy(screen->r);
	col[Cred] = eallocimage(display, Rect(0, 0, 1, 1), RGB24, 1, DRed);
	col[Cgrn] = eallocimage(display, Rect(0, 0, 1, 1), RGB24, 1, DGreen);
	col[Cblu] = eallocimage(display, Rect(0, 0, 1, 1), RGB24, 1, DBlue);
	col[Cgx] = eallocimage(display, Rect(0, 0, dx, 1), GREY8, 1, DNofill);
	col[Cgy] = eallocimage(display, Rect(0, 0, 1, dy), GREY8, 1, DNofill);
	gx = emalloc(dx);
	gy = emalloc(dy);
	for(i = 0; i < dx; i++)
		gx[i] = 255.0 * i/(dx-1);
	for(i = 0; i < dy; i++)
		gy[i] = 255.0 * i/(dy-1);
	loadimage(col[Cgx], col[Cgx]->r, gx, dx);
	loadimage(col[Cgy], col[Cgy]->r, gy, dy);
	draw(screen, screen->r, col[Cred], nil, ZP);
	draw(screen, screen->r, col[Cgrn], col[Cgx], ZP);
	draw(screen, screen->r, col[Cblu], col[Cgy], ZP);
	flushimage(display, 1);
	sleep(5*SEC);
	exits(0);
}