function ping_pong_1d ( drag, stiff )

%*****************************************************************************80
%
%% ping_pong_1d() simulates the horizontal motion of a ping pong ball.
%
%  Discussion:
%
%    Verlet integration is used to simulate the change in position 
%    and velocity.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 September 2022
%
%  Author:
%
%    Algorithm by Nick Berry.
%    This version by John Burkardt.
%
%  Reference:
%
%    Nick Berry,
%    Verlet integration,
%    July 2018,
%    https://datagenetics.com/blog/july22018/index.html
%
%  Input:
%
%    real drag: 1.0 for no drag, or slightly less than 1 to simulate drag.
%
%    real stiff: 1.0 for no energy loss in collision, or slightly less
%    to simulate energy loss.
%
  if ( nargin < 2 )
    stiff = 0.95;
  end

  if ( nargin < 1 )
    drag = 0.99;
  end

  radius = 1.0;

  width = 7.0;

  axis ( [ 0.0, width, -1.0, +1.0 ] );

  for i = 0 : 200

    if ( i == 0 )

      px = width / 2.0;
      py = 0.0;
      vx = 0.25;

    else

      px = px + vx;
      px_old = px;

      if ( ( width - radius ) < px )
        px = ( width - radius );
        px_old = px + vx;
        vx = stiff * ( px - px_old );
      elseif ( px < radius )
        px = radius;
        px_old = px + vx;
        vx = stiff * ( px - px_old );
      end

    end

    vx = drag * vx;

    cla ( );
    axis ( 'equal' );
    grid ( 'on' );
    viscircles ( [ px, py ], radius );
    set ( gca, 'yticklabel', [] );
    pause ( 0.05 );
    
  end

  return
end

