Safe Haskell | None |
---|
Graphics.Web.Processing.Mid
Description
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 ProcVarMonad
class.
This class defines methods 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.
Once your script is complete, use execScriptM
to get the result
code.
- module Graphics.Web.Processing.Core.Types
- class Context c
- data EventM c a
- data ScriptM c a
- on :: Context c => c -> EventM c () -> ScriptM Preamble ()
- execScriptM :: ScriptM Preamble () -> ProcScript
- data Var a
- varName :: Var a -> Text
- class ProcMonad m => ProcVarMonad m where
- module Graphics.Web.Processing.Core.Interface
Types
Contexts
Events
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
.
Instances
ProcMonad EventM | |
ProcVarMonad EventM | |
Monad (EventM c) | |
Functor (EventM c) | |
Applicative (EventM c) |
Script
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
.
Instances
ProcMonad ScriptM | |
ProcVarMonad ScriptM | |
Monad (ScriptM c) | |
Functor (ScriptM c) | |
Applicative (ScriptM c) |
execScriptM :: ScriptM Preamble () -> ProcScriptSource
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
.
Variables
class ProcMonad m => ProcVarMonad m whereSource
Class of monads where variables can be set in a natural
way (similar to IORef
). Instances of this class behave
in a proper way, without the weird behavior of the original
readVar
.
Methods
newVar :: ProcType a => a -> m Preamble (Var a)Source
Create a new variable with a starting value.
readVar :: ProcType a => Var a -> m c aSource
Read a variable.
writeVar :: ProcType a => Var a -> a -> m c ()Source
Write a new value to a variable.
Instances