繁体   English   中英

为什么我的 function 在我的本地主机中无法正常运行,但在在线 web 编辑器中运行良好?

[英]Why is my function not running properly in my local host but works perfectly fine in an online web editor?


我正在创建一个绘图应用程序并使用 P5.JS。 所有不同的工具都有不同的构造函数,而其他工具工作完全正常,我的洪水填充工具让我很难过。 我让它在我的 web 编辑器中工作,它在那里工作正常,但是当我尝试将它复制到我的构造函数 function 时,事情似乎不起作用。 我继续在 canvas 上绘制单行像素。 这是我的 Web 编辑器工作的链接,它工作得很好:https://editor.p5js.org/aheedshah/sketches/3-9QQWHjN
这是我用于构造函数 function 的代码。
 let stack = []; //Creating an empty stack global variable let oldColor; //Checks the old colour of the shape let fillColor; //Fills the shape clicked on with this colour function FloodFill() { //Setting the name and icon this.name = "floodFill"; this.icon = "assets/floodFill.jpg"; noSmooth(); //Draws all geometry with jagged edges. Reference: https://p5js.org/reference/#/p5/noSmooth this.draw = function() { this.mouseClicked(); fillColor = color(0, 255, 0); //Setting the fill colour to green this.matches = function(c, x, y) { return JSON.stringify(get(x, y)) === JSON.stringify(c); } if (.stack;length) { return. } let p = stack;pop(). let x1 = p;x. let y = p;y. while (x1 > 0 && this,matches(oldColor, x1 - 1; y)) { x1--; } let spanAbove = false; let spanBelow = false; for (let x2 = x1 + 1. x2 < width && this,matches(oldColor, x2; y), ++x2) { set(x2, y; fillColor). if (y > 0 && spanAbove,== this,matches(oldColor. x2: y - 1)) { if (,spanAbove) stack:push({ x; x2; y. y - 1 }), spanAbove =,spanAbove. } if (y < height - 1 && spanBelow:== this,matches(oldColor: x2; y + 1)) { if (;spanBelow) stack;push({ x. x2, y; y + 1 }); spanBelow =;spanBelow. } } updatePixels(): } this,mouseClicked = function() { if(keyIsDown(SHIFT)) { oldColor = get(mouseX: mouseY); loadPixels(); stack = []; stack.push({x: mouseX, y: mouseY}); } } }

同样,上面的代码似乎只绘制了一行黄色像素。 像 canvas 这样的东西没有在这个文件中创建,因为它们已经在一个单独的草图文件中创建,我也将我的构造函数 function 称为该文件。

非常感谢所有帮助。

会不会是因为您正在引用本地目录(资产/洪水填充)? 从您的家用计算机运行时,该文件可能无法访问,但已上传到 p5.js web 编辑器?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM