thomasp85 / tweenr

Interpolate your data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

piling up balls.

skanskan opened this issue · comments

Hello.

Could you please add another example as your falling balls one but where the balls instead of falling to the bottom (y=0) stay above the last one if there is one in this x positon?

I mean, balls (of the same size) appear at a given height (y=constant) at random x positions and fall.
And they pile up.
That could be used to show how the histogram is created.

While this could indeed be a cool way to show histogram theory it is a little bit more involved than just using tweenr. In order to calculate the correct hight to stop the balls some sort of collision detection needs to be applied based on the current balls in the view. This is really not related to what tweenr tries to accomplish which is interpolating states. It is a little easier if the balls appear at fixed bins in the x-axis but then the example ends up being a bit contrived...

Hello, thomasp85,
Imagine something like this:

initialize the plot..., a histogram or similar.
# initialize data for simulation
height <- 8
state <- rep(0,9)

# Now repeat this loop automatically or when pressing a key
  x <- sample(9,1, prob=c(1,2,3,4,5,4,3,2,1))
  state[x] <- min(height,state[x]+1)
  plot a ball falling from (x=x, y=height) to  (x=x, y=state[x]) ,  adding the result to the previous plot.

# End loop

but I don't know how to the falling ball part.

So the x-axis is discrete (can only be 1, 2, 3, ...)?

Another "problem" is that the point sizes are absolute while the x and y axes are relative. This means that chasing the right size for the balls depends on the size and resolution of the plot... Clearly something that can be overcome, but an added obstacle

"So the x-axis is discrete (can only be 1, 2, 3, ...)?"
It was just an example. I would be happy with a simple example.

Ok - that simplifies things. This should not be insurmountable...

I've been playing with the example, adding more balls and I've found that it takes too long and consumes too much memory to generate a simple animation.

Well, this is more a problem with gganimate, as it generates all required data up front. Nothing tweenr can do about that