2 ;; Copyright © 2020 Phil Hagelberg and contributors
3 ;; released under the GPLv3 or later
6 ;; dofile("../fennel/fennel.lua").dofile("sim.fnl", {correlate=true})
12 (local cols 6) ; per hand
14 (local angle (math.rad 10))
15 (local corner-radius 8)
16 (local bottom 100) ; outer bottom
18 (local switch-height 13.72)
19 (local switch-width 13.62)
20 (local switch-spacing 18.6)
23 (local offsets [8.0 5.0 0.0 6.0 11.0 15.0])
25 (local hand-width 106.621)
26 (local hand-height (+ (* switch-spacing rows) (- switch-spacing switch-height)
28 (local switch-x-offset (* 1.75 corner-radius))
29 (local switch-y-offset (- bottom hand-height (- (math.sqrt corner-radius))))
31 (local switches-left [])
32 (local switches-right [])
33 (local switches-fn-left [])
34 (local switches-fn-right [])
40 [:esc :tab :super :lshift :backspace :ctrl]])
45 [:alt " " :fn :- :/ "\n"]])
48 [["!" "@" :up "$" "%"]
49 ["(" :left :down :right ")"]
50 ["[" "]" "#" "{" "}" "^"]
51 [:l2 :insert :super2 :rshift :backspace2 :ctrl2]])
54 [[:pgup :7 :8 :9 :backspace3]
55 [:pgdn :4 :5 :6 :blank]
57 [:alt2 :space2 :fn2 :.2 :0 :=]])
61 (for [col 1 cols] ; switches
63 (when (not (and (= 6 col) (<= row 2)))
64 (let [lx (+ (* switch-spacing (- col 1)))
65 rx (- (* (- cols 1) switch-spacing) lx)
66 y (+ (* switch-spacing (- row 1)) (. offsets col))
68 kl (table.remove (. layout-l row) 1)
69 kr (table.remove (. layout-r row))
70 kfl (table.remove (. layout-fl row) 1)
71 kfr (table.remove (. layout-fr row))]
72 (table.insert switches-left {:x lx :y y :p [] :k kl})
73 (table.insert switches-right {:x rx :y y :p [] :k kr})
74 (table.insert switches-fn-left {:x lx :y fn-y :p [] :k kfl :fn true})
75 (table.insert switches-fn-right {:x rx :y fn-y :p [] :k kfr :fn true})
76 (tset keys kl (. switches-left (# switches-left)))
77 (tset keys kr (. switches-right (# switches-right)))
78 (tset keys kfl (. switches-fn-left (# switches-fn-left)))
79 (tset keys kfr (. switches-fn-right (# switches-fn-right)))))))
82 (let [key (. keys (pressed:lower))]
84 (table.insert key.p {:ox (love.math.randomNormal 2 0)
85 :oy (love.math.randomNormal 2 0)
86 :r (love.math.randomNormal 2 8)})
89 (when (not= pressed (pressed:lower))
92 (var text "The Atreus is a mechanical keyboard designed primarily to match the
93 shape of human hands and to be as portable as possible. The case
94 measures 26x12cm and lacks even a number row, relying heavily upon the
95 =fn= key. There is a circuit board for this design, but it's also
96 possible to [[http://wiki.geekhack.org/index.php?title=Hard-Wiring_How-To]
97 [manually wire the matrix]]. ")
101 (let [key (text:sub 1 1)]
103 (set text (text:sub 2)))))
112 (fn draw-switch [{: x : y : k : p}]
113 (love.graphics.rectangle :line x y switch-width switch-height)
115 (love.graphics.print k (+ x 2) y))
116 (love.graphics.setColor 0 0.8 0.9 0.1)
117 (each [_ p (ipairs p)]
118 (love.graphics.circle :fill
119 (+ x p.ox (/ switch-width 2))
120 (+ y p.oy (/ switch-height 2))
122 (love.graphics.setColor 0 0 0))
125 (let [(w h) (love.graphics.getDimensions)]
126 (love.graphics.setColor 1 1 1)
127 (love.graphics.rectangle :fill 0 0 w h)
128 (love.graphics.setColor 0 0 0)
129 (love.graphics.scale scale)
132 (love.graphics.translate (- width hand-width switch-x-offset)
134 (love.graphics.rotate angle 0 hand-height)
135 (love.graphics.translate (- hand-width) 0)
136 (each [_ s (pairs switches-left)]
138 (each [_ s (pairs switches-fn-left)]
143 (love.graphics.translate (- width hand-width switch-x-offset)
145 (love.graphics.rotate (- angle))
146 (each [_ s (pairs switches-right)]
148 (each [_ s (pairs switches-fn-right)]
150 (love.graphics.pop)))
152 (fn love.keypressed [key]
154 "=" (set scale (+ scale 0.2))
155 "-" (set scale (- scale 0.2))
156 "escape" (love.event.quit)
157 "return" (let [fennel (dofile "../fennel/fennel.lua")]
158 (fennel.dofile "sim.fnl"))