diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-05-27 17:49:00 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-05-27 17:49:00 +0200 |
| commit | f75ae45608cb9745c4c2bcc781b3cbea9ff93865 (patch) | |
| tree | 3221f045ec73a5e0892775870c53d5a8f32bc8fd /content/notes/drawing-pixels-in-plan9.md | |
| parent | 5b0d04bf2be32e85e68fc1339000a0ea5a15543c (diff) | |
| download | mitjafelicijan.com-f75ae45608cb9745c4c2bcc781b3cbea9ff93865.tar.gz | |
Note: Drawing pixels in Plan9
Diffstat (limited to 'content/notes/drawing-pixels-in-plan9.md')
| -rw-r--r-- | content/notes/drawing-pixels-in-plan9.md | 66 |
1 files changed, 66 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!* | ||
