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

时间:2013-05-14 15:58:24

标签: javascript canvas paperjs

亲爱的,我没有找到正常的解释,所以我决定寻求你的帮助。 我想在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>

但它在这里没有做任何事...... 谢谢你的关注。

1 个答案:

答案 0 :(得分:0)

您应该查看本教程: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>