Paper.js,光标和画布之间的差距(Paper.js, gap between cursor and canvas)
我正在尝试使用Paper.js构建一个简单的绘图应用程序。 我可以使用鼠标进行绘制,但在光标和画布上绘制的线之间存在间隙。
我已经意识到网页顶部的导航菜单正在向下推动光标(100px)我假设鼠标坐标是从窗口的左上角(0-0)获取的,并且在画布上使用了相同的坐标从它自己的左上角测量这些点(请参见屏幕截图)。 我已经尝试将画布位置设置为绝对,这有助于将其置于左上角的核心,但我需要它在窗口的中心。
我怎么能解决这个问题?
谢谢!
脚本:
... var doc = $(document), win = $(window), canvas = $('#paper'), ctx = canvas[0].getContext('2d') doc.on('mousemove',function(e){ if($.now() - lastEmit > 30){ socket.emit('mousemove',{ 'x': e.pageX, 'y': e.pageY, 'drawing': drawing, 'id': id }); lastEmit = $.now(); } // Draw a line for the current user's movement, as it is // not received in the socket.on('moving') event above // (because he only broadcats (not receiving)) if(drawing){ drawLine(prev.x, prev.y, e.pageX, e.pageY); prev.x = e.pageX; prev.y = e.pageY; } }); function drawLine(fromx, fromy, tox, toy){ console.log(fromy + ' ' + toy); ctx.moveTo(fromx, fromy); ctx.lineTo(tox, toy); ctx.stroke(); }
I am trying to build a simple drawing app with Paper.js. I can draw with the mouse but I have a gap between the cursor and the line drawn on the canvas.
I have realised that the navigation menu on top of the webpage is pushing down the cursor (100px) I assume that the mouse coordinates are taken from top-left (0-0) of the window and the same coordinates are used on the canvas which measured these points from its own top-left corner (see the screenshot). I have tried setting the canvas position to absolute, which helps to get it to the top left corer, but I need it in the center of the window.
How could I fix this?
Thanks!
script:
... var doc = $(document), win = $(window), canvas = $('#paper'), ctx = canvas[0].getContext('2d') doc.on('mousemove',function(e){ if($.now() - lastEmit > 30){ socket.emit('mousemove',{ 'x': e.pageX, 'y': e.pageY, 'drawing': drawing, 'id': id }); lastEmit = $.now(); } // Draw a line for the current user's movement, as it is // not received in the socket.on('moving') event above // (because he only broadcats (not receiving)) if(drawing){ drawLine(prev.x, prev.y, e.pageX, e.pageY); prev.x = e.pageX; prev.y = e.pageY; } }); function drawLine(fromx, fromy, tox, toy){ console.log(fromy + ' ' + toy); ctx.moveTo(fromx, fromy); ctx.lineTo(tox, toy); ctx.stroke(); }
原文:https://stackoverflow.com/questions/33068419
最满意答案
像StéphaneSudre的免费套餐应用程序这样的产品可以让人很轻松地进行PKG向导式设置。 其中一个功能是执行安装前或安装后脚本 ,这可以是Python或Bash脚本。 从那里,我可以从服务器下载browser.plist文件。 服务器可以读取用户的IP地址,读取数据库中的浏览器和广告商ID信息,并在下载时将其注入browser.plist文件。 然后,它可以从数据库中删除该条目(以便数据库不会从流量中爆炸)。 然后,Web服务器还可以删除任何早于x天的记录作为故障安全,以便数据库不会从流量量中爆炸。
A product like the free Packages application from Stéphane Sudre lets one make a PKG wizard-style setup pretty easily. One of the features of it is to have a pre- or post-install script execute, and this can be a Python or Bash script. From there, I can make it download a browser.plist file from the server. The server can read the user's IP address, read the database for browser and advertiser ID information, and inject that into the browser.plist file at the point of download. It can then delete the entry from the database (so that the database doesn't explode from the volume of traffic). The web server can then also remove any records older than x number of days as a failsafe so that the database doesn't explode from the volume of traffic.
相关问答
更多-
错误地,我将/ var / www / html添加到pkg的路径中。 使用curl -o命令下载时无需提及。 只有当我们想去那个特定的位置时,我们才需要在命令行中提到这条路径。 By mistake i added /var/www/html to the path of pkg. This need not be mentioned while downloading using curl -o command. Only if we wanted to go to that particular lo ...
-
如何打包和打包pkg文件?(How to unpack and pack pkg file?)[2022-12-03]
软件包只是具有不同扩展名和指定文件层次结构的.xar存档。 不幸的是,该文件层次结构的一部分是实际可安装程序的cpio.gz存档,通常是您要编辑的。 而且还有一个Bom文件,其中包含有关该cpio存档文件的信息,以及一个包含摘要信息的PackageInfo文件。 如果你真的只需要编辑一个信息文件,这很简单: mkdir Foo cd Foo xar -xf ../Foo.pkg # edit stuff xar -cf ../Foo-new.pkg * 但如果您需要编辑可安装的文件: mkdir Foo ... -
我跑了 lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom \ | while read i; do sudo rm /usr/local/${i} done sudo rm -rf /usr/local/lib/node \ /usr/local/lib/node_modules \ /var/db/receipts/org.nodejs.* 编码为要点2697848 更新似乎收据的.bom文件名可能已更改,因此您可能需要 ...
-
终于找到了答案。 运行/System/Library/CoreServices/Installer.app 导航到卡住的安装程序,并进行安装 利润! 示例和截图可在http://osxdaily.com/2016/07/26/fix-stuck-pkg-verifying-installer-mac-os-x/上找到 Finally found an answer. run /System/Library/CoreServices/Installer.app navigate to the installe ...
-
将文件添加到构建中的文件夹中,该文件夹将复制到用户的计算机。 如果您不想在安装后保留文件,则安装后脚本可以删除它们。 我目前使用以下命令: - pkgbuild --identifier com.company.product --version 0.1 --scripts scripts/ --root ProductNameInstall/ "mypackage.pkg" 要复制的源文件位于ProductNameInstall文件夹中。 Add the files to a folder in the ...
-
您的开发者名称必须紧跟团队ID。 像 - “开发者名称(ABC123456)” Your developer name must be followed by the team ID. Like - "DEVELOPER NAME (ABC123456)"
-
生成R包的命令的源不可用。 但是,您可以下载生成的软件包,并使用OS X pkg实用程序( pkgbuild , pkgutil , productbuild )对其进行修改以包含其他您可能需要的内容。 例如,下面的脚本下载分布式软件包,将用户R库中的任何软件包添加到该软件包中,然后对其进行重新整理以便分发。 wget https://cloud.r-project.org/bin/macosx/R-3.5.0.pkg BUILD_DIR=build mkdir $BUILD_DIR # ...
-
制作Mac PKG下载文件(Make Mac PKG Download File)[2023-03-04]
像StéphaneSudre的免费套餐应用程序这样的产品可以让人很轻松地进行PKG向导式设置。 其中一个功能是执行安装前或安装后脚本 ,这可以是Python或Bash脚本。 从那里,我可以从服务器下载browser.plist文件。 服务器可以读取用户的IP地址,读取数据库中的浏览器和广告商ID信息,并在下载时将其注入browser.plist文件。 然后,它可以从数据库中删除该条目(以便数据库不会从流量中爆炸)。 然后,Web服务器还可以删除任何早于x天的记录作为故障安全,以便数据库不会从流量量中爆炸。 ... -
也许他们没有安装程序的证书:) Maybe they don't have a certificate for the installer :)
-
无论是否具有管理员权限, do shell script的工作目录始终为/ (启动驱动器的根文件夹)。 但是,你可以这样做: tell application "Finder" set myFolder to (quoted form of (POSIX path of (parent of (path to me) as string))) end tell do shell script ¬ "installer -allowUntrusted -pkg " & myFolder & "D ...