Hello i am using Haskell gloss, to create a picture of a binary tree and simulate the insertion of the values.
I was able to create a draw
function to create the picture of the tree and it works fine.
The problem is on creating a simulation. I have a list containing all trees after each value insertion on the tree and wanted the update
-function to pick the tree in the position i
of the list in some time past and keep switching the picture generate by each tree in position i
in the list.
Is there a way to do that?
drawTree::(Show a)=>BTree a->Picture
updateTree :: ViewPort->Float->[BTree a]->[BTree a]
updateTree _ dt list=[list!!toInt dt]
main::IO()
main = do
--receives all values to be inserted
values <- getLine
let list = read values :: [Int]
--temp is a list that stores all the tree generated in each insertion
let temp =insertValues list Leaf
--stores the tree contained in the last inserction
let tree = last temp
--stores the tree after the first insertion
let fir=first temp
simulate window background fps [fir] drawTree updateTree