-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Terminal-based graphing via ANSI and Unicode -- -- Ansigraph is an ultralightweight terminal-based graphing utility. It -- uses Unicode characters and ANSI escape codes to display and animate -- colored graphs of vectors/functions in real and complex variables. -- -- This functionality is provided by a Graphable type class, whose -- method graphWith draws a graph at the terminal. Another -- function animateWith takes a list of Graphable elements and -- displays an animation by rendering them in sequence. Both of these -- functions take an options record as an argument. The graph and -- animate functions are defined to use the default options, and -- the user can define similar functions based on their own settings. -- -- There are two main ways to use the package. Importing -- System.Console.Ansigraph provides all the functionality we -- typically use. This includes the FlexibleInstances extension, -- which makes it marginally more convenient to use graphing functions by -- allowing instances like 'Graphable [Double]'. -- -- If you want to use the package without activating -- FlexibleInstances then you can import -- System.Console.Ansigraph.Core, which provides everything except -- these instances. Then you must use one of a few newtype wrappers, -- namely: Graph, PosGraph, CGraph, Mat, -- CMat. These wrappers are also available from the standard -- Ansigraph module. -- -- The System.Console.Ansigraph.Examples module contains examples -- of all the graph types with animations of various plane waves, and -- also shows the available ANSI colors. @package ansigraph @version 0.1.0.0 -- | This module provides the core functionality of the ansigraph package: -- terminal-based graphing for vectors and matrices of real and complex -- numbers. -- -- This is implemented via a Graphable type class. -- -- Ansigraph is intended to be used in on of two ways: -- -- module System.Console.Ansigraph.Core -- | Things that ansigraph knows how to render at the terminal are -- instances of this class. class Graphable a graphWith :: Graphable a => AGSettings -> a -> IO () -- | Invokes the Graphable type class method graphWith with -- the default AGSettings record, graphDefaults. graph :: Graphable a => a -> IO () -- | Any list of a Graphable type can be made into an animation, by -- graphing each element with a time delay and screen-clear after -- each. AGSettings are used to determine the time delta and any -- coloring/scaling options. animateWith :: Graphable a => AGSettings -> [a] -> IO () -- | Perform animateWith using default options. Equivalent to -- graphing each member of the supplied list with a short delay -- and screen-clear after each. animate :: Graphable a => [a] -> IO () -- | Record that holds graphing options. data AGSettings AGSettings :: AnsiColor -> AnsiColor -> AnsiColor -> AnsiColor -> Int -> (Int -> Int) -> AGSettings -- | Foreground color for real number component [realColor] :: AGSettings -> AnsiColor -- | Foreground color for imaginary number component. [imagColor] :: AGSettings -> AnsiColor -- | Background color for real number component. [realBG] :: AGSettings -> AnsiColor -- | Background color for imaginary number component. [imagBG] :: AGSettings -> AnsiColor -- | Framerate in fps. [framerate] :: AGSettings -> Int -- | How to rescale the size of a vector before displaying it (which is not -- implemented yet). [scaling] :: AGSettings -> (Int -> Int) graphDefaults :: AGSettings blue :: AnsiColor pink :: AnsiColor white :: AnsiColor -- | ANSI colors are characterized by a Color and a -- ColorIntensity. This data type holds one of each. data AnsiColor AnsiColor :: ColorIntensity -> Color -> AnsiColor -- | Holds two AnsiColors representing foreground and background -- colors for display via ANSI. data Coloring Coloring :: AnsiColor -> AnsiColor -> Coloring -- | Projection retrieving foreground and background colors for real number -- graphs in the form of a Coloring. realColors :: AGSettings -> Coloring -- | Projection retrieving foreground and background colors for imaginary -- component of complex number graphs in the form of a Coloring. imagColors :: AGSettings -> Coloring -- | Retrieves a pair of Colorings for real and imaginary graph -- components respectively. colorSets :: AGSettings -> (Coloring, Coloring) -- | Swaps foreground and background colors within a Coloring. invert :: Coloring -> Coloring -- | SGR command to set the foreground to the specified -- AnsiColor. setFG :: AnsiColor -> SGR -- | SGR command to set the background to the specified -- AnsiColor. setBG :: AnsiColor -> SGR -- | Clear any SGR settings, then print a new line and flush stdout. lineClear :: IO () -- | Clear any SGR settings and then flush stdout. clear :: IO () -- | Apply both foreground and background color. applyColor :: Coloring -> IO () -- | Use a particular ANSI Coloring to print a string at the -- terminal (without a newline), then clear all ANSI SGR codes and flush -- stdout. colorStr :: Coloring -> String -> IO () -- | Use a particular ANSI Coloring to print a string at the -- terminal, then clear all ANSI SGR codes, print a newline and flush -- stdout. colorStrLn :: Coloring -> String -> IO () -- | Wrapper type for graph of a real vector/function newtype Graph Graph :: [Double] -> Graph [unGraph] :: Graph -> [Double] -- | Wrapper type for graph of a complex vector/function newtype CGraph CGraph :: [Complex Double] -> CGraph [unCGraph] :: CGraph -> [Complex Double] -- | Wrapper type for graph of a non-negative real vector/function newtype PosGraph PosGraph :: [Double] -> PosGraph [unPosGraph] :: PosGraph -> [Double] -- | Wrapper type for graph of a real two-index vector/two-argument -- function newtype Mat Mat :: [[Double]] -> Mat [unMat] :: Mat -> [[Double]] -- | Wrapper type for graph of a complex two-index vector/two-argument -- function newtype CMat CMat :: [[Complex Double]] -> CMat [unCMat] :: CMat -> [[Complex Double]] -- | ANSI based display for real vectors. To be primarily invoked via -- graph, graphWith, animate, -- animateWith. displayRV :: AGSettings -> [Double] -> IO () -- | ANSI based display for complex vectors. To be primarily invoked via -- graph, graphWith, animate, -- animateWith. displayCV :: AGSettings -> [Complex Double] -> IO () -- | ANSI based display for positive real vectors. To be primarily invoked -- via graph, graphWith, animate, -- animateWith. displayPV :: AGSettings -> [Double] -> IO () -- | Simple vector rendering. Yields a string of unicode chars representing -- graph bars varying in units of 1/8. To be primarily invoked via -- graph, graphWith, animate, -- animateWith. simpleRender :: [Double] -> String -- | Simple vector rendering – inverted version. Rarely used directly. It -- is needed to render negative graph regions. simpleRenderR :: [Double] -> String -- | Given a matrix of Doubles, return the list of strings illustrating the -- absolute value of each entry relative to the largest, via unicode -- chars that denote a particular density. matShow :: [[Double]] -> [String] -- | Use ANSI coloring (specified by an AGSettings) to visually -- display a Real matrix. displayMat :: AGSettings -> [[Double]] -> IO () -- | Use ANSI coloring (specified by an AGSettings) to visually -- display a Complex matrix. displayCMat :: AGSettings -> [[Complex Double]] -> IO () -- | Display a graph of the supplied (non-negative) real vector. posgraph :: [Double] -> IO () -- | Display an animation of the supplied list of (non-negative) real -- vectors. posanim :: [[Double]] -> IO () instance System.Console.Ansigraph.Core.Graphable System.Console.Ansigraph.Core.Graph instance System.Console.Ansigraph.Core.Graphable System.Console.Ansigraph.Core.CGraph instance System.Console.Ansigraph.Core.Graphable System.Console.Ansigraph.Core.PosGraph instance System.Console.Ansigraph.Core.Graphable System.Console.Ansigraph.Core.Mat instance System.Console.Ansigraph.Core.Graphable System.Console.Ansigraph.Core.CMat -- | This is the primary module to import for use of the ansigraph package, -- which provides terminal-based graphing for vectors and matrices of -- real and complex numbers. -- -- This functionality is implemented via a Graphable type class. -- -- Ansigraph is intended to be used in on of two ways: -- -- module System.Console.Ansigraph -- | A module that exports some simple demonstrations of how to use the -- package. module System.Console.Ansigraph.Examples -- | Display an animation of the complex wave z(x,t) = exp(ix - it) -- in some units. waveDemo :: IO () -- | Display an animation of the real function r(x,t) = cos(x-t) in -- the standard style, i.e. with both positive and negative regions. waveDemoR :: IO () -- | Display an animation of the positive real function p(x,t) = -- cos(x-t) + 1 in some units. waveDemoP :: IO () -- | Show all of the available AnsiColors and corresponding -- ColorIntensity, Color pairs. showColors :: IO () -- | Run all of the demos in sequence. demo :: IO () wave :: [Complex Double]