ref: 363056d387d355804f182d3161c63aa3b56d313f
parent: abf3fb949510d09d9c2da348ce3a4c4a7a80cadb
author: Clay Ayers <[email protected]>
date: Wed Oct 11 18:32:44 EDT 2023
e
--- /dev/null
+++ b/0paint.c
@@ -1,0 +1,49 @@
+/*
+ * written in plan 9 c dialect
+ * thedaemon
+*/
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <event.h>
+
+void
+main(void)
+{
+ Mouse m;
+ Point prevm; /* previous mouse position */
+ initdraw(0, 0, "0 Paint");
+ eresized(0);
+ einit(Emouse);
+ int brush = 1;
+ int eraser = 4;
+
+ for(;;){
+ m = emouse();
+
+ if(m.buttons & 2)
+ break;
+ if(m.buttons & 4) {
+ line(screen,
+ prevm.x == -1 ? m.xy : prevm,
+ m.xy, Enddisc, Enddisc, eraser, display->white, ZP);
+ prevm = m.xy;
+ }
+ if(m.buttons & 1) { /* Paint Function ? : is if else true and false*/
+ line(screen,
+ prevm.x == -1 ? m.xy : prevm,
+ m.xy, Enddisc, Enddisc, brush, display->black, ZP); /* ZP is a constant point (0,0) */
+ prevm = m.xy;
+ } else {
+ prevm = Pt(-1, -1);
+ }
+ }
+}
+
+void
+eresized(int new)
+{
+ USED(new);
+ if(getwindow(display, Refnone) < 0)
+ sysfatal("resize failed: %r");
+}