Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
Code from a novice Haskell user
<pre class='prettyprint' language='haskell'>module Main where import Text.XML.HaXml import Text.XML.HaXml.Parse import Text.XML.HaXml.Posn import Text.XML.HaXml.Util import System.Environment (getArgs) import System.IO (IOMode(..), hClose, hGetContents, hPutStr, openFile) import Data.List main = do args <- getArgs case args of [collada, ma] -> process collada ma _ -> argError process :: String -> String -> IO () process collada ma = do colladah <- openFile collada ReadMode mah <- openFile ma ReadMode colladaStr <- hGetContents colladah maStr <- hGetContents mah -- Parse the COLLADA file and get the FOV animation data. let (Document _ _ root _) = xmlParse collada colladaStr let rootElem = CElem root noPos let animations = tag "COLLADA" /> tag "library_animations" /> tag "animation" $ rootElem let fovAnimation = (filter isFovAnimation animations) !! 0 let sources = keep /> tag "source" /> tag "float_array" $ fovAnimation let times = map ((*24.0) . (read :: String -> Float)) $ words $ tagTextContent (sources !! 0) let values = map (yfovToFocalLength . (read :: String -> Float)) $ words $ tagTextContent (sources !! 1) let (CElem (Elem _ attributes _) _) = sources !! 0 let (_, AttValue (Left countVal:_)) = attributes !! 0 let count = read countVal :: Int --putStrLn $ show count --putStrLn $ show values -- Parse the ma file and get the name of the camera node. let createLine = (filter isCustomCameraCreate $ lines maStr) !! 0 let !cameraName = takeWhile isNotQuote $ drop 1 $ dropWhile isNotQuote createLine --putStrLn cameraName hClose mah -- Append the ma file with the FOV animation. mah2 <- openFile ma AppendMode let createNode = "createNode animCurveTU -n \"" ++ cameraName ++ "_focalLength\";\n\tsetAttr \".tan\" 10;\n\tsetAttr \".wgt\" no;\n\tsetAttr -s " ++ (show count) ++ " \".ktv[0:" ++ (show (count - 1)) ++ "]\" " hPutStr mah2 createNode hPutStr mah2 (concat $ map pairToString $ zip times values) hPutStr mah2 ";\n" let connectAttr = "connectAttr \"" ++ cameraName ++ "_focalLength.o\" \"" ++ cameraName ++ ".fl\";" hPutStr mah2 connectAttr hClose colladah hClose mah2 isFovAnimation animation = let (CElem (Elem _ attributes _) _) = animation in let (_, AttValue (Left idStr:_)) = attributes !! 0 in isSuffixOf "FOV" idStr yfovToFocalLength yfov = yAperture / (tan (yfov * 0.5 * pi / 180.0) * 2.0) where yAperture = 25.4 * 0.581 isCustomCameraCreate line = "createNode camera -n" `isPrefixOf` line isNotQuote char = char /= '"' pairToString pair = " " ++ (show . fst $ pair) ++ " " ++ (show . snd $ pair) argError = putStrLn "Usage: add_fov_to_ma.exe COLLADA_filename ma_filename\n"</pre> <a href="http://www.refactormycode.com/codes/1167-code-from-a-novice-haskell-user" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>