mirror of
https://github.com/Art-Portal/April.git
synced 2024-12-26 03:14:17 +01:00
Added color blend command
This commit is contained in:
parent
aa29f648a1
commit
c36304da5b
@ -2,6 +2,7 @@ const { SlashCommandBuilder } = require('discord.js');
|
||||
const Inspiration = require('./graphismecommands/inspiration.js');
|
||||
const Palette = require('./graphismecommands/palette.js');
|
||||
const Remix = require('./graphismecommands/remix.js');
|
||||
const Blend = require('./graphismecommands/colorblend.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
@ -46,6 +47,30 @@ module.exports = {
|
||||
{ name: 'Aquarelle', value: 'watercolor' },
|
||||
{ name: 'Néon', value: 'neon' },
|
||||
))
|
||||
)
|
||||
.addSubcommand(
|
||||
subcommand =>
|
||||
subcommand
|
||||
.setName('blend')
|
||||
.setDescription('Combine deux couleurs pour en créer une troisième.')
|
||||
.addStringOption(option =>
|
||||
option.setName('color1')
|
||||
.setDescription('La première couleur')
|
||||
.setRequired(true))
|
||||
.addStringOption(option =>
|
||||
option.setName('color2')
|
||||
.setDescription('La deuxième couleur')
|
||||
.setRequired(true))
|
||||
.addStringOption(option =>
|
||||
option.setName('mode')
|
||||
.setDescription('Le mode de fusion')
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: 'Normal', value: 'normal' },
|
||||
{ name: 'Multiplication', value: 'multiply' },
|
||||
{ name: 'Écran', value: 'screen' },
|
||||
{ name: 'Overlay', value: 'overlay' },
|
||||
))
|
||||
),
|
||||
async execute(interaction) {
|
||||
switch (interaction.options.getSubcommand()) {
|
||||
@ -58,6 +83,9 @@ module.exports = {
|
||||
case 'remix':
|
||||
Remix.execute(interaction);
|
||||
break;
|
||||
case 'blend':
|
||||
Blend.execute(interaction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
88
commands/misc/graphismecommands/colorblend.js
Normal file
88
commands/misc/graphismecommands/colorblend.js
Normal file
@ -0,0 +1,88 @@
|
||||
const { AttachmentBuilder } = require("discord.js")
|
||||
const Canvas = require('canvas');
|
||||
|
||||
module.exports = {
|
||||
async execute(interaction){
|
||||
const color1 = interaction.options.getString('color1'); // Première couleur
|
||||
const color2 = interaction.options.getString('color2'); // Deuxième couleur
|
||||
const blendMode = interaction.options.getString('mode'); // Mode de fusion
|
||||
|
||||
if (!isValidHexColor(color1) || !isValidHexColor(color2)) {
|
||||
interaction.reply({content: 'Les couleurs doivent être au format hexadécimal (ex. #FF0000).', ephermeral: true});
|
||||
return;
|
||||
}
|
||||
await interaction.deferReply();
|
||||
|
||||
const blendedColor = blendColors(color1, color2, blendMode);
|
||||
|
||||
const canvas = Canvas.createCanvas(99, 99);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.fillStyle = color1;
|
||||
ctx.fillRect(0, 0, 33, 99);
|
||||
ctx.fillStyle = blendedColor;
|
||||
ctx.fillRect(33, 0, 66, 99);
|
||||
ctx.fillStyle = color2;
|
||||
ctx.fillRect(66, 0, 99, 99);
|
||||
|
||||
const attachment = new AttachmentBuilder(canvas.toBuffer(), {name: 'blended_color.png'});
|
||||
await interaction.editReply({content: `Couleur résultante du mélange (${blendMode}) : ${blendedColor}`, files: [attachment]});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fonction pour vérifier si une chaîne est une couleur hexadécimale valide
|
||||
function isValidHexColor(hexColor) {
|
||||
return /^#[0-9A-F]{6}$/i.test(hexColor);
|
||||
}
|
||||
|
||||
// Fonction pour mélanger deux couleurs en fonction du mode de fusion
|
||||
function blendColors(color1, color2, blendMode) {
|
||||
// Parsez les composants RVB des couleurs
|
||||
const r1 = parseInt(color1.slice(1, 3), 16);
|
||||
const g1 = parseInt(color1.slice(3, 5), 16);
|
||||
const b1 = parseInt(color1.slice(5, 7), 16);
|
||||
|
||||
const r2 = parseInt(color2.slice(1, 3), 16);
|
||||
const g2 = parseInt(color2.slice(3, 5), 16);
|
||||
const b2 = parseInt(color2.slice(5, 7), 16);
|
||||
|
||||
// Appliquez le mode de fusion et calculez la couleur résultante
|
||||
let blendedR, blendedG, blendedB;
|
||||
switch (blendMode) {
|
||||
case 'normal':
|
||||
blendedR = r1;
|
||||
blendedG = g1;
|
||||
blendedB = b1;
|
||||
break;
|
||||
case 'multiply':
|
||||
blendedR = (r1 * r2) / 255;
|
||||
blendedG = (g1 * g2) / 255;
|
||||
blendedB = (b1 * b2) / 255;
|
||||
break;
|
||||
case 'screen':
|
||||
blendedR = 255 - (255 - r1) * (255 - r2) / 255;
|
||||
blendedG = 255 - (255 - g1) * (255 - g2) / 255;
|
||||
blendedB = 255 - (255 - b1) * (255 - b2) / 255;
|
||||
break;
|
||||
case 'overlay':
|
||||
blendedR = r1 < 128 ? (2 * r1 * r2) / 255 : 255 - (2 * (255 - r1) * (255 - r2)) / 255;
|
||||
blendedG = g1 < 128 ? (2 * g1 * g2) / 255 : 255 - (2 * (255 - g1) * (255 - g2)) / 255;
|
||||
blendedB = b1 < 128 ? (2 * b1 * b2) / 255 : 255 - (2 * (255 - b1) * (255 - b2)) / 255;
|
||||
break;
|
||||
// Ajoutez d'autres modes de fusion ici
|
||||
default:
|
||||
blendedR = r1;
|
||||
blendedG = g1;
|
||||
blendedB = b1;
|
||||
}
|
||||
|
||||
// Convertissez les composants RVB en une couleur hexadécimale
|
||||
const blendedColor = `#${componentToHex(Math.floor(blendedR))}${componentToHex(Math.floor(blendedG))}${componentToHex(Math.floor(blendedB))}`;
|
||||
return blendedColor;
|
||||
}
|
||||
|
||||
// Fonction pour convertir un composant RVB en hexadécimal
|
||||
function componentToHex(c) {
|
||||
const hex = c.toString(16);
|
||||
return hex.length === 1 ? `0${hex}` : hex;
|
||||
}
|
Loading…
Reference in New Issue
Block a user