shine-varying-0.1.0.0: FRP interface for shine using the varying package

Copyright(c) Francesco Gazzetta, 2016
LicenseMIT
Maintainerfrancygazz@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell98

Graphics.Shine.FRP.Varying

Contents

Description

This package lets you interact with the screen Elm-style. This is especially useful for small games or visualizations. You can get something on the screen quickly using the Vars provided below.

Try to run this:

import Graphics.Shine.FRP.Varying
import Graphics.Shine
import Graphics.Shine.Picture
import Graphics.Shine.Image
import GHCJS.DOM (webViewGetDomDocument, runWebGUI)

resizeImage img (x',y') = Translate (x/2) (y/2) -- Pictures are centered on (0,0), so we need to move it
                        $ Image (Stretched x y) img -- Scale de picture to the given position
  where
    x = fromIntegral x' -- mousePosition is Integral
    y = fromIntegral y'

main :: IO ()
main = runWebGUI $ \ webView -> do
    ctx <- fixedSizeCanvas webView 1024 768
    Just doc <- webViewGetDomDocument webView
    narwhal <- makeImage "https://wiki.haskell.org/wikiupload/8/85/NarleyYeeaaahh.jpg"
    let resizedNarwhal = resizeImage narwhal <$> mousePosition
    playVarying ctx doc 30 resizedNarwhal

Synopsis

Documentation

data ShineInput Source

Datatype representing all possible inputs coming from shine's main loop

Constructors

Input Input

An input event (keypress, mousemove...)

Time Float

An advancement in time

Running the Var

playVarying Source

Arguments

:: (IsEventTarget eventElement, IsDocument eventElement) 
=> CanvasRenderingContext2D

The context to draw on

-> eventElement

the element used to catch events

-> Float

FPS

-> Var ShineInput Picture

A Var that maps time and input events to a Picture

-> IO () 

Feed the input to the Var and draw the result

playVaryingIO Source

Arguments

:: (IsEventTarget eventElement, IsDocument eventElement) 
=> CanvasRenderingContext2D

The context to draw on

-> eventElement

the element used to catch events

-> Float

FPS

-> VarT IO ShineInput Picture

An effectful VarT that maps time and input events to a Picture

-> IO () 

Feed the input to the VarT IO and draw the result

Useful Vars

timeDeltaNumeric :: Monad m => VarT m ShineInput Float Source

Time delta. On non-time inputs the value is 0.

timeDeltaEvent :: Monad m => VarT m ShineInput (Event Float) Source

Time delta. On non-time inputs the value is NoEvent.

time :: Monad m => VarT m ShineInput Float Source

Time since beginning.

isDownButton :: Monad m => MouseBtn -> VarT m ShineInput Bool Source

Whether a mouse button is pressed.

isDownKey :: Monad m => Key -> VarT m ShineInput Bool Source

Whether a key is pressed.

mousePosition :: Monad m => VarT m ShineInput (Int, Int) Source

The pointer's position, relative to the canvas. The top-left corner is the origin.

mouseButtonsDown :: Monad m => VarT m ShineInput [MouseBtn] Source

A list of mouse buttons that are currently being pressed.

keysDown :: Monad m => VarT m ShineInput [Key] Source

A list of keys that are currently being pressed.