有没有办法将两组图片合并为一组?
Is there a way to merge two sets of pictures into one?
我正在尝试用一组单元格显示线条网格,这些单元格填充所述线条中的方块。
我已经尝试过像简单列表一样连接它们。
这是网格线。它自己正确显示。
grid = translate (fromIntegral width * (-0.5))
(fromIntegral height * (-0.5))
(pictures (concat [
[line [(i * unitWidth, 0.0)
,(i * unitWidth, fromIntegral height)]
,line [(0.0, i * unitHeight)
,(fromIntegral width, i * unitHeight)]
]
| i <- [1..gridDimension]]
)
)
这是在线条之间绘制的一组单位,它自己也能正确显示。
units = pictures [translate ((x*unitWidth - unitWidth/2) + (fromIntegral width*(-0.5)))
((y*unitHeight - unitHeight/2) + (fromIntegral height*(-0.5)))
unit
| x <- [1..gridDimension], y <- [1..gridDimension]]
我的主要方法:
main = display window backgroundColor units
我可以在这个地方用单位换网格,效果很好。
我也试过这个:
main = display window backgroundColor (units++grid)
它引发了以下错误:
40: error:
• Couldn't match expected type ‘[a0]’ with actual type ‘Picture’
• In the first argument of ‘(++)’, namely ‘grid’
In the third argument of ‘display’, namely ‘(grid ++ units)’
In the expression: display window backgroundColor (grid ++ units)
|
10 | main = display window backgroundColor (grid++units)
| ^^^^
/home/georg/Desktop/THM/6_semester/funktionale_programmierung/my/app/Main.hs:10:40: error:
• Couldn't match expected type ‘Picture’ with actual type ‘[a0]’
• In the third argument of ‘display’, namely ‘(grid ++ units)’
In the expression: display window backgroundColor (grid ++ units)
In an equation for ‘main’:
main = display window backgroundColor (grid ++ units)
|
10 | main = display window backgroundColor (grid++units)
| ^^^^^^^^^^^
/home/georg/Desktop/THM/6_semester/funktionale_programmierung/my/app/Main.hs:10:46: error:
• Couldn't match expected type ‘[a0]’ with actual type ‘Picture’
• In the second argument of ‘(++)’, namely ‘units’
In the third argument of ‘display’, namely ‘(grid ++ units)’
In the expression: display window backgroundColor (grid ++ units)
|
10 | main = display window backgroundColor (grid++units)
| ^^^^^
(++) :: [a] -> [a] -> [a]
函数附加了两个列表,一个Picture
不是列表,所以你不能使用那个函数。
但是您可以在此处使用 (<>) :: Semigroup m => m -> m -> m
,因为 Picture
是 Semigroup
:
的一个实例
因此我们可以这样写:
main = display window backgroundColor (<b>units <> grid</b>)
或者您可以再次使用 pictures :: [Picture] -> Picture
,并包括您的 units
和 grid
,例如:
main = display window backgroundColor (<b>pictures [units, grid]</b>)
我正在尝试用一组单元格显示线条网格,这些单元格填充所述线条中的方块。
我已经尝试过像简单列表一样连接它们。
这是网格线。它自己正确显示。
grid = translate (fromIntegral width * (-0.5))
(fromIntegral height * (-0.5))
(pictures (concat [
[line [(i * unitWidth, 0.0)
,(i * unitWidth, fromIntegral height)]
,line [(0.0, i * unitHeight)
,(fromIntegral width, i * unitHeight)]
]
| i <- [1..gridDimension]]
)
)
这是在线条之间绘制的一组单位,它自己也能正确显示。
units = pictures [translate ((x*unitWidth - unitWidth/2) + (fromIntegral width*(-0.5)))
((y*unitHeight - unitHeight/2) + (fromIntegral height*(-0.5)))
unit
| x <- [1..gridDimension], y <- [1..gridDimension]]
我的主要方法:
main = display window backgroundColor units
我可以在这个地方用单位换网格,效果很好。 我也试过这个:
main = display window backgroundColor (units++grid)
它引发了以下错误:
40: error:
• Couldn't match expected type ‘[a0]’ with actual type ‘Picture’
• In the first argument of ‘(++)’, namely ‘grid’
In the third argument of ‘display’, namely ‘(grid ++ units)’
In the expression: display window backgroundColor (grid ++ units)
|
10 | main = display window backgroundColor (grid++units)
| ^^^^
/home/georg/Desktop/THM/6_semester/funktionale_programmierung/my/app/Main.hs:10:40: error:
• Couldn't match expected type ‘Picture’ with actual type ‘[a0]’
• In the third argument of ‘display’, namely ‘(grid ++ units)’
In the expression: display window backgroundColor (grid ++ units)
In an equation for ‘main’:
main = display window backgroundColor (grid ++ units)
|
10 | main = display window backgroundColor (grid++units)
| ^^^^^^^^^^^
/home/georg/Desktop/THM/6_semester/funktionale_programmierung/my/app/Main.hs:10:46: error:
• Couldn't match expected type ‘[a0]’ with actual type ‘Picture’
• In the second argument of ‘(++)’, namely ‘units’
In the third argument of ‘display’, namely ‘(grid ++ units)’
In the expression: display window backgroundColor (grid ++ units)
|
10 | main = display window backgroundColor (grid++units)
| ^^^^^
(++) :: [a] -> [a] -> [a]
函数附加了两个列表,一个Picture
不是列表,所以你不能使用那个函数。
但是您可以在此处使用 (<>) :: Semigroup m => m -> m -> m
,因为 Picture
是 Semigroup
:
因此我们可以这样写:
main = display window backgroundColor (<b>units <> grid</b>)
或者您可以再次使用 pictures :: [Picture] -> Picture
,并包括您的 units
和 grid
,例如:
main = display window backgroundColor (<b>pictures [units, grid]</b>)