signage: bring in from external repo
This is b28e6f07aa48f1e2f01eb37bffa180f97a7b03bd from
https://code.hackerspace.pl/q3k/love2d-signage/. We only keep code
commited by inf and q3k, and we're both now licensing this code under
the ISC license, as per COPYING in the root of hscloud.
Change-Id: Ibeee2e6923605e4b1a17a1d295867c056863ef59
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1335
Reviewed-by: informatic <informatic@hackerspace.pl>
Reviewed-by: q3k <q3k@hackerspace.pl>
diff --git a/hswaw/signage/nodes/cube.lua b/hswaw/signage/nodes/cube.lua
new file mode 100644
index 0000000..ab9570b
--- /dev/null
+++ b/hswaw/signage/nodes/cube.lua
@@ -0,0 +1,64 @@
+local node = Node:extend('nodes.at', {
+})
+-- local papa = love.graphics.newImage("papa.png")
+local h = 25.0
+local v = {
+ {-h, -h, -h},
+ { h, -h, -h},
+ { h, h, -h},
+ {-h, h, -h},
+ {-h, -h, h},
+ { h, -h, h},
+ { h, h, h},
+ {-h, h, h}
+}
+
+local c = {
+ {0, 1, 31},
+ {1, 2, 31},
+ {2, 3, 31},
+ {3, 0, 31},
+ {0, 4, 34},
+ {1, 5, 34},
+ {2, 6, 34},
+ {3, 7, 34},
+ {4, 5, 32},
+ {5, 6,32},
+ {6, 7,32},
+ {7, 4,32}
+}
+
+local E = 100 * math.tan(2*math.pi/3)
+
+function to2d(p) return p[1] * E / (p[3]+E), p[2] * E / (p[3]+E) end
+
+function node:render()
+ love.graphics.setColor( 0, 0, 0 )
+ love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
+ love.graphics.setColor( 1.0, 1.0, 1.0 )
+ local w = love.graphics.getWidth() / 2
+ local h = love.graphics.getHeight() / 2
+ local scl = 6
+ for _, p in ipairs(c) do
+ x1, y1 = to2d(v[p[1]+1])
+ x2, y2 = to2d(v[p[2]+1])
+ love.graphics.line(x1 * scl + w, y1 * scl + h, x2 * scl + w, y2 * scl + h)
+ end
+end
+
+function node:update(dt)
+ for _, vec in ipairs(v) do
+ angle = -dt/3
+ nv0 = math.cos(angle) * vec[1] + math.sin(angle) * vec[3]
+ nv2 = -math.sin(angle) * vec[1] + math.cos(angle) * vec[3]
+ vec[1] = nv0
+ vec[3] = nv2
+ angle = dt
+ nv1 = math.cos(angle) * vec[2] - math.sin(angle) * vec[3]
+ nv2 = math.sin(angle) * vec[2] + math.cos(angle) * vec[3]
+ vec[2] = nv1
+ vec[3] = nv2
+ end
+end
+
+return node