aboutsummaryrefslogtreecommitdiff
path: root/content/notes/2023-05-27-drawing-pixels-in-plan9.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/notes/2023-05-27-drawing-pixels-in-plan9.md')
-rw-r--r--content/notes/2023-05-27-drawing-pixels-in-plan9.md82
1 files changed, 82 insertions, 0 deletions
diff --git a/content/notes/2023-05-27-drawing-pixels-in-plan9.md b/content/notes/2023-05-27-drawing-pixels-in-plan9.md
new file mode 100644
index 0000000..5b5115d
--- /dev/null
+++ b/content/notes/2023-05-27-drawing-pixels-in-plan9.md
@@ -0,0 +1,82 @@
1---
2title: "Drawing Pixels in Plan9"
3url: /drawing-pixels-in-plan9.html
4date: 2023-05-27T17:41:33+02:00
5type: note
6draft: false
7---
8
9I have started exploring Plan9's graphics capabilities. This is a hello world
10alternative for drawing that draws a yellow square on a blue background.
11
12More information:
13
14- [draw.h header file](https://github.com/0intro/plan9/blob/main/sys/include/draw.h)
15 contains all the drawing functions
16- [draw man page](https://9fans.github.io/plan9port/man/man3/draw.html)
17 has a bit more digestable descriptions of the draw functions
18- [graphics man page](https://9fans.github.io/plan9port/man/man3/graphics.html)
19 has a bit more digestable descriptions of the graphics functions
20- [all man pages](https://9fans.github.io/plan9port/man/man3/)
21 can be a valuable resource for learning about the system
22
23![Plan9 Howdy World!](/assets/notes/plan9-pixels.png)
24
25```c
26// main.c
27#include <u.h>
28#include <libc.h>
29#include <draw.h>
30#include <cursor.h>
31
32void
33main()
34{
35 ulong co;
36 Image *im, *bg;
37 co = 0x0000FFFF;
38
39 if (initdraw(nil, nil, argv0) < 0)
40 {
41 sysfatal("%s: %r", argv0);
42 }
43
44 im = allocimage(display, Rect(0, 0, 300, 300), RGB24, 0, DYellow);
45 bg = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, co);
46
47 if (im == nil || bg == nil)
48 {
49 sysfatal("not enough memory");
50 }
51
52 draw(screen, screen->r, bg, nil, ZP);
53 draw(screen, screen->r, im, nil, Pt(-40, -40));
54
55 flushimage(display, Refnone);
56
57 // Wait 10 seconds before exiting.
58 sleep(10000);
59
60 exits(nil);
61}
62```
63
64And then compile with `mk` (mkfile below):
65
66```makefile
67# mkfile
68</$objtype/mkfile
69
70RC=/rc/bin
71BIN=/$objtype/bin
72MAN=/sys/man
73
74main:
75 $CC $CFLAGS main.c
76 $LD $LDFLAGS -o main main.$O
77```
78
79And run with `./main`. To exit the program, press `Delete key` (strange but this
80is the alternative for Ctrl+C).
81
82*This is **very cool** indeed!*