Categories
Art Computing Generative Art Projects

Seeking

This took a ridiculous amount of time to hack together, but here’s a Common Lisp function to decide the shortest angle between two other angles. It’s used in the example of seeking a point above. I can now add noise to this to make a more AARON-style pen.

(defun shortest-angle-difference (a1 a2)
  "Find the shortest positive or negative distance between two angles."
  ;; This was slowly assembled from various online sources, none of which worked
  ;; Normalize angles to 0..2pi
  (let ((from (mod a1 +radian+))
        (to (mod a2 +radian+)))
      ;; If from and to are equal (0 = 2pi radians) the angle is zero
      (if (or (= from to)
              (= (+ from to) +radian+))
          0.0d0
          (let ((angle (- to from)))
            (if (> (abs angle) pi)
                ;; Please simplify me
                (* (- (signum angle)) (- +radian+ (abs angle)))
                angle)))))
{"cc_re__cc_re__cc_by_sa_4_0": ["s=\"menu-item menu-item-type-post_type menu-item-object-page menu-item-2754\"><a href=\"../../../../generative-art/index.html\">Generative Art</a></li>\r\n<li id=\"menu-item-2755\" class=\"menu-item menu-item-type-post_type menu-item-object-page menu-item-2755\"><a href=\"../../../../free-culture/index.html\">Free Culture</a></li>\r\n</ul></nav></div></div><div class=\"widget cc-license-widget\"><div class=\"widget-content\"><h2 class=\"widget-title subheading heading-size-3\">License</h2><div class=\"license-wrap\"><a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"../../../../wp-content/plugins/creative-commons/includes/images/by-sa.png\" width=\"88\" height=\"31\" loading=\"lazy\"></a><br>Except where otherwise noted, the content by <a href=\"../../../../http://OFFLINEZIP.wpsho\">R Myers</a> is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/4.0/\">Creative Commons Attribution-ShareAlike 4.0 International</a> License.</div></div></div><div class=\"widget widget_eu_cook", "et\"><div class=\"widget-content\"><h2 class=\"widget-title subheading heading-size-3\">License</h2><div class=\"license-wrap\"><a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"../../../../wp-content/plugins/creative-commons/includes/images/by-sa.png\" width=\"88\" height=\"31\" loading=\"lazy\"></a><br>Except where otherwise noted, the content by <a href=\"../../../../http://OFFLINEZIP.wpsho\">R Myers</a> is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/4.0/\">Creative Commons Attribution-ShareAlike 4.0 International</a> License.</div></div></div><div class=\"widget widget_eu_cookie_law_widget\"><div class=\"widget-content\">\r\n<div class=\"hide-on-button\" data-hide-timeout=\"30\" data-consent-expiration=\"180\" id=\"eu-cookie-law\">\r\n\t<form method=\"post\">\r\n\t\t<input type=\"submit\" value=\"Close and accept\" class=\"accept\"></form>\r\n\r\n\tPrivacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use. <br>\r\nTo find out more, includin"], "copyright__copyright__copyright": [" from various online sources, none of which worked\n  ;; Normalize angles to 0..2pi\n  (let ((from (mod a1 +radian+))\n        (to (mod a2 +radian+)))\n      ;; If from and to are equal (0 = 2pi radians) the angle is zero\n      (if (or (= from to)\n              (= (+ from to) +radian+))\n          0.0d0\n          (let ((angle (- to from)))\n            (if (> (abs angle) pi)\n                ;; Please simplify me\n                (* (- (signum angle)) (- +radian+ (abs angle)))\n                angle)))))", " from various online sources, none of which worked\n  ;; Normalize angles to 0..2pi\n  (let ((from (mod a1 +radian+))\n        (to (mod a2 +radian+)))\n      ;; If from and to are equal (0 = 2pi radians) the angle is zero\n      (if (or (= from to)\n              (= (+ from to) +radian+))\n          0.0d0\n          (let ((angle (- to from)))\n            (if (> (abs angle) pi)\n                ;; Please simplify me\n                (* (- (signum angle)) (- +radian+ (abs angle)))\n                angle)))))", " from various online sources, none of which worked\n  ;; Normalize angles to 0..2pi\n  (let ((from (mod a1 +radian+))\n        (to (mod a2 +radian+)))\n      ;; If from and to are equal (0 = 2pi radians) the angle is zero\n      (if (or (= from to)\n              (= (+ from to) +radian+))\n          0.0d0\n          (let ((angle (- to from)))\n            (if (> (abs angle) pi)\n                ;; Please simplify me\n                (* (- (signum angle)) (- +radian+ (abs angle)))\n                angle)))))", " from various online sources, none of which worked\n  ;; Normalize angles to 0..2pi\n  (let ((from (mod a1 +radian+))\n        (to (mod a2 +radian+)))\n      ;; If from and to are equal (0 = 2pi radians) the angle is zero\n      (if (or (= from to)\n              (= (+ from to) +radian+))\n          0.0d0\n          (let ((angle (- to from)))\n            (if (> (abs angle) pi)\n                ;; Please simplify me\n                (* (- (signum angle)) (- +radian+ (abs angle)))\n                angle)))))", " from various online sources, none of which worked\n  ;; Normalize angles to 0..2pi\n  (let ((from (mod a1 +radian+))\n        (to (mod a2 +radian+)))\n      ;; If from and to are equal (0 = 2pi radians) the angle is zero\n      (if (or (= from to)\n              (= (+ from to) +radian+))\n          0.0d0\n          (let ((angle (- to from)))\n            (if (> (abs angle) pi)\n                ;; Please simplify me\n                (* (- (signum angle)) (- +radian+ (abs angle)))\n                angle)))))", " from various online sources, none of which worked\n  ;; Normalize angles to 0..2pi\n  (let ((from (mod a1 +radian+))\n        (to (mod a2 +radian+)))\n      ;; If from and to are equal (0 = 2pi radians) the angle is zero\n      (if (or (= from to)\n              (= (+ from to) +radian+))\n          0.0d0\n          (let ((angle (- to from)))\n            (if (> (abs angle) pi)\n                ;; Please simplify me\n                (* (- (signum angle)) (- +radian+ (abs angle)))\n                angle)))))", " from various online sources, none of which worked\n  ;; Normalize angles to 0..2pi\n  (let ((from (mod a1 +radian+))\n        (to (mod a2 +radian+)))\n      ;; If from and to are equal (0 = 2pi radians) the angle is zero\n      (if (or (= from to)\n              (= (+ from to) +radian+))\n          0.0d0\n          (let ((angle (- to from)))\n            (if (> (abs angle) pi)\n                ;; Please simplify me\n                (* (- (signum angle)) (- +radian+ (abs angle)))\n                angle)))))"]}