haskell - 动画 Haskell 图
问题描述
我正在尝试用Haskell Diagram创建一个动画。我正在为此使用Reanimate 。我试过这段代码:
{-# LANGUAGE OverloadedStrings #-}
module Reanimate.Diagrams
( renderDiagram
) where
import Data.Text.Lazy (toStrict)
import Diagrams.Backend.SVG (SVG (SVG), Options (SVGOptions))
import Diagrams.Core.Types (Diagram)
import Diagrams.Core.Compile (renderDia)
import Diagrams.Size (absolute)
import Graphics.Svg.Core (renderText)
import Graphics.SvgTree (Tree, parseSvgFile)
import Reanimate.Svg.Unuse (unbox)
import Data.Maybe (maybe)
renderDiagram :: Diagram SVG -> Tree
renderDiagram d =
let opts = SVGOptions absolute Nothing "" [] False
e = renderDia SVG opts d
t = toStrict $ renderText e
err = error "Malformed SVG"
in maybe err unbox (parseSvgFile "" t)
和:
module Main where
import Diagrams.Core.Types (Diagram)
import Diagrams.Backend.SVG (B)
import Diagrams.TwoD.Ellipse (circle)
import Reanimate (addStatic, mkBackground, reanimate, staticFrame)
import Reanimate.Diagrams (renderDiagram)
main :: IO ()
main = reanimate $ addStatic (mkBackground "cyan")
$ staticFrame 1 $ renderDiagram dia
dia :: Diagram B
dia = circle 1 # lw 0.1 <> square 1 # lw 0.1 # (moveTo $ p2 (1, 1))
我明白了:
但是,如果我直接生成图表(没有 Reanimate):
main :: IO ()
main = mainWith $ bg white $ dia
我明白了:
还是线宽的问题……图好像也是垂直翻转的。谢谢
编辑:添加箭头也会带来问题。
dia :: Diagram B
dia = (circle 1 # lw 0.01 # named "circle"
<> square 1 # lw 0.01 # (moveTo $ p2 (1, 1)) # named "square")
# connect "circle" "square"
解决方案
推荐阅读
- python - “如果”函数从文本文件导入后无法识别变量的值
- javascript - Axios 发布和上传图像在 IOS/IPhone (HTTP 400) 上的 Safari 不起作用
- r - 如何在蒙特卡洛模拟中添加均值和标准差线?
- protractor - Protractor 5.4.2 和 Webdriver 12.1.6 以及 chromedrivers 不支持 chrome 76
- amazon-web-services - 嵌套数组(属性)的分页
- javascript - 使用 GET 提交一些数据,一些使用 POST 提交到同一页面
- powershell - 使用 Authenticationn/Access Token 访问 TeamCity 会出现错误 401 Unauthorized
- intellij-idea - Intellij Idea 中“服务器问题”检查严重性的含义
- typescript - 如何在 TypeScript 中将字符串细化为“字符串枚举”?
- c# - 通过 api 控制器向用户发送主动消息