Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6571379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:52:29+00:00 2026-05-25T14:52:29+00:00

I’m trying to get a very quick and dirty animated display of some data

  • 0

I’m trying to get a very quick and dirty animated display of some data produced using Haskell. The simplest thing to try seems to be ASCII art — in other words, something along the lines of:

type Frame = [[Char]]     -- each frame is given as an array of characters

type Animation = [Frame]

display :: Animation -> IO ()
display = ??

How can I best do this?

The part I can’t figure out at all is how to ensure a minimal pause between frames; the rest is straightforward using putStrLn together with clearScreen from the ansi-terminal package, found via this answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:52:30+00:00Added an answer on May 25, 2026 at 2:52 pm

    Well, here’s a rough sketch of what I’d do:

    import Graphics.UI.SDL.Time (getTicks)
    import Control.Concurrent (threadDelay)
    
    type Frame = [[Char]]
    type Animation = [Frame]
    
    displayFrame :: Frame -> IO ()
    displayFrame = mapM_ putStrLn
    
    timeAction :: IO () -> IO Integer
    timeAction act = do t <- getTicks
                        act
                        t' <- getTicks
                        return (fromIntegral $ t' - t)
    
    addDelay :: Integer -> IO () -> IO ()
    addDelay hz act = do dt <- timeAction act
                         let delay = calcDelay dt hz
                         threadDelay $ fromInteger delay
    
    calcDelay dt hz = max (frame_usec - dt_usec) 0
      where frame_usec = 1000000 `div` hz
            dt_usec = dt * 1000
    
    runFrames :: Integer -> Animation -> IO ()
    runFrames hz frs = mapM_ (addDelay hz . displayFrame) frs
    

    Obviously I’m using SDL here purely for getTicks, because it’s what I’ve used before. Feel free to replace it with any other function to get the current time.

    The first argument to runFrames is–as the name suggests–the frame rate in hertz, i.e., frames per second. The runFrames function first converts each frame into an action that draws it, then gives each to the addDelay function, which checks the time before and after running the action, then sleeps until the frame time has passed.

    My own code would look a bit different than this, because I’d generally have a more complicated loop that would do other stuff, e.g., polling SDL for events, doing background processing, passing data to the next iteration, &c. But the basic idea is the same.

    Obviously the nice thing about this approach is that, while still being fairly simple, you get a consistent frame rate when possible, with a clear means of specifying the target speed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run a query in a very quick and dirty way in
I'm trying to get a very simple Spring @mvc app to work and I'm
I am very new to erlang and am trying to get my head around
I am just trying to get into python, but I've found it very difficult
I'm very new to c++ and boost. I'm trying to get the host name
Very strange bug I can't seems to figure out. I am trying to get
I'm trying to compile a very simple c++ code and get a linking error
I am trying to load a very basic XML document but everytime I get
I'm trying to write a very lightweight build script which will basically just get
I'm trying to make a very simple OSGi test but I can't get it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.