ghci-diagrams (empty) → 0.1
raw patch · 5 files changed
+174/−0 lines, 5 filesdep +basedep +cairodep +coloursetup-changed
Dependencies added: base, cairo, colour, diagrams, gtk
Files
- Diagrams.hs +62/−0
- DrawDiagrams.hs +48/−0
- LICENSE +31/−0
- Setup.lhs +3/−0
- ghci-diagrams.cabal +30/−0
+ Diagrams.hs view
@@ -0,0 +1,62 @@+{-# LANGUAGE NoMonomorphismRestriction #-}++module Diagrams+ ( Diagram+ , circle, rect, (>-<)+ , move, rotate, scale+ , (<|>), union+ , polygon, polyline+ , strokeWidth+ , fill, stroke, Color, rgb+ , module Data.Colour.Names+ , Point, (.+.), (.-.), (.*.), (*.)+ , scaleY+ ) where++import Graphics.Rendering.Diagrams hiding (circle, rotate, scale)+import qualified Graphics.Rendering.Diagrams as D +import Graphics.Rendering.Diagrams.Types++import Data.Colour.SRGB.Linear (rgb)+import Data.Colour.RGBSpace+import Data.Colour.Names++--------------------------------++infix 4 >-<++infixl 3 `move`, `rotate`, `scale`, `fill`, `stroke`, `strokeWidth`++infixl 2 <|>++-----------------++d `move` (x,y) = translate x y d+x `rotate` d = D.rotate (d/360) x+scale = flip D.scale++fill = flip fillColor+stroke = flip lineColor+strokeWidth = flip lineWidth++(<|>) = (##)++circle d | d > 0 = D.circle d+circle _ = nil++a >-< b = straight (pathFromVertices [a,b]) `move` 0.5 *. (a .+. b)++polygon :: [Point] -> Diagram+polygon xs = straight $ closed $ pathFromVertices xs++polyline :: [Point] -> Diagram+polyline xs = straight $ pathFromVertices xs++--rgb :: Int -> Int -> Int -> Color+--rgb r g b = rgbUsingSpace space r g b+{-+space :: RGBSpace Double+space = linearRGBSpace $ mkRGBGamut (curryRGB id x x x) x + where+ x = Data.Colour.CIE.Illuminant.e+-}
+ DrawDiagrams.hs view
@@ -0,0 +1,48 @@+{-# LANGUAGE NoMonomorphismRestriction #-}++module DrawDiagrams+ ( module Diagrams+ , draw+ , drawOn+ ) where++import Diagrams++import Graphics.UI.Gtk+import Graphics.Rendering.Cairo ( Render, liftIO )+import Graphics.Rendering.Diagrams.Engine ( render )+import Graphics.Rendering.Diagrams.Types ( runDiaRenderM, defaultDiaRenderEnv )+++test1 = draw $ union [circle 2 `move` (x,0) | x<-[0..10]] `fill` white++draw :: Diagram -> IO ()+draw = drawOn 640 400++drawOn :: Int -> Int -> Diagram -> IO ()+drawOn w h dia = do+ initGUI+ dialog <- dialogNew+ windowSetKeepAbove dialog True+ set dialog [ windowWindowPosition := WinPosCenter ]+ dialogAddButton dialog stockClose ResponseClose+ contain <- dialogGetUpper dialog+ canvas <- drawingAreaNew+ canvas `onSizeRequest` return (Requisition w h)+ boxPackStartDefaults contain canvas+ canvas `on` exposeEvent $ tryEvent $ liftIO $ do+ win <- widgetGetDrawWindow canvas+ renderWithDrawable win $+ flip runDiaRenderM defaultDiaRenderEnv $ render $+ (rect (fromIntegral w) (fromIntegral h) `fill` white `strokeWidth` 0 + <|> scaleY (-1) dia `scale` 20)+ `move` (fromIntegral w/2, fromIntegral h/2)++ widgetShow canvas+ dialogRun dialog+ widgetDestroy dialog+ flush++++
+ LICENSE view
@@ -0,0 +1,31 @@+Copyright Péter Diviánszky 2011++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Péter Diviánszky nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ ghci-diagrams.cabal view
@@ -0,0 +1,30 @@+name: ghci-diagrams+version: 0.1+category: Graphics+synopsis: Display simple diagrams from ghci+description:+ This library provides a simple 2D graphics environment which is used+ in our beginner's Haskell course at ELTE University in Budapest.+ .+ Example> draw $ circle 3+stability: alpha+license: BSD3+license-file: LICENSE+author: Péter Diviánszky+maintainer: divip@aszt.inf.elte.hu+cabal-version: >=1.2+build-type: Simple++library+-- ghc-options: -Wall+ exposed-modules:+ DrawDiagrams+ other-modules:+ Diagrams+ build-depends:+ base >= 4.0 && < 4.4,+ diagrams >= 0.2 && < 0.3,+ cairo,+ gtk,+ colour+