From 0cb6a5c81271a61e930505f3315b1d67bdf22724 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sun, 16 Jul 2023 22:46:06 +0200 Subject: Renamed all the notes files to include date --- .../notes/2023-05-27-drawing-pixels-in-plan9.md | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 content/notes/2023-05-27-drawing-pixels-in-plan9.md (limited to 'content/notes/2023-05-27-drawing-pixels-in-plan9.md') 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..473ccaf --- /dev/null +++ b/content/notes/2023-05-27-drawing-pixels-in-plan9.md @@ -0,0 +1,83 @@ +--- +title: "Drawing Pixels in Plan9" +url: drawing-pixels-in-plan9.html +date: 2023-05-27T17:41:33+02:00 +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!](/notes/plan9-pixels.png) + +```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 +