💾 Archived View for heavysquare.com › visuals › haskell-diagram.txt captured on 2021-12-03 at 14:04:38.
-=-=-=-=-=-=-
Read about this library [here](http://projects.haskell.org/diagrams/documentation.html). ![diagrams1](/im/diagrams1.jpg "w/ args -w 500 -h 500") Source code: import Diagrams.Prelude import Diagrams.Backend.Cairo.CmdLine prime y = (==) 0 . length $ filter is_divisor candidates where candidates = [2 .. floor $ sqrt $ fromIntegral y] is_divisor x = y `mod` x == 0 disc y = (fc color . lw 0 $ circle 1) `atop` backg where backg = fc white . lw 0 $ square 2.2 color = if 1 < y && prime y then red else black row x i = foldl (|||) mempty $ map disc [i * x .. i * x + x - 1] tile x = foldl (===) mempty $ map (row x) [0 .. x - 1] backg x = fc white . lw 0 $ square $ 2.4 * fromIntegral x frame x = tile x # centerXY `atop` backg x main = defaultMain $ frame 37