earlygrey/shapedrawer

Plot Interpolations

Closed this issue · 6 comments

Hello. I'm largely putting this issue up so I can remember to make a PR in the future. Basically, I think it would be a great idea if ShapeDrawer can plot a given Interpolation. See https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/math/Interpolation.java.

This will be great for level editors that want to visualize a movement or tween for example. The method would look something like drawInterpolationPlot(Interpolation interpolation, float width, float height, int samples).

I don't think it would take me a lot of effort to make the PR, so long as you think it's worth doing. I'm going to do something like that with SceneComposer anyway. What are your thoughts?

Hey!

I'm having trouble visualising exactly what you mean, do you mean that would be a sort of demo thing which animates these or something like that? So the intention would be to use shape drawer to "showcase" the interpolations?

That's basically what I had in mind, except that it won't "animate" it necessarily. It will basically reproduce those graphs exactly as you see them, except that they can be scaled to any size. I know it won't be useful in the strictest sense, but it would be a nice thing to show off to people.

Now that I think about it, there is a practical use for this sort of graph. See here: https://youtu.be/dTjSLtefjvI?t=10

Making your own custom graph will be easy if you supply your own custom Interpolation...

I wouldn't want to put those in the ShapeDrawer class, as it would add to the already large number of drawing methods, however I had considered something like extra drawer classes that could add extra methods not considered elementary shape drawing. In that case, methods like these could go there, as long as they're general enough to be considered useful themselves (eg methods to help draw graphs). These extra drawer classes would be instantiated as separate objects to the ShapeDrawer object.

When I say "extra drawer classes", I mean something like a GraphDrawer class, with methods to help draw eg those interpolation graphs. These would accept a ShapeDrawer object in the constructor, and could for example either be created by the user if needed, eg

GraphDrawer graphDrawer = new GraphDrawer(shapeDrawer);
graphDrawer.drawGraph(...);

or created internally by ShapeDrawer and be used via eg

shapeDrawer.graphs.drawGraph(...)

Another alternative would be static methods eg GraphDrawer.drawGraph(shapeDrawer, ...) instead of putting them into a drawer object, though I think that makes less sense.

In any case, I'm always happy for more contributions and content, and the only thing I'm wary of is adding methods that aren't directly related to drawing elementary shapes to the ShapeDrawer class. If you like you can float some ideas here when you think of them.

That's an excellent idea! It's bound to get pretty messy, so thankfully you told me about that first. Okay, I'll work on a PR. I hope to do the idea justice!

See pull request #20