Skip to content

Instantly share code, notes, and snippets.

@dustinlacewell
Created September 6, 2021 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinlacewell/2fe2bd282a794a97677cf723b4499989 to your computer and use it in GitHub Desktop.
Save dustinlacewell/2fe2bd282a794a97677cf723b4499989 to your computer and use it in GitHub Desktop.
-- Balloons have x,y coordinates, a radius, and a color
data Balloon = Balloon {
x :: Float,
y :: Float,
r :: Float,
c :: Color
} deriving (Show)
main :: IO ()
main =
let
rng = mkStdGen 0
world = Circle 60
-- function to return a random color
randColor = let colors = [red, green, blue, yellow, magenta, cyan]
in colors !! fst (randomR (0, 5) rng)
-- list comprehension of 50 random x, y tuples
circles :: [Balloon]
circles = [Balloon { x=x, y=y, r=r, c=c } |
x <- take 50 (randomRs (- 200, 200) rng),
y <- take 50 (randomRs (- 200, 200) rng),
r <- take 50 (randomRs (5, 15) rng),
c <- replicate 50 randColor]
in playIO
(InWindow "Gloss" (200, 200) (10, 10))
white
60
circles
draw
handleEvent
update
drawCircle (Balloon x y r c ) =
translate x y $ color red $ circleSolid r
draw :: Monad m0 => [Balloon] -> m0 Picture
draw = return . pictures . map drawCircle
--- handle escape and quit
handleEvent (G.EventKey (G.SpecialKey G.KeyEsc) G.Down _ _) _ = exitSuccess
handleEvent _ c = return c
update t = return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment