#include #include #include #include /* For Celeste. ❤ */ Image *background; Image *ball; Image *opening; Image *face; Font *font; char* fontname; Point center; int balldia; int openingdia; Point facep[3]; char* mesg; char *results[] = { "Yes.", "It is\ncertain.", "It is\ndecidedly\nso.", "Without\na doubt.", "Definitely!", "You may\nrely on\nit.", "As I see\nit, yes.", "Most likely.", "Signs point\nto yes.", "No.", "Don't\ncount on\nit.", "My reply\nis no.", "My sources\nsay no.", "Outlook\nnot so\ngood.", "Doubtful.", "Ask again\nlater.", "Reply hazy,\ntry again\nlater.", "Cannot\npredict\nnow.", "Concentrate\nand ask\nagain.", }; void usage(void) { fprint(2, "usage %s\n", argv0); exits("usage"); } void sizes(void) { int wid, ht, a, h, r; wid = screen->r.max.x-screen->r.min.x; ht = screen->r.max.y-screen->r.min.y; center = Pt(screen->r.min.x+wid*0.5, screen->r.min.y+ht*0.5); balldia = 200; openingdia = balldia * 0.6; a = openingdia * 1.4; h = a * sqrt(3) / 2; r = h * 2/3; facep[0] = addpt(center, Pt(-a/2, -h/3)); facep[1] = addpt(center, Pt(a/2, -h/3)); facep[2] = addpt(center, Pt(0, r)); } void init(void) { if(initdraw(nil, fontname, argv0) < 0) { fprint(2, "%s: initdraw failed: %r\n", argv0); exits("initdraw"); } background = allocimagemix(display, DWhite, 0x443344FF); ball = allocimagemix(display, DBlack, DBlack); opening = allocimagemix(display, 0x443344FF, DBlack); face = allocimagemix(display, 0x443344FF, DWhite); if(background==nil) { fprint(2, "%s: can't create images: %r\n", argv0); exits("image"); } } void getmesg(void) { int x; x = nrand(sizeof(results)/sizeof(char*)); // fprint(2, "nrand: %d\n", x); mesg = strdup(results[x]); } void drawmesg(void) { Point p; char *s; char *args[3]; int i, n, w, y; if(strcmp(mesg, "") != 0) { s = strdup(mesg); n = getfields(s, args, nelem(args), 0, "\n"); // fprint(2, "args: %d\n", n); p = stringsize(font, s); y = (p.y * n) / 2; for(i=0; ir, background, nil, ZP); fillellipse(screen, center, balldia, balldia, ball, ZP); fillellipse(screen, center, openingdia, openingdia, opening, ZP); fillpoly(screen, facep, 3, 0, face, ZP); drawmesg(); flushimage(display, 1); } void main(int argc, char *argv[]) { Event e; fontname = "/lib/font/bit/lucida/unicode.12.font"; fontname = "/lib/font/bit/lucidasans/unicode.10.font"; ARGBEGIN { default: usage(); } ARGEND init(); einit(Ekeyboard|Emouse); mesg=""; eresized(0); for (;;) { switch(eread(Ekeyboard|Emouse, &e)) { case Ekeyboard: if(e.kbdc==0x7F || e.kbdc=='q') exits(0); break; case Emouse: if(e.mouse.buttons) { getmesg(); eresized(0); } break; default: break; } } }