move circle functions out to library (2)

also a logic fix
This commit is contained in:
Laetitia (O-01-67) 2022-12-08 11:03:20 -05:00 committed by GitHub
parent bb7a18b6f9
commit 1e4dbcd623
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 1 deletions

View File

@ -410,7 +410,7 @@
};
};
} else if(typeof(color) === "object") {
if(!color.r || !color.g || !color.b) {
if(typeof(color.r) === "undefined" || typeof(color.g) === "undefined" || typeof(color.b) === "undefined") {
throw new Error("Color must be of the form {r: red, g: green, b: blue}");
};
@ -1094,6 +1094,38 @@
};
};
//World
function breakCircle(x,y,radius,respectHardness=false,changeTemp=false,defaultBreakIntoDust=false) {
var coords = circleCoords(x,y,radius);
for(i = 0; i < coords.length; i++) {
coordX = coords[i].x;
coordY = coords[i].y;
if(!isEmpty(coordX,coordY,true)) {
var pixel = pixelMap[coordX][coordY];
respectHardness ? tryBreak(pixel,changeTemp,defaultBreakIntoDust) : breakPixel(pixel,changeTemp,defaultBreakIntoDust);
};
};
};
function fillCircle(element,x,y,radius,overwrite=false) {
var coords = circleCoords(x,y,radius);
var newElement = element;
if(Array.isArray(newElement)) {
newElement = newElement[Math.floor(Math.random() * newElement.length)];
};
for(i = 0; i < coords.length; i++) {
coordX = coords[i].x;
coordY = coords[i].y;
if(overwrite && !isEmpty(coordX,coordY,true)) {
changePixel(pixelMap[coordX][coordY],element);
};
if(isEmpty(coordX,coordY,false)) {
createPixel(element,coordX,coordY);
};
};
};
//Logic
function xor(c1,c2) {