forked from hawx/img
/
shuffle.go
41 lines (32 loc) · 924 Bytes
/
shuffle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"github.com/hawx/img/shuffle"
"github.com/hawx/img/utils"
)
var cmdShuffle = &Command{
UsageLine: "shuffle [options]",
Short: "shuffles pixels of the image",
Long: `
Shuffle takes an image, shuffles the pixels of the image, then prints the
result to STDOUT
--horizontal # Use horizontal shuffling only
--vertical # Use vertical shuffling only
`,
}
var shuffleVertical, shuffleHorizontal bool
func init() {
cmdShuffle.Run = runShuffle
cmdShuffle.Flag.BoolVar(&shuffleVertical, "vertical", false, "")
cmdShuffle.Flag.BoolVar(&shuffleHorizontal, "horizontal", false, "")
}
func runShuffle(cmd *Command, args []string) {
i := utils.ReadStdin()
if (shuffleVertical && !shuffleHorizontal) {
i = shuffle.Vertically(i)
} else if (shuffleHorizontal && !shuffleVertical) {
i = shuffle.Horizontally(i)
} else {
i = shuffle.Shuffle(i)
}
utils.WriteStdout(i)
}