| 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 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.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
- execScriptMFast :: ScriptM Preamble () -> ProcScript
- module Graphics.Web.Processing.Core.Var
- 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.
Script
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.
execScriptMFast :: ScriptM Preamble () -> ProcScriptSource
Like execScriptM, but skips optimizations.