gloss-1.13.1.2: Painless 2D vector graphics, animations and simulations.

Safe Haskell | None
Language | Haskell2010

Graphics.Gloss

Description

Gloss hides the pain of drawing simple vector graphics behind a nice data type and a few display functions.

Getting something on the screen is as easy as:

     import Graphics.Gloss
     main = display (InWindow "Nice Window" (200, 200) (10, 10)) white (Circle 80)

Once the window is open you can use the following:

    * Quit
      - esc-key

    * Move Viewport
      - arrow keys
      - left-click drag

    * Zoom Viewport
      - page up/down-keys
      - control-left-click drag
      - right-click drag
      - mouse wheel

    * Rotate Viewport
      - home/end-keys
      - alt-left-click drag

    * Reset Viewport
      r-key

Animations can be constructed similarly using the `animate`.

If you want to run a simulation based around finite time steps then try `simulate`.

If you want to manage your own key/mouse events then use `play`.

Gloss uses OpenGL under the hood, but you don't have to worry about any of that.

Gloss programs should be compiled with `-threaded`, otherwise the GHC runtime will limit the frame-rate to around 20Hz.

To build gloss using the GLFW window manager instead of GLUT use `cabal install gloss --flags="GLFW -GLUT"`

    Release Notes:

     For 1.13.1:
      Thanks to Thaler Jonathan
      * Repaired GLFW backend.
      Thanks to Samuel Gfrörer
      * Support for bitmap sections.
      Thanks to Basile Henry
      * Handle resize events in playField driver.

     For 1.12.1:
      Thanks to Trevor McDonell
      * Travis CI integration, general cleanups.

     For 1.11.1:
      Thanks to Lars Wyssard
      * Use default display resolution in full-screen mode.

     For 1.10.1:
      * Gloss no longer consumes CPU time when displaying static pictures.
      * Added displayIO wrapper for mostly static pictures, eg when
        plotting graphs generated from infrequently updated files.
      * Allow viewport to be scaled with control-left-click drag.
      * Rotation of viewport changed to alt-left-click drag.
      * Preserve current colour when rendering bitmpaps.
      * Changed to proper sum-of-squares colour mixing, rather than naive
        addition of components which was causing mixed colours to be too dark.
     Thanks to Thomas DuBuisson
      * Allow bitmaps to be specified in RGBA byte order as well as ABGR.
     Thanks to Gabriel Gonzalez
      * Package definitions for building with Stack.

For more information, check out http://gloss.ouroborus.net.

Synopsis

- module Graphics.Gloss.Data.Picture
- module Graphics.Gloss.Data.Color
- module Graphics.Gloss.Data.Bitmap
- data Display
  - = InWindow String (Int, Int) (Int, Int)
  - | FullScreen
- display :: Display -> Color -> Picture -> IO ()
- animate :: Display -> Color -> (Float -> Picture) -> IO ()
- simulate :: Display -> Color -> Int -> model -> (model -> Picture) -> (ViewPort -> Float -> model -> model) -> IO ()
- play :: Display -> Color -> Int -> world -> (world -> Picture) -> (Event -> world -> world) -> (Float -> world -> world) -> IO ()

# Documentation

module Graphics.Gloss.Data.Picture

module Graphics.Gloss.Data.Color

module Graphics.Gloss.Data.Bitmap

data Display Source #

Describes how Gloss should display its output.

Constructors

InWindow String (Int, Int) (Int, Int) | Display in a window with the given name, size and position.
FullScreen | Display full screen.

#### Instances

Instances details

Eq Display Source # |
Instance details Defined in Graphics.Gloss.Data.Display Methods (==) :: Display -> Display -> Bool (/=) :: Display -> Display -> Bool
Read Display Source # |
Instance details Defined in Graphics.Gloss.Data.Display Methods readsPrec :: Int -> ReadS Display readList :: ReadS [Display] readPrec :: ReadPrec Display readListPrec :: ReadPrec [Display]
Show Display Source # |
Instance details Defined in Graphics.Gloss.Data.Display Methods showsPrec :: Int -> Display -> ShowS show :: Display -> String showList :: [Display] -> ShowS

display Source #

Arguments

:: Display | Display mode.
-> Color | Background color.
-> Picture | The picture to draw.
-> IO () |

Open a new window and display the given picture.

animate Source #

Arguments

:: Display | Display mode.
-> Color | Background color.
-> (Float -> Picture) | Function to produce the next frame of animation. It is passed the time in seconds since the program started.
-> IO () |

Open a new window and display the given animation.

Once the window is open you can use the same commands as with `display`.

simulate Source #

Arguments

:: Display | Display mode.
-> Color | Background color.
-> Int | Number of simulation steps to take for each second of real time.
-> model | The initial model.
-> (model -> Picture) | A function to convert the model to a picture.
-> (ViewPort -> Float -> model -> model) | A function to step the model one iteration. It is passed the current viewport and the amount of time for this simulation step (in seconds).
-> IO () |

Run a finite-time-step simulation in a window. You decide how the model is represented, how to convert the model to a picture, and how to advance the model for each unit of time. This function does the rest.

Once the window is open you can use the same commands as with `display`.

play Source #

Arguments

:: Display | Display mode.
-> Color | Background color.
-> Int | Number of simulation steps to take for each second of real time.
-> world | The initial world.
-> (world -> Picture) | A function to convert the world a picture.
-> (Event -> world -> world) | A function to handle input events.
-> (Float -> world -> world) | A function to step the world one iteration. It is passed the period of time (in seconds) needing to be advanced.
-> IO () |

Play a game in a window. Like `simulate`, but you manage your own input events.