processing-1.0.0.1: Web graphic applications with Processing.

Safe HaskellNone

Graphics.Web.Processing.Mid

Contents

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.

Synopsis

Types

Contexts

class Context c Source

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).

Events

data EventM c a Source

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

data ScriptM c a Source

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.

on :: Context c => c -> EventM c () -> ScriptM Preamble ()Source

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

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

data Var a Source

Type of variables.

varName :: Var a -> TextSource

Get the name of a variable.

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.

Interface