Add count command

counts how many pxs of an element exist and alert()s the result
This commit is contained in:
O-01-67 2022-09-01 11:51:02 -04:00 committed by GitHub
parent db94ebb826
commit af09a65b38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 0 deletions

View File

@ -218,6 +218,37 @@ function funniPrompt() {
};
};
break;
case "count":
//alert("To do");
if(inputAsArray.length < 2) {
alert("Usage: count [element] \nDon't include the brackets. \nNote: The element name can't have a space in it because spaces are the separator used in the parsing split(). \nArguments in [brackets] are required.");
break;
};
var inputElement = inputAsArray[1];
//console.log("Element gotten: " + inputElement);
var originalInput = inputElement; //for error display
inputElement = mostSimilarElement(inputElement);
if(!elements[inputElement]) {
alert("Element " + originalInput + " does not exist!");
break;
}
//Actual counting code;
var count = 0;
for (var i = 1; i < width; i++) {
for (var j = 1; j < height; j++) {
if (!isEmpty(i,j)) {
//console.log("Pixel (" + i + "," + j + ") exists")
if(pixelMap[i][j].element === inputElement) {
//console.log("Element is a match: " + inputElement + ", " + pixelMap[i][j].element)
count++;
};
};
};
};
alert(`There are ${count} pixels of ${inputElement}`);
break;
default:
alert(`Command ${firstItem} not found!`);
};