packages feed

FiniteCategories-0.1.0.0: test/ExampleRandomDiagram/ExampleRandomTriangle.hs

{-| Module  : FiniteCategories
Description : Examples of random triangle diagrams.
Copyright   : Guillaume Sabbagh 2021
License     : GPL-3
Maintainer  : guillaumesabbagh@protonmail.com
Stability   : experimental
Portability : portable

This example shows how to use `mkRandomDiagram`.
-}

module ExampleRandomDiagram.ExampleRandomTriangle
(
    main
)
where
    import CompositionGraph.CompositionGraph
    import RandomCompositionGraph.RandomCompositionGraph
    import RandomDiagram.RandomDiagram
    import System.Random
    import ExportGraphViz.ExportGraphViz
    import UsualCategories.Three
    
    generateRDiags 0 gen diags = (diags,gen)
    generateRDiags n gen diags = ((diag:end), finalGen)
        where
            (newCG,newGen) = (defaultMkRandomCompositionGraph gen)
            (diag,newGen2) = (mkRandomDiagram Three newCG newGen)
            (end,finalGen) = generateRDiags (n-1) newGen2 diags

    exportDiags [] = putStrLn "End of ExampleRandomTriangle"
    exportDiags (diag:diags) = do 
        putStrLn (show (length diags)++" random triangles remaining...")
        diagToPdf diag ("OutputGraphViz/Examples/RandomDiagram/RandomTriangles/funct"++show (length diags))
        diagToPdf2 diag ("OutputGraphViz/Examples/RandomDiagram/RandomTriangles/diag"++show (length diags))
        exportDiags diags

    -- | Exports 5 random composition graphs as pdf.
    main = do
        putStrLn "Start of ExampleRandomTriangle"
        exportDiags diags
        where
            (diags, g) = generateRDiags 5 (mkStdGen 745678765434567) []