]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - src/RMCA/GUI/Shapes.hs
Better note selection.
[tmp/julm/arpeggigon.git] / src / RMCA / GUI / Shapes.hs
1 module RMCA.GUI.Shapes where
2
3 import Graphics.Rendering.Cairo
4
5 -- Draws a regular hexagon
6 --
7 -- Colors are given in RGB format, coefficient goes from 0 to 1
8 hexagon :: (Double, Double, Double) -- Background color
9 -> (Double, Double, Double) -- Frame color
10 -> (Double, Double) -- Center
11 -> Double -- Width
12 -> Render ()
13 hexagon (backR, backG, backB) (frameR, frameG, frameB) (x,y) w = do
14 setSourceRGB frameR frameG frameB
15 setLineWidth (0.01 * w)
16
17 let a = 0.5*w
18 b = 0.87*w
19
20 moveTo (x+a) (y-b)
21 lineTo (x-a) (y-b)
22 lineTo (x-w) y
23 lineTo (x-a) (y+b)
24 lineTo (x+a) (y+b)
25 lineTo (x+w) y
26 closePath
27 strokePreserve
28 setSourceRGB backR backG backB
29 fill
30 return ()
31
32 pnw = 200
33 pnh = 200
34
35 main = withImageSurface FormatARGB32 pnw pnh
36 (\srf -> do renderWith srf (hexagon (1,1,1) (0,0,0)
37 (fromIntegral pnw/2,fromIntegral pnh/ 2) (fromIntegral (pnw `quot` 2)))
38 surfaceWriteToPNG srf "myDraw.png")