Skip to content

Instantly share code, notes, and snippets.

@adicirstei
Last active July 5, 2018 11:25
Show Gist options
  • Save adicirstei/ebca2581db79dbeac6dfdef00bdb9ca8 to your computer and use it in GitHub Desktop.
Save adicirstei/ebca2581db79dbeac6dfdef00bdb9ca8 to your computer and use it in GitHub Desktop.
Gloss with JuicyPixels trying to make a match
name: tutu
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/githubuser/tutu#readme
license: BSD3
license-file: LICENSE
author: Adrian Cirstei
maintainer:
copyright: 2018 Adrian Cirstei
category: Web
build-type: Simple
cabal-version: >=1.10
extra-source-files: README.md
executable tutu
hs-source-dirs: src
main-is: Main.hs
default-language: Haskell2010
other-modules: Codec.Picture.Canvas
build-depends: base >= 4.7 && < 5
, gloss
, gloss-juicy
, JuicyPixels
, primitive
module Main where
import Codec.Picture
import Control.Monad.ST
import Control.Monad.Primitive
import qualified Codec.Picture.Types as M
import Graphics.Gloss
import Graphics.Gloss.Data.ViewPort(ViewPort)
import Graphics.Gloss.Juicy (fromImageRGBA8)
type Model m = m (M.MutableImage (PrimState m) PixelRGBA8)
size = (512,512)
blankMI :: Model (ST s)
blankMI = M.createMutableImage 512 512 $ PixelRGBA8 0xff 0xff 0xff 0xff
render :: Model (ST s) -> Picture
render m =
let
img = runST (m >>= M.freezeImage)
in
fromImageRGBA8 img
update :: ViewPort -> Float -> Model (ST s) -> Model (ST s)
update vp f m = do
i <- m
writePixel i (round f * 12) (round f * 10) (PixelRGBA8 0 0 0 0xff)
pure i
main :: IO ()
main = simulate (InWindow "Juicy" size (0,0) ) white 10 blankMI render update
resolver: lts-11.16
packages:
- .
extra-deps:
- gloss-juicy-0.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment