Create a gist now

Instantly share code, notes, and snippets.

Gtk2Hs Cairo + Pango Hello World
-- Reqs: apt-get install libghc6-time-dev libghc6-cairo-dev libghc6-gtk-dev
-- Compile by doing
-- ghc --make hello.hs -o hello
import Graphics.UI.Gtk hiding (fill)
import Graphics.Rendering.Cairo
import Data.Time.Clock.POSIX
import Time
frac = snd . properFraction
modf a b = frac (a / b) * b
normalizeAngle a | a < 0 = 2*pi + (a `modf` (2*pi))
normalizeAngle a = a `modf` (2*pi)
floorf = fromInteger . fst . properFraction
quantize d f = d * floorf (f / d)
angularDistance a b =
f (na - nb)
where na = normalizeAngle a
nb = normalizeAngle b
f a | a > pi = a - 2*pi
f a | a < -pi = a + 2*pi
f a = a
exposeHandler widget e = do
drawWin <- widgetGetDrawWindow widget
(wi,hi) <- widgetGetSize widget
let (w,h) = (realToFrac wi, realToFrac hi)
t <- getPOSIXTime
let n = 20
let rot = normalizeAngle (realToFrac t)
renderWithDrawable drawWin $ do
save
translate (w * 0.55) (h * 0.40)
arc 0 0 (w * 0.2) 0 (pi*2)
setLineWidth 20
stroke
renderWithSimilarSurface ContentAlpha 200 40 $ \tmp -> do
renderWith tmp $ do
scale 1.5 1.5
createLayout "God damn it" >>= showLayout
withPatternForSurface tmp $ \pat -> do
mapM_ (\i -> do
let trot = normalizeAngle $ rot + (i * (pi * 2) / n)
let sc = (1.0 + 0.5*(sin trot)) / 1.5
let tl = ((w*0.2+10) / sqrt 2)
save
rotate trot
translate tl tl
scale sc sc
translate 10 10
setSource pat
rectangle 0 0 200 40
fill
restore ) [1..n]
restore
widgetQueueDraw widget
return True
main = do
initGUI
window <- windowNew
da <- drawingAreaNew
set window [ containerChild := da ]
windowSetDefaultSize window 410 450
onExpose da (exposeHandler da)
onDestroy window mainQuit
widgetShowAll window
mainGUI
@jhegedus42

what ghc does this run with?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment