Skip to content

Commit

Permalink
Added reverse and full gif animations.
Browse files Browse the repository at this point in the history
  • Loading branch information
eleby committed Mar 1, 2021
1 parent 371b064 commit 32846a8
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions main/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ func launchPixellisator(f *os.File, min int, count int, increase int) {
if hasParam("gif") {
addToGif(&gifImg, newImg)
}
if hasParam("print") {
printInTerminal(newImg, pointMin, pointMax, min+(i*increase))
}
if i+1 == count {
if hasParam("print") {
printInTerminal(newImg, pointMin, pointMax, min+(i*increase))
}
if hasParam("gif") {
if hasParam("reverse") {
reverseGif(&gifImg)
}
if hasParam("full") {
addReverseToGif(&gifImg)
}
gifOutput, errGif := os.Create("results.gif")
if errGif != nil {
log.Print("Cannot create gif image")
Expand Down Expand Up @@ -121,3 +127,18 @@ func addToGif(gifImg *gif.GIF, img image.Image) {
gifImg.Image = append(gifImg.Image, palettedImage)
gifImg.Delay = append(gifImg.Delay, GifDelayEachFrame)
}

func addReverseToGif(gifImg *gif.GIF) {
for i := len(gifImg.Image) - 2; i > 0; i-- {
gifImg.Image = append(gifImg.Image, gifImg.Image[i])
gifImg.Delay = append(gifImg.Delay, GifDelayEachFrame)
}
}

func reverseGif(gifImg *gif.GIF) {
var images []*image.Paletted
for i := len(gifImg.Image) - 1; i >= 0; i-- {
images = append(images, gifImg.Image[i])
}
gifImg.Image = images
}

0 comments on commit 32846a8

Please sign in to comment.