chiark / gitweb /
Add mechanisms (as yet unused) for varying Bedstead's weight.
authorBen Harris <bjh21@bjh21.me.uk>
Tue, 25 Jul 2017 22:36:10 +0000 (23:36 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 25 Jul 2017 22:36:10 +0000 (23:36 +0100)
There are rather tight limits to the weights it can achieve, though.

bedstead.c

index 56ed86858d2d9cf698d9f612924b61ebacb5532d..8ba649eea8013b25317d455715113c4e1cfbc30e 100644 (file)
@@ -1814,7 +1814,46 @@ emit_path()
        }
        if (started) printf("EndSplineSet\n");
 }
-               
+
+/*
+ * To vary the weight of Bedstead, we just vary the thickness of
+ * vertical strokes.  More precisely, we pretend that the weight
+ * variation is achieved by moving the rising edges of the output
+ * waveform of the SAA5050.  This is implemented by moving all left
+ * edges left and right.  The code below only handles cases where we
+ * don't run out of slack in horizontal lines, which limits weight to
+ * the range (-50 * SCALE) < weight < (25 * SCALE).
+ */
+static int weight = 0 * SCALE;
+
+static void
+adjust_weight()
+{
+       int i;
+       point *p;
+
+       for (i = 0; i < nextpoint; i++) {
+               p = &points[i];
+               if (p->next == NULL) continue;
+               assert(p->prev != NULL);
+               /* Move left-edge points horizontally */
+               if (p->prev->v.y <= p->v.y && p->v.y <= p->next->v.y)
+                       p->v.x -= weight;
+               /* Move top inner corner points along NE/SW diagonal */
+               if (p->prev->v.y < p->v.y && p->v.y > p->next->v.y &&
+                   p->prev->v.x > p->v.x && p->v.x > p->next->v.x) {
+                       p->v.x -= weight/2;
+                       p->v.y -= weight/2;
+               }
+               /* Move bottom inner corner points along NW/SE diagonal */
+               if (p->prev->v.y > p->v.y && p->v.y < p->next->v.y &&
+                   p->prev->v.x < p->v.x && p->v.x < p->next->v.x) {
+                       p->v.x -= weight/2;
+                       p->v.y += weight/2;
+               }
+       }
+}
+
 static void
 blackpixel(int x, int y, int bl, int br, int tr, int tl)
 {
@@ -1916,6 +1955,7 @@ dochar(char const data[YSIZE], unsigned flags)
                }
        }
        clean_path();
+       adjust_weight();
        emit_path();
 }