Add count command
counts how many pxs of an element exist and alert()s the result
This commit is contained in:
parent
db94ebb826
commit
af09a65b38
|
|
@ -218,6 +218,37 @@ function funniPrompt() {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
break;
|
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:
|
default:
|
||||||
alert(`Command ${firstItem} not found!`);
|
alert(`Command ${firstItem} not found!`);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue