make shapes more moddable
This commit is contained in:
parent
e72dd8aefa
commit
353071dd2a
|
|
@ -3085,6 +3085,84 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
|
||||||
|
|
||||||
currentShape = "square";
|
currentShape = "square";
|
||||||
shapeOrder = ["square","circle","triangle","inverted triangle","rhombus","squircle","twinkle"];
|
shapeOrder = ["square","circle","triangle","inverted triangle","rhombus","squircle","twinkle"];
|
||||||
|
shapeExclusionConditions = {
|
||||||
|
/*"square": function(x,y,size,mouseX,mouseY,topLeft,bottomRight) {
|
||||||
|
return false
|
||||||
|
},*/
|
||||||
|
"triangle": function(x,y,size,mouseX,mouseY,topLeft,bottomRight) {
|
||||||
|
var xOffset = (x - topLeft[0]);
|
||||||
|
var yOffset = (y - topLeft[1]);
|
||||||
|
var distanceFromCenterLine;
|
||||||
|
if(size % 2 == 0) {
|
||||||
|
distanceFromCenterLine = Math.abs((size / 2) - (xOffset + 0.5))
|
||||||
|
} else {
|
||||||
|
distanceFromCenterLine = Math.abs(mouseX - x);
|
||||||
|
};
|
||||||
|
var distanceProportion = distanceFromCenterLine / size;
|
||||||
|
var hpovp = ((yOffset + (size % 2 == 0)) / size) / 2; //halvedPossiblyOffsetVerticalProportion
|
||||||
|
return distanceProportion > (hpovp + 0.01);
|
||||||
|
},
|
||||||
|
"inverted triangle": function(x,y,size,mouseX,mouseY,topLeft,bottomRight) {
|
||||||
|
var xOffset = (x - topLeft[0]);
|
||||||
|
var yOffset = (y - topLeft[1]);
|
||||||
|
var distanceFromCenterLine;
|
||||||
|
if(size % 2 == 0) {
|
||||||
|
distanceFromCenterLine = Math.abs((size / 2) - (xOffset + 0.5))
|
||||||
|
} else {
|
||||||
|
distanceFromCenterLine = Math.abs(mouseX - x);
|
||||||
|
};
|
||||||
|
var distanceProportion = distanceFromCenterLine / size;
|
||||||
|
var hpovpc = (1 - ((yOffset + (size % 2 !== 0)) / size)) / 2; //halvedPossiblyOffsetVerticalProportionComplement
|
||||||
|
return distanceProportion > (hpovpc + 0.01);
|
||||||
|
},
|
||||||
|
"rhombus": function(x,y,size,mouseX,mouseY,topLeft,bottomRight) {
|
||||||
|
var xOffset = (x - topLeft[0]);
|
||||||
|
var yOffset = (y - topLeft[1]);
|
||||||
|
var xDistanceFromCenterLine;
|
||||||
|
if(size % 2 == 0) { xDistanceFromCenterLine = Math.abs((size / 2) - (xOffset + 0.5)) } else { xDistanceFromCenterLine = Math.abs(mouseX - x) };
|
||||||
|
var yDistanceFromCenterLine;
|
||||||
|
if(size % 2 == 0) { yDistanceFromCenterLine = Math.abs((size / 2) - (yOffset + 0.5)) } else { yDistanceFromCenterLine = Math.abs(mouseY - y) };
|
||||||
|
return (xDistanceFromCenterLine + yDistanceFromCenterLine) > (size / 2) //i was just messing around, i didn't expect this to actually be the right condition :sob:
|
||||||
|
},
|
||||||
|
"squircle": function(x,y,size,mouseX,mouseY,topLeft,bottomRight) {
|
||||||
|
var xOffset = (x - topLeft[0]);
|
||||||
|
var yOffset = (y - topLeft[1]);
|
||||||
|
var xDistanceFromCenterLine;
|
||||||
|
if(size % 2 == 0) { xDistanceFromCenterLine = Math.abs((size / 2) - (xOffset + 0.5)) } else { xDistanceFromCenterLine = Math.abs(mouseX - x) };
|
||||||
|
var yDistanceFromCenterLine;
|
||||||
|
if(size % 2 == 0) { yDistanceFromCenterLine = Math.abs((size / 2) - (yOffset + 0.5)) } else { yDistanceFromCenterLine = Math.abs(mouseY - y) };
|
||||||
|
return ( (((xDistanceFromCenterLine ** 3) + (yDistanceFromCenterLine ** 3)) ** (1/3)) > (size / 2)) || ((size > 2) && (size <= 6) && ((xDistanceFromCenterLine + yDistanceFromCenterLine) == (size - 1)));
|
||||||
|
},
|
||||||
|
"twinkle": function(x,y,size,mouseX,mouseY,topLeft,bottomRight) {
|
||||||
|
var xOffset = (x - topLeft[0]);
|
||||||
|
var yOffset = (y - topLeft[1]);
|
||||||
|
var xDistanceFromCenterLine;
|
||||||
|
if(size % 2 == 0) { xDistanceFromCenterLine = Math.abs((size / 2) - (xOffset + 0.5)) } else { xDistanceFromCenterLine = Math.abs(mouseX - x) };
|
||||||
|
var yDistanceFromCenterLine;
|
||||||
|
if(size % 2 == 0) { yDistanceFromCenterLine = Math.abs((size / 2) - (yOffset + 0.5)) } else { yDistanceFromCenterLine = Math.abs(mouseY - y) };
|
||||||
|
return ((((xDistanceFromCenterLine ** (1/2)) + (yDistanceFromCenterLine ** (1/2))) ** (2)) > ((size / (size % 2 ? 2 : 1.7)))) && (xDistanceFromCenterLine > 0.5) && (yDistanceFromCenterLine > 0.5)
|
||||||
|
},
|
||||||
|
"circle": function(x,y,size,mouseX,mouseY,topLeft,bottomRight) {
|
||||||
|
var xOffset = (x - topLeft[0]);
|
||||||
|
var yOffset = (y - topLeft[1]);
|
||||||
|
var xDistanceFromCenterLine;
|
||||||
|
if(size % 2 == 0) { xDistanceFromCenterLine = Math.abs((size / 2) - (xOffset + 0.5)) } else { xDistanceFromCenterLine = Math.abs(mouseX - x) };
|
||||||
|
var yDistanceFromCenterLine;
|
||||||
|
if(size % 2 == 0) { yDistanceFromCenterLine = Math.abs((size / 2) - (yOffset + 0.5)) } else { yDistanceFromCenterLine = Math.abs(mouseY - y) };
|
||||||
|
if( (((xDistanceFromCenterLine ** 2) + (yDistanceFromCenterLine ** 2)) ** (1/2)) > (size / 2)) { return true }; //structured this way for legibility
|
||||||
|
if( ((xDistanceFromCenterLine + yDistanceFromCenterLine) == 2) && (size == 3)) { return true };
|
||||||
|
if( ((xDistanceFromCenterLine + yDistanceFromCenterLine) >= 3.5) && (size == 6)) { return true };
|
||||||
|
if( ((xDistanceFromCenterLine + yDistanceFromCenterLine) >= 4.5) && (size == 8) && !(Math.abs(xDistanceFromCenterLine) === Math.abs(yDistanceFromCenterLine))) { return true };
|
||||||
|
if( //i can't explain how these rules work, but they just do
|
||||||
|
(size % 2 == 1) &&
|
||||||
|
(size > 5) &&
|
||||||
|
((xDistanceFromCenterLine + yDistanceFromCenterLine) >= (size - 3)) &&
|
||||||
|
!(Math.abs(xDistanceFromCenterLine) === Math.abs(yDistanceFromCenterLine))
|
||||||
|
) { return true };
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//supplementary functions for below
|
//supplementary functions for below
|
||||||
|
|
||||||
|
|
@ -3099,112 +3177,31 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
|
||||||
else {
|
else {
|
||||||
var mouseOffset = Math.trunc(size/2);
|
var mouseOffset = Math.trunc(size/2);
|
||||||
}
|
}
|
||||||
switch(shape) {
|
|
||||||
case "square":
|
|
||||||
var topLeft = [mouseX-mouseOffset,mouseY-mouseOffset];
|
var topLeft = [mouseX-mouseOffset,mouseY-mouseOffset];
|
||||||
var bottomRight = [mouseX+mouseOffset,mouseY+mouseOffset];
|
var bottomRight = [mouseX+mouseOffset,mouseY+mouseOffset];
|
||||||
if(size % 2 == 0) {
|
if(size % 2 == 0) {
|
||||||
bottomRight[0]--;
|
bottomRight[0]--;
|
||||||
bottomRight[1]--;
|
bottomRight[1]--;
|
||||||
};
|
};
|
||||||
// Starting at the top left, go through each pixel
|
var exclusionFunction = shapeExclusionConditions[shape] ?? null;
|
||||||
for (var x = topLeft[0]; x <= bottomRight[0]; x++) {
|
if((shape !== "square") && (exclusionFunction == null)) {
|
||||||
for (var y = topLeft[1]; y <= bottomRight[1]; y++) {
|
|
||||||
// If the pixel is empty, add it to coords
|
|
||||||
coords.push([x,y]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
break
|
|
||||||
case "triangle":
|
|
||||||
case "inverted triangle":
|
|
||||||
var isInverted = (shape == "inverted triangle");
|
|
||||||
var topLeft = [mouseX-mouseOffset,mouseY-mouseOffset];
|
|
||||||
var bottomRight = [mouseX+mouseOffset,mouseY+mouseOffset];
|
|
||||||
if(size % 2 == 0) {
|
|
||||||
bottomRight[0]--;
|
|
||||||
bottomRight[1]--;
|
|
||||||
};
|
|
||||||
// Starting at the top left, go through each pixel
|
|
||||||
for (var x = topLeft[0]; x <= bottomRight[0]; x++) {
|
|
||||||
for (var y = topLeft[1]; y <= bottomRight[1]; y++) {
|
|
||||||
var xOffset = (x - topLeft[0]);
|
|
||||||
var yOffset = (y - topLeft[1]);
|
|
||||||
// If the pixel is empty, add it to coords
|
|
||||||
var distanceFromCenterLine;
|
|
||||||
if(size % 2 == 0) {
|
|
||||||
distanceFromCenterLine = Math.abs((size / 2) - (xOffset + 0.5))
|
|
||||||
} else {
|
|
||||||
distanceFromCenterLine = Math.abs(mouseX - x);
|
|
||||||
};
|
|
||||||
//if(y == topLeft[1]) { console.log(pixelTicks,distanceFromCenterLine) };
|
|
||||||
var distanceProportion = distanceFromCenterLine / size;
|
|
||||||
var hpovppc = isInverted ? (1 - ((yOffset + (size % 2 !== 0)) / size)) / 2 : ((yOffset + (size % 2 == 0)) / size) / 2; //halvedPossiblyOffsetVerticalProportionPossiblyComplement
|
|
||||||
//console.log(pixelTicks,distanceProportion,y,hpovp)
|
|
||||||
if(distanceProportion > (hpovppc + 0.01)) { continue };
|
|
||||||
coords.push([x,y]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
break
|
|
||||||
case "rhombus":
|
|
||||||
case "squircle":
|
|
||||||
case "circle":
|
|
||||||
case "twinkle":
|
|
||||||
var topLeft = [mouseX-mouseOffset,mouseY-mouseOffset];
|
|
||||||
var bottomRight = [mouseX+mouseOffset,mouseY+mouseOffset];
|
|
||||||
if(size % 2 == 0) {
|
|
||||||
bottomRight[0]--;
|
|
||||||
bottomRight[1]--;
|
|
||||||
};
|
|
||||||
// Starting at the top left, go through each pixel
|
|
||||||
for (var x = topLeft[0]; x <= bottomRight[0]; x++) {
|
|
||||||
for (var y = topLeft[1]; y <= bottomRight[1]; y++) {
|
|
||||||
var xOffset = (x - topLeft[0]);
|
|
||||||
|
|
||||||
var yOffset = (y - topLeft[1]);
|
|
||||||
|
|
||||||
var xDistanceFromCenterLine;
|
|
||||||
if(size % 2 == 0) {
|
|
||||||
xDistanceFromCenterLine = Math.abs((size / 2) - (xOffset + 0.5))
|
|
||||||
} else {
|
|
||||||
xDistanceFromCenterLine = Math.abs(mouseX - x);
|
|
||||||
};
|
|
||||||
|
|
||||||
var yDistanceFromCenterLine;
|
|
||||||
if(size % 2 == 0) {
|
|
||||||
yDistanceFromCenterLine = Math.abs((size / 2) - (yOffset + 0.5))
|
|
||||||
} else {
|
|
||||||
yDistanceFromCenterLine = Math.abs(mouseY - y);
|
|
||||||
};
|
|
||||||
|
|
||||||
if(shape == "rhombus") {
|
|
||||||
if((xDistanceFromCenterLine + yDistanceFromCenterLine) > (size / 2)) { continue } //i was just messing around, i didn't expect this to actually be the right condition :sob:
|
|
||||||
} else if(shape == "squircle") {
|
|
||||||
if( (((xDistanceFromCenterLine ** 3) + (yDistanceFromCenterLine ** 3)) ** (1/3)) > (size / 2)) { continue }; //a proper squircle has n=4 but that's even closer to a square
|
|
||||||
if((size > 2) && (size <= 6) && ((xDistanceFromCenterLine + yDistanceFromCenterLine) == (size - 1))) { continue }
|
|
||||||
} else if(shape == "twinkle") {
|
|
||||||
if( ((((xDistanceFromCenterLine ** (1/2)) + (yDistanceFromCenterLine ** (1/2))) ** (2)) > ((size / (size % 2 ? 2 : 1.7)))) && (xDistanceFromCenterLine > 0.5) && (yDistanceFromCenterLine > 0.5) ) { continue };
|
|
||||||
} else if(shape == "circle") {
|
|
||||||
if( (((xDistanceFromCenterLine ** 2) + (yDistanceFromCenterLine ** 2)) ** (1/2)) > (size / 2)) { continue };
|
|
||||||
if( ((xDistanceFromCenterLine + yDistanceFromCenterLine) == 2) && (size == 3)) { continue };
|
|
||||||
if( ((xDistanceFromCenterLine + yDistanceFromCenterLine) >= 3.5) && (size == 6)) { continue };
|
|
||||||
if( ((xDistanceFromCenterLine + yDistanceFromCenterLine) >= 4.5) && (size == 8) && !(Math.abs(xDistanceFromCenterLine) === Math.abs(yDistanceFromCenterLine))) { continue };
|
|
||||||
if( //i can't explain how these rules work, but they just do
|
|
||||||
(size % 2 == 1) &&
|
|
||||||
(size > 5) &&
|
|
||||||
((xDistanceFromCenterLine + yDistanceFromCenterLine) >= (size - 3)) &&
|
|
||||||
!(Math.abs(xDistanceFromCenterLine) === Math.abs(yDistanceFromCenterLine))
|
|
||||||
) { continue }
|
|
||||||
}
|
|
||||||
coords.push([x,y]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
logMessage(`Shape ${shape} not recognized!`)
|
logMessage(`Shape ${shape} not recognized!`)
|
||||||
coords = []
|
return []
|
||||||
|
};
|
||||||
|
|
||||||
|
// Starting at the top left, go through each pixel
|
||||||
|
for (var x = topLeft[0]; x <= bottomRight[0]; x++) {
|
||||||
|
for (var y = topLeft[1]; y <= bottomRight[1]; y++) {
|
||||||
|
// If the pixel is empty, add it to coords
|
||||||
|
if((shape !== "square") && exclusionFunction?.(x,y,size,mouseX,mouseY,topLeft,bottomRight)) {
|
||||||
|
continue
|
||||||
|
};
|
||||||
|
coords.push([x,y]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return coords
|
return coords
|
||||||
};
|
};
|
||||||
|
|
||||||
//this part defines basically all of the keybinds
|
//this part defines basically all of the keybinds
|
||||||
function addKeyboardListeners() {
|
function addKeyboardListeners() {
|
||||||
document.addEventListener("keydown", function(e) {
|
document.addEventListener("keydown", function(e) {
|
||||||
|
|
@ -3263,8 +3260,8 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
|
||||||
}
|
}
|
||||||
// If the user presses ] or =, increase the mouse size by 2
|
// If the user presses ] or =, increase the mouse size by 2
|
||||||
if (e.keyCode == 221 || e.keyCode == 187) {
|
if (e.keyCode == 221 || e.keyCode == 187) {
|
||||||
//If a shift key is pressed, increase by 15
|
//If a shift key is pressed, increase by 16
|
||||||
if (shiftDown && shiftDown % 2 == 1) {mouseSize = (mouseSize+15)-((mouseSize+15) % 15)}
|
if (shiftDown && shiftDown % 2 == 1) {mouseSize = (mouseSize+16)-((mouseSize+16) % 16)}
|
||||||
//If an alt key is pressed, increase by 1
|
//If an alt key is pressed, increase by 1
|
||||||
else if (shiftDown && shiftDown % 2 == 0) {mouseSize++}
|
else if (shiftDown && shiftDown % 2 == 0) {mouseSize++}
|
||||||
else {mouseSize += 2;}
|
else {mouseSize += 2;}
|
||||||
|
|
@ -42862,7 +42859,8 @@ maxPixels (default 1000): Maximum amount of pixels/changes (if xSpacing and ySpa
|
||||||
if(isNaN(_tps)) {
|
if(isNaN(_tps)) {
|
||||||
_tps = 30;
|
_tps = 30;
|
||||||
};
|
};
|
||||||
tps = _tps
|
tps = _tps;
|
||||||
|
resetInterval(tps);
|
||||||
|
|
||||||
var shape = urlParams.get("shape") ?? "square";
|
var shape = urlParams.get("shape") ?? "square";
|
||||||
if(shapeOrder.indexOf(shape) == -1) {
|
if(shapeOrder.indexOf(shape) == -1) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue