There are soooo many ways to do this, I hate to limit it with an example, but here’s one way:
From your post I assume you mean that you want a line to move across the screen until either a student presses stop or it reaches a certain point. If you add a max value in when you create the line you should get that behavior. Graphing Calculator
Side note: I would LOVE to see all of the different ways that contributors to this forum handle this interaction!