p5.js画布不可见

问题描述 投票:1回答:1

向正在阅读本文的人问好

我对以下代码有问题,我似乎无法让浏览器显示画布

JS代码:

sketch.js:

     var blob;

     function setup() {
        createCanvas(600, 600);
        blob = new Blob();
    }

    function draw() {
        background(0);
        blob.show();
    }

blob.js:

     function Blob() {
        this.pos = createVector(width / 2, height / 2);
        this.r = 64;
    }

    this.show = function() {
        fill(255);
        ellipse(this.pos.x, this.pos.y, this.r * 2, this.r * 2);
    };

[我首先使用script-src属性将其链接为外部javascript文件,但该文件不起作用,然后我尝试将其嵌入HTML文档中,但那也不起作用。

我也尝试过更改浏览器,但未能更改网页的外观,该网页仍然为空白。

然后,我尝试使用该元素来显示画布,但效果也不佳。

请帮助,我是第一次使用p5.js画布

javascript html5-canvas p5.js
1个回答
0
投票

this.show()方法应为Blob()对象的一部分,像这样

function Blob() {
  this.pos = createVector(width / 2, height / 2);
  this.r = 64;
  this.show = function() {
    fill(255);
    ellipse(this.pos.x, this.pos.y, this.r * 2, this.r * 2);
  }
}; 

Here是一个有效的例子。

© www.soinside.com 2019 - 2024. All rights reserved.