diff options
Diffstat (limited to 'axis.hs')
-rw-r--r-- | axis.hs | 32 |
1 files changed, 20 insertions, 12 deletions
@@ -19,6 +19,7 @@ import Data.List (elemIndex, elemIndices, filter, groupBy, length, reverse, sort | |||
19 | import GHC.Word | 19 | import GHC.Word |
20 | import Data.Bits | 20 | import Data.Bits |
21 | import qualified Sound.ALSA.Sequencer.Event as Event | 21 | import qualified Sound.ALSA.Sequencer.Event as Event |
22 | import qualified Graphics.UI.SDL.Utilities as SDL.Util | ||
22 | 23 | ||
23 | netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String | 24 | netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String |
24 | netwireIsCool = | 25 | netwireIsCool = |
@@ -171,6 +172,11 @@ data LoopState = LoopState { | |||
171 | repeatCols :: Integer | 172 | repeatCols :: Integer |
172 | } deriving (Show) | 173 | } deriving (Show) |
173 | 174 | ||
175 | _SDL_DIGITS = Set.fromList [SDL.SDLK_1, SDL.SDLK_2, SDL.SDLK_3, SDL.SDLK_4, SDL.SDLK_5, SDL.SDLK_6, SDL.SDLK_7, SDL.SDLK_8, SDL.SDLK_9, SDL.SDLK_0] | ||
176 | firstDigitDown :: Set.Set SDL.Keysym.SDLKey -> Maybe Integer | ||
177 | firstDigitDown k = if Set.null digitsDown then Nothing else Just $ (-48 +) $ fromIntegral $ SDL.Util.fromEnum $ Set.findMin digitsDown | ||
178 | where digitsDown = Set.intersection _SDL_DIGITS k | ||
179 | |||
174 | main = | 180 | main = |
175 | withAlsaInit $ \h public private q publicAddr privateAddr -> do | 181 | withAlsaInit $ \h public private q publicAddr privateAddr -> do |
176 | cmdlineAlsaConnect h public -- fail early if bad command lines | 182 | cmdlineAlsaConnect h public -- fail early if bad command lines |
@@ -208,7 +214,7 @@ main = | |||
208 | (ds, s') <- stepSession s | 214 | (ds, s') <- stepSession s |
209 | (ex, w') <- stepWire w ds (Right x) | 215 | (ex, w') <- stepWire w ds (Right x) |
210 | let x' = either (const "") id ex | 216 | let x' = either (const "") id ex |
211 | let colsRepeat' = if (keyDown SDL.SDLK_1 keysDown') then 1 else if (keyDown SDL.SDLK_2 keysDown') then 2 else colsRepeat | 217 | let colsRepeat' = case firstDigitDown keysDown' of Nothing -> colsRepeat; (Just 0) -> colsRepeat; (Just n) -> n; |
212 | 218 | ||
213 | let restartVideo = resolution' /= resolution || colsRepeat' /= colsRepeat | 219 | let restartVideo = resolution' /= resolution || colsRepeat' /= colsRepeat |
214 | 220 | ||
@@ -344,17 +350,19 @@ getKeyLocationsAbs colsRepeat = | |||
344 | kh = kw/2 * sqrt(3) -- hexagon ratio | 350 | kh = kw/2 * sqrt(3) -- hexagon ratio |
345 | 351 | ||
346 | xys = | 352 | xys = |
347 | map (\y -> map (\i -> ( | 353 | map (\y -> map (\i -> |
348 | 354 | ||
349 | fromInteger(i) * kw * 3 / 4, | 355 | let repetition = i `div` fromIntegral(_AXIS_UNIQUE_COLS) |
350 | 356 | odd = 1 == i `mod` 2 | |
351 | y + kh / 2 * fromInteger(i `mod` 2) + | 357 | dropBy = if odd then kh / 2 + kh * fromInteger(repetition `div` 2) |
352 | 358 | else kh * fromInteger((repetition + 1) `div` 2) | |
353 | (if (fromInteger(i) >= _AXIS_UNIQUE_COLS) then kh * fromInteger((i+1) `mod` 2) else 0) | 359 | in |
354 | 360 | ( | |
355 | )) [0 .. round(kb_cols) - 1]) $ | 361 | fromInteger(i) * kw * 3 / 4, |
356 | map (\i -> kh * fromIntegral(i)) | 362 | y + dropBy |
357 | [0..round(kb_rows) - 1] | 363 | )) [0 .. round(kb_cols) - 1]) $ |
364 | map (\i -> kh * fromIntegral(i)) | ||
365 | [0..round(kb_rows) - 1] | ||
358 | in | 366 | in |
359 | (kh, kw, xys) | 367 | (kh, kw, xys) |
360 | 368 | ||