shithub: orca

Download patch

ref: d1de810c759517acc8f54c623d3fb341088da193
parent: feab5f0d6229e3cec111b975126f07da484eb746
parent: ba44c6f1cf05ad6967ba4a30f6aa1b3d2bbffe64
author: Nicola Pisanti <pisanti.nicola@gmail.com>
date: Mon May 20 18:41:54 EDT 2019

Merge pull request #30 from npisanti/master

U is now the uclid operator

--- a/sim.c
+++ b/sim.c
@@ -240,7 +240,7 @@
   _('R', random)                                                               \
   _('S', movement)                                                             \
   _('T', track)                                                                \
-  _('U', uturn)                                                                \
+  _('U', uclid)                                                                \
   _('V', variable)                                                             \
   _('W', movement)                                                             \
   _('X', teleport)                                                             \
@@ -682,34 +682,23 @@
   POKE(1, 0, PEEK(0, read_val_x));
 END_OPERATOR
 
-static Isz const uturn_data[] = {
-    // clang-format off
-  -1,  0, (Isz)'N',
-   0, -1, (Isz)'W',
-   0,  1, (Isz)'E',
-   1,  0, (Isz)'S',
-    // clang-format on
-};
-
-enum {
-  Uturn_per = 3,
-  Uturn_loop_limit = Uturn_per * 4,
-};
-
-BEGIN_OPERATOR(uturn)
+// optimized starting from from
+// https://www.computermusicdesign.com/simplest-euclidean-rhythm-algorithm-explained/
+BEGIN_OPERATOR(uclid)
   LOWERCASE_REQUIRES_BANG;
-  for (Usz i = 0; i < Uturn_loop_limit; i += Uturn_per) {
-    PORT(uturn_data[i + 0], uturn_data[i + 1], IN | OUT | PARAM | NONLOCKING);
-  }
-  for (Usz i = 0; i < Uturn_loop_limit; i += Uturn_per) {
-    Isz dy = uturn_data[i + 0];
-    Isz dx = uturn_data[i + 1];
-    Glyph g = PEEK(dy, dx);
-    switch (g) {
-    case MOVEMENT_CASES:
-      POKE(dy, dx, (Glyph)uturn_data[i + 2]);
-    }
-  }
+  PORT(0, -1, IN | PARAM);
+  PORT(0, 1, IN);
+  PORT(1, 0, OUT);
+  Glyph left = PEEK(0, -1);
+  Usz steps = 1;
+  if (left != '.' && left != '*')
+    steps = index_of(left);
+  Usz max = index_of(PEEK(0, 1));
+  if (max == 0)
+    max = 8;
+  Usz bucket = (steps * (Tick_number + max - 1)) % max + steps;
+  Glyph g = (bucket >= max) ? '*' : '.';
+  POKE(1, 0, g);
 END_OPERATOR
 
 BEGIN_OPERATOR(variable)