Drawing Pixels in Plan9
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 contains all the drawing functions
- draw man page has a bit more digestable descriptions of the draw functions
- graphics man page has a bit more digestable descriptions of the graphics functions
- all man pages can be a valuable resource for learning about the system
![Plan9 Howdy World!](/assets/notes/plan9-pixels.png)
// main.c
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <cursor.h>
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):
# mkfile
</$objtype/mkfile
RC=/rc/bin
BIN=/$objtype/bin
MAN=/sys/man
main:
$CC $CFLAGS main.c
$LD $LDFLAGS -o main main.$O
And run with ./main
. To exit the program, press Delete key
(strange but this
is the alternative for Ctrl+C).
This is very cool indeed!
Other notes
- Download list of YouTube files
- Execute not blocking async shell command in C#
- Cache busting in Hugo
- plan9 Run 9front in Qemu
- Online radio streaming with MPV from terminal
- plan9 Install Plan9port on Linux
- c Calling assembly functions from C
- Write ISO to USB Key
- plan9 Compile drawterm on Fedora 38
- Development environments with Nix
- Simple presentations with Markdown
- c Extend Lua with custom C functions using Clang
- 60's IBM Computers Commercial
- Push to multiple origins at once in Git
- 10/GUI 10 Finger Multitouch User Interface