hs-logo (empty) → 0.1
raw patch · 5 files changed
+155/−0 lines, 5 filesdep +basedep +cmdargsdep +containerssetup-changed
Dependencies added: base, cmdargs, containers, diagrams-cairo, diagrams-core, diagrams-lib, mtl, parsec, parsec-numbers, random
Files
- LICENSE +30/−0
- Logo.hs +65/−0
- README.md +23/−0
- Setup.hs +2/−0
- hs-logo.cabal +35/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2011, various (see headers of individual source files)++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 Various 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.
+ Logo.hs view
@@ -0,0 +1,65 @@+{-# LANGUAGE DeriveDataTypeable #-}+module Main where++import Diagrams.Prelude+import Diagrams.Backend.Cairo.CmdLine+import Diagrams.TwoD.Path.Turtle++import Logo.Types+import Logo.TokenParser+import Logo.Builtins+import Logo.Evaluator++import System.Environment (getProgName, withArgs)++import System.Console.CmdArgs.Implicit++import qualified Data.Map as M+++data LogoOpts = LogoOpts+ { output :: String -- output file to write to+ , src :: Maybe String -- source file to read from+ } deriving (Show, Data, Typeable)++logoOpts :: String -> LogoOpts+logoOpts prog = LogoOpts+ { output = "logo.png"+ &= typFile+ &= help "Output image file (default=logo.png)"+ , src = def+ &= typFile+ &= args+ }+ &= summary "hs-logo Logo Interpreter v0.1"+ &= program prog++main :: IO ()+main = do+ prog <- getProgName+ opts <- cmdArgs (logoOpts prog)+ case src opts of+ Nothing -> error "Source file not specified"+ Just s -> renderLogo s (output opts)++renderLogo :: String -> String -> IO ()+renderLogo s o = do+ tokens <- readSource s+ diag <- stroke <$> runTurtleT (evaluateSourceTokens tokens)+ withArgs ["-o", o, "-w", "400", "-h", "400"] $ defaultMain (diag # lw (0.005 * width diag) # centerXY # pad 1.1)++readSource :: FilePath -> IO [LogoToken]+readSource f = do+ tokens <- tokenize <$> readFile f+ case tokens of+ Left x -> error $ show x+ Right t -> return t++evaluateSourceTokens :: [LogoToken] -> TurtleIO ()+evaluateSourceTokens tokens = do+ let initialContext = LogoContext builtins M.empty M.empty+ res <- evaluateWithContext tokens initialContext+ case res of+ Left err -> error $ show err+ Right _ -> return ()+
+ README.md view
@@ -0,0 +1,23 @@+Logo interpreter written in Haskell, specialized for turtle graphics. Still very+much a WIP. Lot of the language still needs to be implemented, but it is fairly+functional already.++More info at http://deepakjois.github.com/hs-logo++## Quickstart++For those who like to live dangerously, here is a quickstart:++* Install [diagrams](http://projects.haskell.org/diagrams/) and related dependencies. Here is a [gist of instructions](https://gist.github.com/1683922) if you are on OS X.+* Clone the Git repo for hs-logo+* Run `cabal configure && cabal build`++You can now try out some logo programs in the [examples](https://github.com/deepakjois/hs-logo/tree/master/site/examples) folder++ % dist/build/hs-logo/hs-logo site/examples/sources/snowflake.logo -o ~/tmp/snowflake.png++++ % dist/build/hs-logo/hs-logo site/examples/sources/design1.logo -o ~/tmp/design1.png++
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hs-logo.cabal view
@@ -0,0 +1,35 @@+Name: hs-logo+Version: 0.1+Synopsis: Logo turtle graphics interpreter+Description: Interpreter for the Logo programming language,+ specialised for turtle graphics.+Homepage: http://deepakjois.github.com/hs-logo+License: BSD3+License-File: LICENSE+Author: Deepak Jois+Maintainer: deepak.jois@gmail.com+Build-Type: Simple+Synopsis: Logo interpreter written in Haskell++Category: Parser+Cabal-Version: >=1.6+Data-Files: README.md++Source-Repository head+ type: git+ location: https://github.com/deepakjois/hs-logo++Executable hs-logo+ Ghc-Options: -Wall -fno-warn-unused-do-bind+ Hs-Source-Dirs: .+ Main-Is: Logo.hs+ Build-Depends: base >= 4.2 && < 4.6,+ containers >= 0.3 && < 0.5,+ mtl >= 1 && < 3.0,+ parsec >= 3.0 && < 3.2,+ cmdargs >= 0.6 && <= 0.9,+ random >= 1.0,+ parsec-numbers,+ diagrams-core >= 0.5 && < 0.6,+ diagrams-lib >= 0.5 && < 0.6,+ diagrams-cairo >= 0.5 && < 0.6