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 = displayInWindow "My Window" (200, 200) (10, 10) white (Circle 80)
Once the window is open you can use the following:
- Quit - esc-key.
- Move Viewport - left-click drag, arrow keys.
- Rotate Viewport - right-click drag, control-left-click drag, or home/end-keys.
- Zoom Viewport - mouse wheel, or page up/down-keys.
Animations can be constructed similarly using the animateInWindow.
If you want to run a simulation based around finite time steps then try
simulateInWindow.
If you want to manage your own key/mouse events then use gameInWindow.
Gloss uses OpenGL under the hood, but you don't have to worry about any of that.
Release Notes:
For 1.5.0:
* O(1) Conversion of ForeignPtrs to bitmaps.
* An extra flag on the Bitmap constructor allows bitmaps to be cached
in texture memory between frames.
For 1.4.0:
Thanks to Christiaan Baaij:
* Refactoring of Gloss internals to support multiple window manager backends.
* Support for using GLFW as the window library instead of GLUT.
GLUT is still the default, but to use GLFW install gloss with:
cabal install gloss --flags="GLFW -GLUT"
For 1.3.0:
* Various wibbles for GHC 7.1
Thanks to Ben Lambert-Smith:
* Support for displaying bitmap files.
For 1.2.0:
* Cleaned up module hierarchy.
* Added line-line intersection utils.
* Enabled -Wall and fixed all warnings.
* Various wibbles for GHC 7.0
Thanks to Thomas DuBuisson:
* Fixed a bug causing motion events to give the wrong position.
Thanks to Stephan Maka:
* Fixed a space leak in simulate mode when the window was hidden.
For 1.1.0:
* Added game mode.
* Added QuadTree and Extent structures.
* Added simple ray casting.
- module Graphics.Gloss.Data.Picture
- module Graphics.Gloss.Data.Color
- displayInWindow :: String -> (Int, Int) -> (Int, Int) -> Color -> Picture -> IO ()
- animateInWindow :: String -> (Int, Int) -> (Int, Int) -> Color -> (Float -> Picture) -> IO ()
- simulateInWindow :: forall model. String -> (Int, Int) -> (Int, Int) -> Color -> Int -> model -> (model -> Picture) -> (ViewPort -> Float -> model -> model) -> IO ()
- gameInWindow :: forall world. String -> (Int, Int) -> (Int, Int) -> Color -> Int -> world -> (world -> Picture) -> (Event -> world -> world) -> (Float -> world -> world) -> IO ()
Documentation
module Graphics.Gloss.Data.Picture
module Graphics.Gloss.Data.Color
Arguments
| :: String | Name of the window. |
| -> (Int, Int) | Initial size of the window, in pixels. |
| -> (Int, Int) | Initial position of the window, in pixels. |
| -> Color | Background color. |
| -> Picture | The picture to draw. |
| -> IO () |
Open a new window and display the given picture.
Use the following commands once the window is open:
- Quit - esc-key.
- Move Viewport - left-click drag, arrow keys.
- Rotate Viewport - right-click drag, control-left-click drag, or home/end-keys.
- Zoom Viewport - mouse wheel, or page up/down-keys.
Arguments
| :: String | Name of the window. |
| -> (Int, Int) | Initial size of the window, in pixels. |
| -> (Int, Int) | Initial position of the window, in pixels. |
| -> 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 displayInWindow.
Arguments
| :: forall model . | |
| => String | Name of the window. |
| -> (Int, Int) | Initial size of the window, in pixels. |
| -> (Int, Int) | Initial position of the window, in pixels. |
| -> 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 displayInWindow.
Arguments
| :: forall world . | |
| => String | Name of the window. |
| -> (Int, Int) | Initial size of the window, in pixels. |
| -> (Int, Int) | Initial position of the window, in pixels. |
| -> 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 () |
Run a game in a window.