1

I'm using the gloss library to picture a simulation. Is there a function, which stops the simulation function when a condition is true. Just the last drawn picture should remain in the window.

Thanks in advance

Max K
  • 171
  • 12
  • 1
    What about just adding another state variable to record whether or not the simulation should be frozen? If the `isFrozen` value is `True` you just return the current model; otherwise you evolve it - i.e. apply the step function. – ErikR Sep 04 '16 at 14:10

1 Answers1

0

As @ErikR suggested, what you're describing amounts to not updating the model anymore once you've reached the state you are looking for. You can define a combinator acting on stepping functions doing precisely this:

untilModel
  :: (ViewPort -> Float -> model -> model)
  -> (model -> Bool)
  -> (ViewPort -> Float -> model -> model)
untilModel step isFrozen v f m =
  if isFrozen m then m
  else step v f m

When you have a step function and you want to stop the simulation when isFrozen becomes true of the model, you can simply pass simulate the altered step function step `untilModel` isFrozen.

gallais
  • 11,823
  • 2
  • 30
  • 63