Skip to content

Commit

Permalink
add reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Jan 25, 2018
1 parent e2fd67e commit a5ef732
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
43 changes: 18 additions & 25 deletions cmd/pic2ascii/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func main() {
}

if *r {
*chars = reverseString(*chars)
*chars = pic2ascii.ReverseString(*chars)
}

toAscii := func(img image.Image) string {
Expand Down Expand Up @@ -106,22 +106,24 @@ func main() {
dds := []string{}
sg := pic2ascii.SliceGIF(img)
for _, v := range sg {
dds = append(dds, fmt.Sprintln(toAscii(v)))
dd := toAscii(v)
dds = append(dds, dd)
}

if *o == "" {
if img.LoopCount == 0 {
img.LoopCount = *m
}
if *o != "" {
ioutil.WriteFile(*o, []byte(strings.Join(dds, "\n")), 0666)
return
}

if img.LoopCount == 0 {
img.LoopCount = *m
}

for i := 0; i != img.LoopCount; i++ {
for k, v := range dds {
fmt.Println(v)
time.Sleep(time.Duration(img.Delay[k]) * time.Second / 100)
}
for i := 0; i != img.LoopCount; i++ {
for k, v := range dds {
fmt.Println(v)
time.Sleep(time.Duration(img.Delay[k]) * time.Second / 100)
}
} else {
ioutil.WriteFile(*o, []byte(strings.Join(dds, "\n")), 0666)
}

default:
Expand All @@ -132,20 +134,11 @@ func main() {
}

dd := toAscii(img)
if *o == "" {
fmt.Print(dd)
} else {
if *o != "" {
ioutil.WriteFile(*o, []byte(dd), 0666)
return
}
}
}

func reverseString(s string) string {
str := []rune(s)
l := len(str) / 2
for i := 0; i < l; i++ {
j := len(str) - i - 1
str[i], str[j] = str[j], str[i]
fmt.Print(dd)
}
return string(str)
}
11 changes: 11 additions & 0 deletions reverse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package pic2ascii

func ReverseString(s string) string {
str := []rune(s)
l := len(str) / 2
for i := 0; i < l; i++ {
j := len(str) - i - 1
str[i], str[j] = str[j], str[i]
}
return string(str)
}

0 comments on commit a5ef732

Please sign in to comment.