Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globe animations/GIFs? #3

Open
LOZORD opened this issue Jul 10, 2017 · 7 comments
Open

Globe animations/GIFs? #3

LOZORD opened this issue Jul 10, 2017 · 7 comments

Comments

@LOZORD
Copy link

LOZORD commented Jul 10, 2017

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).

@caleuanhopkins
Copy link

caleuanhopkins commented Jul 10, 2017

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)
	}
}

@LOZORD
Copy link
Author

LOZORD commented Jul 10, 2017

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" ( 🤞 ) to extrapolate your solution to use this library (especially the []*image.Paletted field), if you wanted to make PR.

@caleuanhopkins
Copy link

@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.

@mmcloughlin
Copy link
Owner

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).

@mmcloughlin
Copy link
Owner

@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.

@tidwall
Copy link

tidwall commented Jul 10, 2017

@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.

@caleuanhopkins
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants