gpt4 book ai didi

javascript - 无法从 .html 文件运行 paper.js

转载 作者:行者123 更新时间:2023-11-28 09:08:58 24 4
gpt4 key购买 nike

亲爱的,我没有找到正常的解释,所以我决定寻求你的帮助。我想在 html 文件中创建一个 paper.js 项目。我无法连接它们的问题我尝试使用 var scope = new paper.PaperScope();
scope.setup(myCanvas);

但是没有成功。 这是取自 Paper.js web site 的代码

    <!DOCTYPE html>
<html>
<head>
<!-- Load the Paper.js library -->
<script type="text/javascript" src="paper.js"></script>
<!-- Define inlined JavaScript -->
<script type="text/javascript">
// Only executed our code once the DOM is ready.
var scope = new paper.PaperScope();
scope.setup(myCanvas);

var myPath = new Path();
myPath.strokeColor = 'black';

// This function is called whenever the user
// clicks the mouse in the view:
function onMouseDown(event) {
// Add a segment to the path at the position of the mouse:
myPath.add(event.point);
}
</script>
</head>
<body>
<canvas id="myCanvas" resize></canvas>
</body>
</html>

但它在这里没有任何作用......感谢您的关注。

最佳答案

您应该看看本教程:http://paperjs.org/tutorials/getting-started/using-javascript-directly/

这是一个有效的示例:

<!DOCTYPE html>
<html>
<head>
<!-- Load the Paper.js library -->
<script type="text/javascript" src="paper.min.js"></script>
<!-- Define inlined JavaScript -->
<script type="text/javascript">
// Only executed our code once the DOM is ready.
window.onload = function() {
// Get a reference to the canvas object
var canvas = document.getElementById('myCanvas');
// Create an empty project and a view for the canvas:
paper.setup(canvas);

var myPath = new paper.Path();
myPath.strokeColor = 'black';

// Draw the view now:
paper.view.draw();

var tool = new paper.Tool();

tool.onMouseDown = function(event) {
myPath.add(event.point);
}
}
</script>
</head>
<body>
<canvas id="myCanvas" resize></canvas>
</body>
</html>

关于javascript - 无法从 .html 文件运行 paper.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16547738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com