mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
![unsettledgames](/assets/img/avatar_default.png)
Fixed a bug in the flatten visible undo, created an array to store the colours in the current palette, implemented project saving.
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
|
|
function createColorPalette(selectedPalette, fillBackground) {
|
|
//remove current palette
|
|
colors = document.getElementsByClassName('color-button');
|
|
while (colors.length > 0) {
|
|
colors[0].parentElement.remove();
|
|
}
|
|
|
|
var lightestColor = '#000000';
|
|
var darkestColor = '#ffffff';
|
|
|
|
for (var i = 0; i < selectedPalette.length; i++) {
|
|
var newColor = selectedPalette[i];
|
|
var newColorElement = addColor(newColor);
|
|
|
|
var newColorHex = hexToRgb(newColor);
|
|
|
|
var lightestColorHex = hexToRgb(lightestColor);
|
|
if (newColorHex.r + newColorHex.g + newColorHex.b > lightestColorHex.r + lightestColorHex.g + lightestColorHex.b)
|
|
lightestColor = newColor;
|
|
|
|
var darkestColorHex = hexToRgb(darkestColor);
|
|
if (newColorHex.r + newColorHex.g + newColorHex.b < darkestColorHex.r + darkestColorHex.g + darkestColorHex.b) {
|
|
|
|
//remove current color selection
|
|
var selectedColor = document.querySelector('#colors-menu li.selected');
|
|
if (selectedColor) selectedColor.classList.remove('selected');
|
|
|
|
//set as current color
|
|
newColorElement.classList.add('selected');
|
|
|
|
darkestColor = newColor;
|
|
}
|
|
|
|
}
|
|
|
|
//set as current color
|
|
currentLayer.context.fillStyle = darkestColor;
|
|
}
|