aboutsummaryrefslogtreecommitdiff
path: root/content/notes/drawing-pixels-in-plan9.md
blob: d903675c6add5e4dd03b4916035513df7da016ef (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
---
title: "Drawing Pixels in Plan9"
url: drawing-pixels-in-plan9.html
date: 2023-05-27T17:41:33+02:00
type: notes
draft: false
tags: [plan9, graphics]
---

I have started exploring Plan9's graphics capabilities. This is a hello world
alternative for drawing that draws a yellow square on a blue background.

![Plan9 Howdy World!](/notes/plan9-pixels.png)

```c
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <cursor.h>

void main(int argc, char *argv[])
{
  ulong co;
  Image *im, *bg;
  co = 0xFF0000FF;

  if (initdraw(nil, nil, argv0) < 0)
  {
    sysfatal("%s: %r", argv0);
  }

  im = allocimage(display, Rect(0, 0, 100, 100), RGB24, 0, DYellow);
  bg = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, co);

  if (im1 == nil || bg == nil)
  {
    sysfatal("get more memory, bub");
  }

  draw(screen, screen->r, bg, nil, ZP);
  draw(screen, screen->r, im, nil, Pt(-40, -40));

  flushimage(display, Refnone);

  // Wait 10 seconds before exiting.
  sleep(10000);

  exits(nil);
}
```

And then compile with Makefile:

```makefile
</$objtype/mkfile

RC=/rc/bin
BIN=/$objtype/bin
MAN=/sys/man

main:
	$CC $CFLAGS main.c
	$LD $LDFLAGS -o main main.$O
```

*This is **very cool** indeed!*