diff options
Diffstat (limited to 'content')
| -rw-r--r-- | content/notes/drawing-pixels-in-plan9.md | 66 | ||||
| -rw-r--r-- | content/notes/plan9-screenshot.md | 4 |
2 files changed, 70 insertions, 0 deletions
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 @@ | |||
| 1 | --- | ||
| 2 | title: "Drawing Pixels in Plan9" | ||
| 3 | url: drawing-pixels-in-plan9.html | ||
| 4 | date: 2023-05-27T17:41:33+02:00 | ||
| 5 | type: notes | ||
| 6 | draft: true | ||
| 7 | tags: [plan9, graphics] | ||
| 8 | --- | ||
| 9 | |||
| 10 | I have started exploring Plan9's graphics capabilities. This is a hello world | ||
| 11 | alternative for drawing that draws a yellow square on a blue background. | ||
| 12 | |||
| 13 |  | ||
| 14 | |||
| 15 | ```c | ||
| 16 | #include <u.h> | ||
| 17 | #include <libc.h> | ||
| 18 | #include <draw.h> | ||
| 19 | #include <cursor.h> | ||
| 20 | |||
| 21 | void main(int argc, char *argv[]) | ||
| 22 | { | ||
| 23 | ulong co; | ||
| 24 | Image *im, *bg; | ||
| 25 | co = 0xFF0000FF; | ||
| 26 | |||
| 27 | if (initdraw(nil, nil, argv0) < 0) | ||
| 28 | { | ||
| 29 | sysfatal("%s: %r", argv0); | ||
| 30 | } | ||
| 31 | |||
| 32 | im = allocimage(display, Rect(0, 0, 100, 100), RGB24, 0, DYellow); | ||
| 33 | bg = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, co); | ||
| 34 | |||
| 35 | if (im1 == nil || bg == nil) | ||
| 36 | { | ||
| 37 | sysfatal("get more memory, bub"); | ||
| 38 | } | ||
| 39 | |||
| 40 | draw(screen, screen->r, bg, nil, ZP); | ||
| 41 | draw(screen, screen->r, im, nil, Pt(-40, -40)); | ||
| 42 | |||
| 43 | flushimage(display, Refnone); | ||
| 44 | |||
| 45 | // Wait 10 seconds before exiting. | ||
| 46 | sleep(10000); | ||
| 47 | |||
| 48 | exits(nil); | ||
| 49 | } | ||
| 50 | ``` | ||
| 51 | |||
| 52 | And then compile with Makefile: | ||
| 53 | |||
| 54 | ```makefile | ||
| 55 | </$objtype/mkfile | ||
| 56 | |||
| 57 | RC=/rc/bin | ||
| 58 | BIN=/$objtype/bin | ||
| 59 | MAN=/sys/man | ||
| 60 | |||
| 61 | main: | ||
| 62 | $CC $CFLAGS main.c | ||
| 63 | $LD $LDFLAGS -o main main.$O | ||
| 64 | ``` | ||
| 65 | |||
| 66 | *This is **very cool** indeed!* | ||
diff --git a/content/notes/plan9-screenshot.md b/content/notes/plan9-screenshot.md index ad11358..71e5808 100644 --- a/content/notes/plan9-screenshot.md +++ b/content/notes/plan9-screenshot.md | |||
| @@ -13,6 +13,10 @@ output it to `/dev/screen`. You can then use `topng` to convert it to a png | |||
| 13 | image. | 13 | image. |
| 14 | 14 | ||
| 15 | ```sh | 15 | ```sh |
| 16 | # Instant screenshot. | ||
| 16 | cat /dev/screen | topng > screen.png | 17 | cat /dev/screen | topng > screen.png |
| 18 | |||
| 19 | # Delayed screenshot (5 seconds). | ||
| 20 | sleep 5; cat /dev/screen | topng > screen.png | ||
| 17 | ``` | 21 | ``` |
| 18 | 22 | ||
