module Exercise_13 where import Transform import Codec.Picture import Data.Word import Data.Number.Erf animate :: [(String, Transform -> Transform)] -> String -> [String] animate = undefined paint :: String -> String paint = undefined {-WETT-} -- Add any code that generates images or videos between these tags -- Please also include instructions on how to invoke your code -- If you need libraries that are not available on the testserver, send your submission to fpv@in.tum.de -- dependencies: -- cabal install JuicyPixels -- cabal install erf {- HOW TO INVOKE? - the most simple way is just run "draw " so for example: draw "winning_pic.png" -} {- This minimalistic work explores the delicate balance of programming paradigms - the light is functional programming, the darkness is object oriented. - This artwork suggests that even in the most pure functional languages, - there is a tiny bit of object orientation, and even in the most - heavy and over complicated object oriented languages, there is a - little bit of functional programming. -} distance (x1, y1) (x2, y2) = sqrt $ fromIntegral $ (x1-x2)^2 + (y1-y2)^2 image width height = generateImage yinYang width height where yinCenter = (width*3 `div` 4, height `div` 4) yangCenter = (width `div` 4, height*3 `div` 4) probit pi = (fromIntegral $ (height `div` 4)) * ((sqrt 2) * (inverf (2*p-1)) + 2) -- based on definition from wikipedia, shifted and scaled where p = ((fromIntegral pi) / (fromIntegral width)) :: Float yinYang x y | distance (x,y) yinCenter < 50 = 0 :: Word8 | distance (x,y) yangCenter < 50 = -1 :: Word8 | (fromIntegral y) < probit x = -1 | otherwise = 0 drawDims path width height = writePng path $ image width height -- call: draw "winning_pic.png" draw path = drawDims path 700 700 {-TTEW-}