about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-14 12:14:41 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-14 12:14:41 -0700
commita1893a44d020dc3af7eea8d679312b32dd04ad77 (patch)
treece9e0506dd410bfc4c45b5fe329dab8df702b4ca /main.lua
parent5e39aea97d54730e6e74f7181c9d462188dcfff4 (diff)
downloadlines.love-a1893a44d020dc3af7eea8d679312b32dd04ad77.tar.gz
Devine's suggestion to try to live with just freehand
https://merveilles.town/@neauoire/108301005736317873

Drawbacks:
  Smoothing eliminates high-frequency noise but not low-frequency bumps.
  Making a drawing end at the start point is very challenging.

Still perhaps a useful addition to the toolbox for now. I'm going to
need a cambrian explosion of tools in the toolbox for a while before I
prune.
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/main.lua b/main.lua
index b2278d4..5f415e4 100644
--- a/main.lua
+++ b/main.lua
@@ -197,6 +197,11 @@ function keychord_pressed(chord)
     if drawing then
       convert_horvert(drawing,i,shape)
     end
+  elseif chord == 'C-s' then
+    local drawing,i,shape = select_shape_at_mouse()
+    if drawing then
+      smoothen(shape)
+    end
   end
 end
 
@@ -235,5 +240,17 @@ function convert_horvert(drawing, i, shape)
   end
 end
 
+function smoothen(shape)
+  for _=1,7 do
+    for i=2,#shape-1 do
+      local a = shape[i-1]
+      local b = shape[i]
+      local c = shape[i+1]
+      b.x = (a.x + b.x + c.x)/3
+      b.y = (a.y + b.y + c.y)/3
+    end
+  end
+end
+
 function love.keyreleased(key, scancode)
 end