且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Haskell:在水平线上移动图像

更新时间:2023-11-22 22:45:10

The fundamental algorithm is the same as your vertical shift function, since String is also a list of characters, [Char].

You can generalize your algorithm to a move function since the code for moveVer really only requires a list and has no dependency on Img:

move :: Int -> [a] -> [a]
move n xs = take len $ drop (mod n len) $ cycle xs
  where len = length xs

Now you can rewrite your moveVer function in terms of move:

moveVer :: Int -> Img -> Img
moveVer = move

And since a string is just a List of characters, you can map over the list of strings and use the move function to do your horizontal movement.

moveHor :: Int -> Img -> Img
moveHor n = map $ move n

相关阅读

推荐文章