oscpacking-0.3.0.0: Graphics/OscPacking/Paint.hs
{-|
Module : Graphics.OscPacking.Paint
Description : Displaying packings on the screen
Copyright : (c) Christopher Howard, 2016
License : GPL-3
Maintainer : ch.howard@zoho.com
-}
module Graphics.OscPacking.Paint where
import Prelude (Int, IO, take, (/), (*))
import Graphics.OscPacking.Packing
import Graphics.OscPacking.Interpret
import Graphics.Gloss (Picture, display, Display (InWindow, FullScreen), Color, translate)
-- |Generating a packing from Packing parameters and convert into a Picture
buildPicture :: Interpretation -- ^ graphical interpretation method
-> Packing -- ^ initialization parameters
-> Int -- ^ maximum number of circles to build
-> Picture
buildPicture intp pkg maxcircles =
translate ((-1) * boxWidth pkg / 2) ((-1) * boxHeight pkg / 2)
(intp (take maxcircles (pack pkg)))
-- |Display a picture in a window on-screen
displayWindow :: (Int, Int) -- ^ width and height of window
-> Color -- ^ background color
-> Picture -- ^ the Picture to display
-> IO ()
displayWindow (width, height) bg pic =
display (InWindow "KC" (width, height) (0, 0)) bg pic
-- |Display a picture in full-screen mode
displayFullscreen :: (Int, Int) -- ^ width and height of actual display area
-> Color -- ^ background color
-> Picture -- ^ the Picture to display
-> IO ()
displayFullscreen (width, height) bg pic =
display (FullScreen (width, height)) bg pic
-- Removed because, at late processing stages, does not all for
-- processing keyboard input often enough:
-- growWindow :: (Int, Int) -> Color -> Interpretation -> Int -> Packing -> IO ()
-- growWindow (width, height) bg intp stepsPerSec pkg =
-- simulate (InWindow "KC" (width, height) (0, 0)) bg stepsPerSec
-- ([head circles], tail circles) toPic step
-- where circles = pack pkg
-- toPic (usedCircles, _) = translate ((-1) * boxWidth pkg / 2)
-- ((-1) * boxHeight pkg / 2)
-- (intp usedCircles)
-- step _ _ (usedCircles, remCircles) = (head remCircles : usedCircles, tail remCircles)