From 32846a809cd1922dd3408a28a02e1a57492d3ba8 Mon Sep 17 00:00:00 2001 From: Rewan_ Date: Mon, 1 Mar 2021 22:07:31 +0100 Subject: [PATCH] Added reverse and full gif animations. --- main/image.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/main/image.go b/main/image.go index 5e98bf1..9dc6a3b 100644 --- a/main/image.go +++ b/main/image.go @@ -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") @@ -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 +}