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