-
Notifications
You must be signed in to change notification settings - Fork 0
/
Diagram.hs
35 lines (29 loc) · 1 KB
/
Diagram.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Monad
import Data.List
import Diagrams.Backend.SVG.CmdLine
import Diagrams.Prelude hiding (Point)
import Diagrams.TwoD
import System.Random
type Point = P2 Double
generatePoint :: IO Point
generatePoint = do
x <- randomIO :: IO Double
y <- randomIO :: IO Double
return (p2 (x, y))
cartesianProduct :: [a] -> [(a, a)]
cartesianProduct list =
case list of
[] -> []
head : rest -> map (\ a -> (head, a)) rest ++ cartesianProduct rest
createLines :: (Point, Point) -> Diagram B
createLines (a, b) =
fromVertices [a, b]
main :: IO ()
main = do
points <- replicateM 50 generatePoint
let lines = (centerXY ((mconcat (map createLines (cartesianProduct points))) # lw 0.1))
mainWith (lines `atop` centerXY (square 1 # lw none # fc white # scale 1.25))
putStrLn "use double quotes"