-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Web graphic applications with processing.js. -- -- Processing is a visual design programming language. -- Processing.js is the sister project of Processing designed for -- the web. The Haskell processing package is a web animation -- library with Processing.js as backend. -- -- What is this for? -- -- With this library you are able to write scripts that, once executed in -- a browser, will execute interactive visual programs. -- -- Where can I see a running example? -- -- Running examples are provided in the examples directory. These -- are some of the outputs: -- -- -- -- The code of the latter is included in the source distribution. -- -- How do I learn to use it? -- -- The API reference of the library includes guidance and is complemented -- with code examples. Look also to the examples directory -- included in the source distribution. It contains some fully working -- examples. Also online at: -- -- https://github.com/Daniel-Diaz/processing/tree/master/examples -- -- The library provides different APIs (interfaces). Each one with a -- different philosophy. -- -- -- -- The module Graphics.Web.Processing.Html helps you to create the -- HTML document where you will display the animation. @package processing @version 1.2.0.0 -- | Module exporting Var and ArrayVar type and functions. module Graphics.Web.Processing.Core.Var -- | Type of variables. data Var a -- | Type of variables storing arrays. data ArrayVar a -- | Size of the array. arraySize :: ArrayVar a -> Int -- | Get the name of a variable. varName :: Var a -> Text -- | Get the name of a variable storing an array. arrayVarName :: ArrayVar a -> Text -- | Create a new variable with a starting value. newVar :: (ProcMonad m, ProcType a) => a -> m Preamble (Var a) -- | Read a variable. readVar :: (ProcMonad m, ProcType a) => Var a -> m c a -- | Write a new value to a variable. writeVar :: (ProcMonad m, ProcType a) => Var a -> a -> m c () -- | Create a new array variable with a starting list of values. newArrayVar :: (ProcMonad m, ProcType a) => [a] -> m Preamble (ArrayVar a) -- | Read a component of an array variable. readArrayVar :: (ProcMonad m, Monad (m c), ProcType a) => ArrayVar a -> Proc_Int -> m c a -- | Write a component of an array variable. writeArrayVar :: (ProcMonad m, ProcType a) => ArrayVar a -> Proc_Int -> a -> m c () -- | Code optimization module. module Graphics.Web.Processing.Optimize -- | Optimization by substitution. It looks for commonly repeated -- operations and create variables for them so they are only calculated -- once. -- -- This optimization is applied automatically when using -- execScriptM. -- -- Look at the generated to code to see which substitutions have been -- made. They are delimited by comments, with title Substitution -- Optimization settings. If this is not present, no substitution has -- been made. optimizeBySubstitution :: ProcScript -> ProcScript -- | Optimizations are projections. In particular: -- --
--   let f = optimizeBySubstitution
--   in  f x == f (f x)
--   
-- -- This function checks that this equality holds for a given x. -- Apply it to your own script to check that the property is true. Tests -- has been applied to randomly generated scripts, but for them, -- fid. prop_optimizeBySubstitution_projection :: ProcScript -> Bool instance Optimizable Proc_Float instance Optimizable Proc_Int instance Optimizable Proc_Bool -- | Collection of types (Proc_* types and others), and some -- functions on these types as well. module Graphics.Web.Processing.Core.Types -- | A complete Processing script. -- -- It consists in several parts, most of them optional. -- -- To generate each part of the code, use the ProcM monad and -- the functions from the Graphics.Web.Processing.Interface -- module. Then, run runProcM or execProcM to get the -- code result. -- -- More abstract functions generate ProcScript values as well. See -- modules Graphics.Web.Processing.Mid and -- Graphics.Web.Processing.Simple for two alternative ways. data ProcScript ProcScript :: ProcCode Preamble -> ProcCode Setup -> Maybe (ProcCode Draw) -> Maybe (ProcCode MouseClicked) -> Maybe (ProcCode MouseReleased) -> Maybe (ProcCode KeyPressed) -> ProcScript proc_preamble :: ProcScript -> ProcCode Preamble proc_setup :: ProcScript -> ProcCode Setup proc_draw :: ProcScript -> Maybe (ProcCode Draw) proc_mouseClicked :: ProcScript -> Maybe (ProcCode MouseClicked) proc_mouseReleased :: ProcScript -> Maybe (ProcCode MouseReleased) proc_keyPressed :: ProcScript -> Maybe (ProcCode KeyPressed) -- | Empty script. emptyScript :: ProcScript -- | Render a script as a lazy Text. renderScript :: ProcScript -> Text -- | Render a script using renderScript and write it directly in a -- file. renderFile :: FilePath -> ProcScript -> IO () -- | A piece of Processing code. The type parameter indicates what the -- context of the code is. This context will allow or disallow the use of -- certain commands along different events. data ProcCode c -- | The preamble is the code that is executed at the beginning of -- the script. data Preamble Preamble :: Preamble -- | In the setup part, settings like size or frame -- rate are supplied. data Setup Setup :: Setup -- | The drawing loop. data Draw Draw :: Draw -- | Code that is executed when the mouse is clicked. data MouseClicked MouseClicked :: MouseClicked -- | Code that is executed when the mouse is released. data MouseReleased MouseReleased :: MouseReleased -- | Code executed when a key is pressed. data KeyPressed KeyPressed :: KeyPressed -- | Class of Processing value types (Proc_* types). -- -- Proc_* types are types from the world of Processing. Some of -- them are similar to Haskell types, like Proc_Bool and -- Bool. However, they are not equal. Proc_* types are -- instance of Eq. However, you should instead use methods from -- the analog Proc_Eq class. Proc_* types contain -- expressions instead of values. Think of 2+2 instead of -- 4. Under this situation, 2+2 /= 3+1, since they are -- different expressions, even if they evaluate to the same value. -- Actually, you will get True from the evaluation of 2+2 == -- 3+1, since the library is smart enough to figure out they have -- the same value. But, please, don't rely on this. Use the -- Proc_Eq and Proc_Ord classes instead. They return -- Processing boolean expressions instead of Bool values. Anyway, -- the types of the library will try to force you to use Proc_* -- types everywhere. -- -- The reason this library stores expressions instead of values is that -- it needs to handle things like 2+x, where x is an -- unknown value. However, an effort is done to ensure that each -- expression is reduced to its minimum extension. class ProcType a -- | Boolean values. data Proc_Bool -- | Value of True. true :: Proc_Bool -- | Value of False. false :: Proc_Bool -- | Cast a Bool value. fromBool :: Bool -> Proc_Bool -- | Negation. pnot :: Proc_Bool -> Proc_Bool -- | Disjunction. (#||) :: Proc_Bool -> Proc_Bool -> Proc_Bool -- | Conjunction. (#&&) :: Proc_Bool -> Proc_Bool -> Proc_Bool -- | Integer numbers. data Proc_Int -- | Cast an Int value. fromInt :: Int -> Proc_Int -- | Cast a Proc_Int to a Proc_Float. intToFloat :: Proc_Int -> Proc_Float -- | Floating point numbers. The provided Eq instance checks the -- equality of the internal expression, not the value. data Proc_Float -- | Cast a Float value. fromFloat :: Float -> Proc_Float -- | Calculate the floor of a Proc_Float. pfloor :: Proc_Float -> Proc_Int -- | Round a number to the closest integer. pround :: Proc_Float -> Proc_Int -- | Type of characters. data Proc_Char -- | Cast a Char value. fromChar :: Char -> Proc_Char -- | Type of textual values. -- -- It is recommended to enable the OverloadedStrings extension. -- Note that Proc_Text is an instance of the IsString -- class. data Proc_Text -- | Cast a strict Text value. fromStText :: Text -> Proc_Text -- | Append two text strings. (+.+) :: Proc_Text -> Proc_Text -> Proc_Text -- | Similar to the Show class, but for Proc_* types. class Proc_Show a pshow :: Proc_Show a => a -> Proc_Text -- | Type of images. data Proc_Image -- | Eq class for Proc_* values. class Proc_Eq a where x #== y = pnot $ x #/= y x #/= y = pnot $ x #== y (#==) :: Proc_Eq a => a -> a -> Proc_Bool (#/=) :: Proc_Eq a => a -> a -> Proc_Bool -- | Ord class for Proc_* values. class Proc_Ord a (#<=) :: Proc_Ord a => a -> a -> Proc_Bool (#<) :: Proc_Ord a => a -> a -> Proc_Bool (#>=) :: Proc_Ord a => a -> a -> Proc_Bool (#>) :: Proc_Ord a => a -> a -> Proc_Bool -- | Conditional value. For example: -- --
--   if_ (x #> 3) "X is greater than 3."
--                "X is less than or equal to 3."
--   
if_ :: ProcType a => Proc_Bool -> a -> a -> a -- | Variables, commands and functions. The interface to the -- processing.js API (http://processingjs.org/reference), with -- some additions, deletions and modifications. module Graphics.Web.Processing.Core.Interface -- | Width of the canvas. screenWidth :: Proc_Int -- | Height of the canvas. screenHeight :: Proc_Int -- | Write a variable with a random number within an interval. random :: ProcMonad m => Var Proc_Float -> Proc_Float -> Proc_Float -> m c () -- | Noise random function. noise :: (ProcMonad m, Monad (m c)) => Proc_Point -> m c Proc_Float -- | Class of contexts where the user can draw pictures in the screen. class Drawing a -- | RGBA colors. Values must be between 0 and 255, including in the alpha -- channel. data Color Color :: Proc_Int -> Proc_Int -> Proc_Int -> Proc_Int -> Color -- | Red channel. redc :: Color -> Proc_Int -- | Blue channel. bluec :: Color -> Proc_Int -- | Green channel. greenc :: Color -> Proc_Int -- | Alpha channel (opacity). 0 means transparent, and 255 opaque. alphac :: Color -> Proc_Int -- | Set the drawing color. stroke :: (ProcMonad m, Drawing c) => Color -> m c () -- | Set the filling color. fill :: (ProcMonad m, Drawing c) => Color -> m c () -- | Fill the screen with a given color. background :: (ProcMonad m, Drawing c) => Color -> m c () -- | Set the weight of the lines. strokeWeight :: (ProcMonad m, Drawing c) => Proc_Int -> m c () -- | A point as a pair of floating point numbers. type Proc_Point = (Proc_Float, Proc_Float) -- | Draw a ellipse. ellipse :: (ProcMonad m, Drawing c) => Proc_Point -> Proc_Float -> Proc_Float -> m c () -- | Draw a circle. circle :: (ProcMonad m, Drawing c) => Proc_Point -> Proc_Float -> m c () -- | Draw an arc. -- -- The arc is drawn following the line of an ellipse between two angles. arc :: (ProcMonad m, Drawing c) => Proc_Point -> Proc_Float -> Proc_Float -> Proc_Float -> Proc_Float -> m c () -- | Draw a line. line :: (ProcMonad m, Drawing c) => Proc_Point -> Proc_Point -> m c () -- | Prints a dot. point :: (ProcMonad m, Drawing c) => Proc_Point -> m c () -- | A quad is a quadrilateral, a four sided polygon. The first parameter -- is the first vertex and the subsequent parameters should proceed -- clockwise or counter-clockwise around the defined shape. quad :: (ProcMonad m, Drawing c) => Proc_Point -> Proc_Point -> Proc_Point -> Proc_Point -> m c () -- | Draws a rectangle to the screen. A rectangle is a four-sided shape -- with every angle at ninety degrees. The first parameter set the -- location, the second sets the width, and the third sets the height. rect :: (ProcMonad m, Drawing c) => Proc_Point -> Proc_Float -> Proc_Float -> m c () -- | A triangle is a plane created by connecting three points. triangle :: (ProcMonad m, Drawing c) => Proc_Point -> Proc_Point -> Proc_Point -> m c () -- | Bézier curve. bezier :: (ProcMonad m, Drawing c) => Proc_Point -> Proc_Point -> Proc_Point -> Proc_Point -> m c () -- | Polygon drawer. polygon :: (ProcMonad m, Monad (m c), Drawing c) => [Proc_Point] -> m c () -- | Display a text in the screen. The color is specified by fill. drawtext :: (ProcMonad m, Drawing c) => Proc_Text -> Proc_Point -> Proc_Float -> Proc_Float -> m c () -- | Set the size of the canvas. size :: ProcMonad m => Proc_Int -> Proc_Int -> m c () -- | Specify the number of frames to be displayed every second. The default -- rate is 60 frames per second. setFrameRate :: ProcMonad m => Proc_Int -> m Setup () -- | Move the current position. translate :: (ProcMonad m, Drawing c) => Proc_Float -> Proc_Float -> m c () -- | Apply a rotation to the following pictures, centered at the current -- position. rotate :: (ProcMonad m, Drawing c) => Proc_Float -> m c () -- | Apply a scaling to the following pictures, centered at the current -- position. scale :: (ProcMonad m, Drawing c) => Proc_Float -> Proc_Float -> m c () -- | Reset the transformation matrix. resetMatrix :: (ProcMonad m, Drawing c) => m c () -- | Get the current position of the mouse pointer. getMousePoint :: (ProcMonad m, Monad (m c)) => m c Proc_Point -- | Keyboard keys recognized by Processing. data Key CharKey :: Char -> Key SpecialKey :: SpecialKey -> Key ArrowKey :: ArrowKey -> Key ModKey :: KeyModifier -> Key -> Key -- | Arrow keys. data ArrowKey UP :: ArrowKey DOWN :: ArrowKey LEFT :: ArrowKey RIGHT :: ArrowKey -- | Key modifiers. data KeyModifier ALT :: KeyModifier CONTROL :: KeyModifier SHIFT :: KeyModifier -- | Special keys. data SpecialKey BACKSPACE :: SpecialKey TAB :: SpecialKey ENTER :: SpecialKey RETURN :: SpecialKey ESC :: SpecialKey -- | This function takes a variable of type Proc_Bool and a -- Key, and sets the variable to true if the key pressed is -- the given Key. Otherwise, the variable is set to false. matchKey :: (ProcMonad m, Monad (m KeyPressed)) => Var Proc_Bool -> Key -> m KeyPressed () -- | Conditional execution. When the boolean value is true, it -- executes the first monadic argument. Otherwise, it executes the other -- one. In any case, the result is discarded. See also if_. ifM :: ProcMonad m => Proc_Bool -> m c a -> m c b -> m c () -- | Frames since the beginning of the script execution. frameCount :: (ProcMonad m, Monad (m c)) => m c Proc_Int -- | Approximate number of frames per second. getFrameRate :: (ProcMonad m, Monad (m c)) => m c Proc_Int -- | Include a comment in the current position of the code. You normally -- don't need to read the processing.js code output, but this function -- can be useful to analyse or debug it. comment :: ProcMonad m => Text -> m c () -- | Types in this instance form a monad when they are applied to a context -- c. They are used to write Processing code. class ProcMonad m instance Drawing MouseReleased instance Drawing MouseClicked instance Drawing Draw instance Drawing Setup -- | The basic interface is the closest to the original. Although it -- contains some variations too. -- -- For several reasons, it is recommended to use the mid interface -- instead, which can be found in the Graphics.Web.Processing.Mid -- module. module Graphics.Web.Processing.Basic -- | Processing script producer monad. The context c indicates the -- context of the underlying ProcCode. This context restricts the -- use of certain commands only to places where they are expected. -- -- The commands that you can run under this monad are mostly defined in -- Graphics.Web.Processing.Interface. -- -- Once you have all the commands you want, use runProcM or -- execProcM to generate the corresponding Processing code under -- the ProcCode type. data ProcM c a -- | Generate Processing code using the ProcM monad. The code output -- is reduced. runProcM :: ProcM c a -> (a, ProcCode c) -- | Generate Processing code using the ProcM monad, discarding the -- final value. -- --
--   execProcM = snd . runProcM
--   
execProcM :: ProcM c a -> ProcCode c -- | Processing scripting, mid interface. Unlike the basic -- interface (see Graphics.Web.Processing.Basic) the script is -- more guided by the types. However, the output is less predictable, -- since it does some tricks in order to obtain semantics that are more -- coherent with Haskell. The difference is small, but let's say that -- this module has more freedom writing the output code. It also applies -- code optimizations, so the output code may look different (see -- execScriptM and Graphics.Web.Processing.Optimize). -- -- How to work with it? -- -- Everything is done within the ScriptM monad, a state monad that -- controls the entire script, including the preamble, draw loop, setup, -- etc. The interaction with the different parts of the script is done -- via events (see EventM). For example, the Draw -- event controls the draw loop. -- --
--   mouse :: ScriptM Preamble ()
--   mouse = do
--     on Setup $ do
--        size screenWidth screenHeight
--        fill $ Color 255 255 255 255
--     on Draw  $ do
--        background $ Color 0 0 0 255
--        p <- getMousePoint
--        circle p 10
--   
-- -- Note that to make it work, the context of the script must be -- Preamble. -- -- Interaction with variables is done via the interface provided by the -- Graphics.Web.Processing.Core.Var module. This module defines -- functions to interact with variables in both the ScriptM monad -- and the EventM monad. To store custom types in variables, see -- the Graphics.Web.Processing.Mid.CustomVar module (you have to -- import this module separately). -- -- Once your script is complete, use execScriptM to get the result -- code. module Graphics.Web.Processing.Mid -- | Context of an event. The context determines which functions can be -- used. Preamble is not an instance of Context to avoid -- using Preamble as an event (see on). class Context c -- | Monad of events. Use on to insert an event in a script -- (ScriptM). To write the event code, use the functions in -- Graphics.Web.Processing.Core.Interface, since EventM is -- an instance of ProcMonad. data EventM c a -- | Scripter monad. This monad is where Processing code is written. -- Because of some implementation details, ScriptM has a context -- c. However, this context is always Preamble. data ScriptM c a -- | Set an event. Different events are specified by the instances of the -- Context class. -- -- For example, the following code sets the fill pattern in the -- setup event (the event that is called once at the beginning of the -- execution). -- --
--   on Setup $ fill $ Color 0 0 0 255
--   
on :: Context c => c -> EventM c () -> ScriptM Preamble () -- | Execute the scripter monad to get the full Processing script. Use -- renderScript or renderFile to render it. -- -- After generating the script, the output code is optimized using -- optimizeBySubstitution. execScriptM :: ScriptM Preamble () -> ProcScript -- | Like execScriptM, but skips optimizations. execScriptMFast :: ScriptM Preamble () -> ProcScript instance Context KeyPressed instance Context MouseReleased instance Context MouseClicked instance Context Draw instance Context Setup instance ProcMonad ScriptM instance Monad (ScriptM c) instance Applicative (ScriptM c) instance Functor (ScriptM c) instance ProcMonad EventM instance Monad (EventM c) instance Applicative (EventM c) instance Functor (EventM c) -- | This module re-exports the mid interface to processing. module Graphics.Web.Processing -- | This module implements variables which may contain values from types -- different from the native types (Proc_* types). -- -- To make a type available to custom variables, it needs to be -- instantiated in the CustomValue class, which is subclass of the -- VarLength class. These instances are derivables using the -- DeriveGeneric extension. Things you need are: enable the -- DeriveGeneric language extension, import GHC.Generics, -- derive a Generic instance of your type and then write the -- following instances (where Foo is any type of interest): -- --
--   instance VarLength Foo
--   instance CustomValue Foo
--   
-- -- Note that Foo must be made from other types that are -- instances of CustomValue. Also, note that instances of -- VarLength or CustomValue can not be recursive or -- sum types. An example: -- --
--   {-# LANGUAGE DeriveGeneric #-}
--   
--   import Graphics.Web.Processing.Mid
--   import Graphics.Web.Processing.Mid.CustomVar
--   import GHC.Generics
--   
--   data Point = Point Proc_Float Proc_Float
--                  deriving Generic
--   
--   instance VarLength Point
--   instance CustomValue Point
--   
-- -- Types instance of the CustomValue class can be contained by a -- special type of variables, called CustomVar (Custom Variable). -- Functions for custom variables are equal to the function for regular -- variables, except that they all end in C. For example, -- newVar is called newVarC for custom variables. -- -- There are also arrays which may contain custom values. See -- CustomArrayVar. -- -- The dependency of this module in several language extensions was the -- reason to make it separate from the rest of the mid interface -- where it belongs to. Somehow, it forces the user to use -- DeriveGeneric and import GHC.Generics to do something -- useful with it (more than use custom variables for tuples). module Graphics.Web.Processing.Mid.CustomVar -- | Variable with custom values. data CustomVar a -- | Array variable of custom values. data CustomArrayVar a -- | Size of the custom array. customArraySize :: CustomArrayVar a -> Int -- | Typeclass of values that can be stored in several native variables -- (Var). class VarLength a where varLength = gvarLength . from varLength :: VarLength a => a -> Int -- | Typeclass of custom values, which can be stored in custom variables -- (CustomVar). class VarLength a => CustomValue a where newVarC = liftM castCVar . gnewVarC . from newArrayVarC = liftM castCAVar . gnewArrayVarC . fmap from readVarC v = liftM to $ greadVarC (castCVar v) writeVarC v x = gwriteVarC (castCVar v) (from x) ifC b x y = to $ gifC b (from x) (from y) newVarC :: (CustomValue a, Monad (m Preamble), ProcMonad m) => a -> m Preamble (CustomVar a) newArrayVarC :: (CustomValue a, Monad (m Preamble), ProcMonad m) => [a] -> m Preamble (CustomArrayVar a) readVarC :: (CustomValue a, Monad (m c), ProcMonad m) => CustomVar a -> m c a writeVarC :: (CustomValue a, Monad (m c), ProcMonad m) => CustomVar a -> a -> m c () ifC :: CustomValue a => Proc_Bool -> a -> a -> a -- | Read a component of a custom array variable. readArrayVarC :: (ProcMonad m, Monad (m c), CustomValue a) => CustomArrayVar a -> Proc_Int -> m c a -- | Write a component of a custom array variable. writeArrayVarC :: (ProcMonad m, Monad (m c), CustomValue a) => CustomArrayVar a -> Proc_Int -> a -> m c () instance (CustomValue a, CustomValue b, CustomValue c) => CustomValue (a, b, c) instance (VarLength a, VarLength b, VarLength c) => VarLength (a, b, c) instance (CustomValue a, CustomValue b) => CustomValue (a, b) instance (VarLength a, VarLength b) => VarLength (a, b) instance CustomValue Proc_Char instance CustomValue Proc_Text instance CustomValue Proc_Image instance CustomValue Proc_Float instance CustomValue Proc_Int instance CustomValue Proc_Bool instance VarLength Proc_Char instance VarLength Proc_Text instance VarLength Proc_Image instance VarLength Proc_Float instance VarLength Proc_Int instance VarLength Proc_Bool instance Generic (CustomVar a) instance Datatype D1CustomVar instance Constructor C1_0CustomVar instance CustomValue a => GCustomValue (K1 i a) instance GCustomValue a => GCustomValue (M1 i c a) instance GCustomValue (a :+: b) instance (GVarLength a, GCustomValue a, GCustomValue b) => GCustomValue (a :*: b) instance VarLength a => GVarLength (K1 i a) instance GVarLength a => GVarLength (M1 i c a) instance GVarLength (a :+: b) instance (GVarLength a, GVarLength b) => GVarLength (a :*: b) instance GVarLength U1 -- | A Monoid models figures in the plane. Then, figures are -- displayed or animated using a Processing script. -- -- For example, this expression represents a circle of radius 10 centered -- at the origin: -- --
--   Circle (0,0) 10
--   
-- -- The origin will be represented at the center of the screen. As opposed -- to the other modules, y-coordinates increase to the top, while -- x-coordinates still increase to the right. -- -- This is a red rectangle with top-left corner at the origin, 10 points -- height and 10 points width: -- --
--   FillColor (Color 255 0 0 255) $ Rectangle (0,0) 10 10
--   
-- -- To display several figures together, use the Monoid instance: -- --
--   Circle (0,0) 10 <> Circle (0,20) 10
--   
-- -- If you just want to display this figure in the target canvas, use -- displayFigure. If you want to animate it, use -- animateFigure. Animations depend on the number of frames since -- the beginning of the execution, instead of in the time spent. -- -- Once you have created a processing script (a value of type -- ProcScript), use renderFile to write it to a file. See -- also the Graphics.Web.Processing.Html module. -- -- The default filling color and line color are white and black -- respectively. Use FillColor and LineColor to change -- these colors. Colors are in RGBA format, meaning that they may -- be transparent (with an alpha value of 0), opaque (with an alpha value -- of 255) or something in between. Use a fully transparent color to -- indicate that a Figure should not be filled. -- -- You can apply transformations like translation, rotation and scaling. -- If p is a point and f a figure, Translate p -- f will draw f with p as the origin of -- coordinates. Rotations and scalings are always done in respect to the -- origin, but note that you can modify where the origin is using -- Translate. module Graphics.Web.Processing.Simple -- | RGBA colors. Values must be between 0 and 255, including in the alpha -- channel. data Color Color :: Proc_Int -> Proc_Int -> Proc_Int -> Proc_Int -> Color -- | Red channel. redc :: Color -> Proc_Int -- | Blue channel. bluec :: Color -> Proc_Int -- | Green channel. greenc :: Color -> Proc_Int -- | Alpha channel (opacity). 0 means transparent, and 255 opaque. alphac :: Color -> Proc_Int -- | A point as a pair of floating point numbers. type Proc_Point = (Proc_Float, Proc_Float) -- | A path is just a list of points. type Path = [Proc_Point] -- | The monoid of plane figures. data Figure -- | Line joining a list of points. Line :: Path -> Figure -- | Polygon given a list of vertex. Polygon :: Path -> Figure -- | Ellipse centered at the given point, with width and height also -- specified. Ellipse :: Proc_Point -> Proc_Float -> Proc_Float -> Figure -- | Circle centered at the given point and with the specified radius. Circle :: Proc_Point -> Proc_Float -> Figure -- | Arc. The arc is drawn following the line of an ellipse between two -- angles. The first argument is the center of the ellipse. The next two -- arguments are the width and height of the ellipse. The last two -- arguments are the initial and end angles of the arc. Arc :: Proc_Point -> Proc_Float -> Proc_Float -> Proc_Float -> Proc_Float -> Figure -- | Rectangle such that the top-left corner is at the specified point, and -- its width and height are specified by the other two arguments. Rectangle :: Proc_Point -> Proc_Float -> Proc_Float -> Figure -- | Bezier curve. First and last arguments are the initial and end points -- of the curve. The other points are control points. Bezier :: Proc_Point -> Proc_Point -> Proc_Point -> Proc_Point -> Figure -- | Text. Text :: Proc_Point -> Proc_Text -> Figure -- | Set the line color of a figure. LineColor :: Color -> Figure -> Figure -- | Set the filling color of a figure. FillColor :: Color -> Figure -> Figure -- | Translate a figure in the direction of a vector. Translate :: Proc_Point -> Figure -> Figure -- | Rotate a figure by the given angle in radians. Rotate :: Proc_Float -> Figure -> Figure -- | Scale a figure by the given x and y factors. Scale :: Proc_Float -> Proc_Float -> Figure -> Figure -- | List of figures. Figures :: [Figure] -> Figure -- | Display a figure using a Processing script. displayFigure :: Maybe Int -> Maybe Int -> Color -> Figure -> ProcScript -- | Create a Processing animation from a Figure-valued function. animateFigure :: Maybe Int -> Maybe Int -> Int -> Color -> (Proc_Int -> Figure) -> ProcScript -- | Framework to create interactive scripts. -- -- Note that is required for the state to be an instance of -- CustomValue. More info on how to instantiate a type in the -- CustomValue class in the -- Graphics.Web.Processing.Mid.CustomVar module. interactiveFigure :: CustomValue w => Maybe Int -> Maybe Int -> Int -> w -> (w -> Figure) -> (w -> Color) -> (Proc_Int -> w -> w) -> (Proc_Point -> w -> w) -> [(Key, w -> w)] -> ProcScript -- | Keyboard keys recognized by Processing. data Key CharKey :: Char -> Key SpecialKey :: SpecialKey -> Key ArrowKey :: ArrowKey -> Key ModKey :: KeyModifier -> Key -> Key -- | Arrow keys. data ArrowKey UP :: ArrowKey DOWN :: ArrowKey LEFT :: ArrowKey RIGHT :: ArrowKey -- | Key modifiers. data KeyModifier ALT :: KeyModifier CONTROL :: KeyModifier SHIFT :: KeyModifier -- | Special keys. data SpecialKey BACKSPACE :: SpecialKey TAB :: SpecialKey ENTER :: SpecialKey RETURN :: SpecialKey ESC :: SpecialKey instance Monoid Figure -- | Once created, processing scripts can be included in HTML canvas. To be -- able to reproduce the animation, you must import the -- processing.js library, downloadable from -- http://processingjs.org/download (do not import it from the -- original link, download it and use your own copy). To import -- processing.js, use a script tag. -- --
--   <script src="processing.js"></script>
--   
-- -- See importScript. -- -- Note from the author: I didn't manage to run a processing animation -- locally, so you may have the same issue. Once I uploaded them -- to my server, they worked just fine. module Graphics.Web.Processing.Html -- | Create a canvas element which contain a Processing animation. The -- output is of the following form: -- --
--   <canvas data-processing-sources="specified path"></canvas>
--   
procCanvas :: FilePath -> Html -- | Create the following HTML element: -- --
--   <script src="specified path"></script>
--   
-- -- Use it to import the processing.js script, inside the -- head tag. importScript :: FilePath -> Html -- | Default template for visualizing Processing scripts in HTML. defaultHtml :: FilePath -> FilePath -> Text -> Html -- | Write a Processing script and the HTML default template for it to -- files, using renderFile and defaultHtml. All the -- FilePaths must be relative to where the HTML file is written. writeHtml :: FilePath -> FilePath -> Text -> FilePath -> ProcScript -> IO ()