globe
globe copied to clipboard
Globe animations/GIFs?
It would be cool to be able save a rotating globe as a GIF (or similar format). This could possibly be done through sewing generated images together (using something like ffmpeg).
I did try to do this with a for loop to make a stop-frame animation but cannot get the for loop to work properly: (Disclaimer: I've never used golang before, so this is the first time I've been playing with it)
package main
import (
"fmt"
"github.com/mmcloughlin/globe"
)
func main() {
g := globe.New()
g.DrawGraticule(10.0)
g.DrawLandBoundaries()
for i := -90; i <= 90; i++ {
g.CenterOn(0, float64(i))
t := fmt.Sprintf("imgs/globe-%f.png", float64(i))
g.SavePNG(t, 1000)
}
}
Very cool @caleuanhopkins! Nothing looks wrong with your code from my perspective. I just learned that the GIF package exists. I assume it would be "easy" ( :crossed_fingers: ) to extrapolate your solution to use this library (especially the []*image.Paletted field), if you wanted to make PR.
@LOZORD thanks, but there is an issue as the images don't move along the lon axis, they jump around at almost random co-ords! 😖 no idea why i doesn't just make the CentreOn() method run in a line.
This would be a great feature! I'm planning to work on it. As @LOZORD has pointed out the best way is to use the image/gif package. The pinhole package has an example:
https://github.com/tidwall/pinhole/blob/86ba04e3523bd03ebff51eac8dd0865c9dc9305e/examples/earth.go
The delicate part here is selecting a good color palette. The pinhole example solves this in a very specific way, but we would need a more general solution. Probably just picking the most common colors across the frames would be a decent solution in this case. However after some searching I think there may be a gap in the market for some more sophisticated implementations of the Quantizer interface which can be used for palette selection (see gif.Options).
@caleuanhopkins the CenterOn behavior you mentioned is a bug. It does the wrong thing when called more than once. I've recorded this in #4. The fix is fairly easy and I will work on it this evening.
@mmcloughlin Thought I might chime in. With the pinhole examples I used Go's builtin image package. But I've since moved to exporting each frame as an individual PNGs and using ffmpeg for creating the gif. This can often lead to much smoother animations, and also provides a utility for generating a palette from an existing frame.
This is how I create this cities globe.
@tidwall I was thinking the same for an animation solution as with each frame they could then be imported into a range slider html element and allow the creation of 3d rotational sliders (this is just a practical example of something I have in my head I can use Globe for).
@mmcloughlin thanks for highlighting the bug, I would love to help but I'm brand new to GoLang and I would be useless in helping to debug this one!