From 4abcce013c9ee3053badf2abda77190233066676 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Fri, 23 Feb 2024 10:35:22 +0100 Subject: Testing thoughts page --- _posts/notes/2023-05-27-drawing-pixels-in-plan9.md | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 _posts/notes/2023-05-27-drawing-pixels-in-plan9.md (limited to '_posts/notes/2023-05-27-drawing-pixels-in-plan9.md') diff --git a/_posts/notes/2023-05-27-drawing-pixels-in-plan9.md b/_posts/notes/2023-05-27-drawing-pixels-in-plan9.md new file mode 100644 index 0000000..3d37a2c --- /dev/null +++ b/_posts/notes/2023-05-27-drawing-pixels-in-plan9.md @@ -0,0 +1,84 @@ +--- +title: "Drawing Pixels in Plan9" +permalink: /drawing-pixels-in-plan9.html +date: 2023-05-27T17:41:33+02:00 +layout: post +type: note +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. + +More information: + +- [draw.h header file](https://github.com/0intro/plan9/blob/main/sys/include/draw.h) + contains all the drawing functions +- [draw man page](https://9fans.github.io/plan9port/man/man3/draw.html) + has a bit more digestable descriptions of the draw functions +- [graphics man page](https://9fans.github.io/plan9port/man/man3/graphics.html) + has a bit more digestable descriptions of the graphics functions +- [all man pages](https://9fans.github.io/plan9port/man/man3/) + can be a valuable resource for learning about the system + +![Plan9 Howdy World!](/assets/notes/plan9-pixels.png){:loading="lazy"} + +```c +// main.c +#include +#include +#include +#include + +void +main() +{ + ulong co; + Image *im, *bg; + co = 0x0000FFFF; + + if (initdraw(nil, nil, argv0) < 0) + { + sysfatal("%s: %r", argv0); + } + + im = allocimage(display, Rect(0, 0, 300, 300), RGB24, 0, DYellow); + bg = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, co); + + if (im == nil || bg == nil) + { + sysfatal("not enough memory"); + } + + 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 `mk` (mkfile below): + +```makefile +# mkfile +