【问题标题】:Purescript: drawing an image on a canvasPurescript:在画布上绘制图像
【发布时间】:2018-12-09 15:54:39
【问题描述】:

我想使用 Purescript 将图像绘制到画布上。当我在 Javascript 中执行此操作时,它看起来类似于以下内容:

window.onload = function() {
    var c=document.getElementById("myCanvas");
    var ctx=c.getContext("2d");
    var img=document.getElementById("scream");  // THIS LINE IN PURESCRIPT???
    ctx.drawImage(img,10,10);
};

我正在使用 purs 0.12。我已经安装了 Graphics.Canvas,我可以用它来绘制矩形和椭圆等。但我无法弄清楚drawImage 的API。我也无法弄清楚与 getElementbyId() 等效的 Purescript 驻留在哪个库中。

【问题讨论】:

  • 似乎drawImage 可用in the same library。你有一些具体的问题吗?
  • 它需要一个CanvasImageSource——所以问题是我从哪里得到它?
  • 好像可以通过tryLoadImage获得
  • 我无法理解 tryLoadImage 的论点。事实上,这应该如何产生 CanvasImageSource 。它需要一个带有Maybe CanvasImageSource 作为参数的函数... huh????
  • 编辑:我想我可以编写这样一个函数,它将对 drawImage 的调用与上下文和坐标结合为闭包,并且将 Maybe CanvasImageSource 作为参数(我必须处理Nothing 的情况),然后每次我想画一些东西时将它传递给tryLoadImage,但这似乎不是我想要的

标签: purescript


【解决方案1】:

使用Pursuit 搜索getElementById 等定义。

tryLoadImage 将回调作为参数。回调是接收CanvasImageSource 的内容。您可能希望使用Aff 或至少ContT 来提供帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 2013-07-20
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多