From f75ae45608cb9745c4c2bcc781b3cbea9ff93865 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sat, 27 May 2023 17:49:00 +0200 Subject: Note: Drawing pixels in Plan9 --- content/notes/drawing-pixels-in-plan9.md | 66 +++++++++++++++++++++++++++++++ content/notes/plan9-screenshot.md | 4 ++ static/notes/plan9-pixels.png | Bin 0 -> 10737 bytes 3 files changed, 70 insertions(+) create mode 100644 content/notes/drawing-pixels-in-plan9.md create mode 100644 static/notes/plan9-pixels.png diff --git a/content/notes/drawing-pixels-in-plan9.md b/content/notes/drawing-pixels-in-plan9.md new file mode 100644 index 0000000..e5f5af4 --- /dev/null +++ b/content/notes/drawing-pixels-in-plan9.md @@ -0,0 +1,66 @@ +--- +title: "Drawing Pixels in Plan9" +url: drawing-pixels-in-plan9.html +date: 2023-05-27T17:41:33+02:00 +type: notes +draft: true +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 +#include +#include +#include + +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 + screen.png + +# Delayed screenshot (5 seconds). +sleep 5; cat /dev/screen | topng > screen.png ``` diff --git a/static/notes/plan9-pixels.png b/static/notes/plan9-pixels.png new file mode 100644 index 0000000..91600b1 Binary files /dev/null and b/static/notes/plan9-pixels.png differ -- cgit v1.2.3