[英]JavaScript works on my local host, but not on web host (Hostinger)
[英]Why is my function not running properly in my local host but works perfectly fine in an online web editor?
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.