【发布时间】:2021-06-25 03:45:57
【问题描述】:
您好,我正在使用 Haskell gloss,创建二叉树的图片并模拟值的插入。
我能够创建一个draw 函数来创建树的图片,它工作正常。
问题在于创建模拟。在树上的每个值插入之后,我有一个包含所有树的列表,并希望update-函数在过去的某个时间在列表的i 位置选择树,并继续切换每个树生成的图片位置i 在列表中。
有没有办法做到这一点?
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
【问题讨论】: