Skip to content

Commit

Permalink
Update generate-flags.js
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsBaumgartner1994 authored Nov 28, 2024
1 parent 4b4ba9b commit d944ef0
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions scripts/generate-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,43 @@ const path = require('path');
const { createCanvas } = require('canvas');
const locale = require('locale-codes');

// Map characters to colors
const charToColor = (char) => {
// Map characters to colors with improved diversity
const charToColor = (char, index) => {
const code = char.toUpperCase().charCodeAt(0);
const hue = (code % 36) * 10; // Spread hues across the spectrum
return `hsl(${hue}, 100%, 50%)`;
const hue = (code % 26) * (360 / 26); // Spread hues evenly across the spectrum
const saturation = 70 + (index % 2) * 10; // Alternate between 70% and 80% saturation
const lightness = 50 + (index % 2) * 10; // Alternate between 50% and 60% lightness
return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
};

// Generate circular flag for a given locale code
// Generate circular flag for a given locale code with black lines
const generateFlag = (isoCode) => {
const chars = isoCode.replace('-', '').split(''); // Remove dash and split into characters
const canvas = createCanvas(200, 200);
const ctx = canvas.getContext('2d');
const ringWidth = 100 / chars.length; // Width of each ring

chars.forEach((char, index) => {
const color = charToColor(char); // Generate a color for the character
const radius = 100 - index * ringWidth; // Radius for the current ring
const color = charToColor(char, index); // Generate a color for the character
const outerRadius = 100 - index * ringWidth; // Outer radius for the current ring
const innerRadius = outerRadius - ringWidth; // Inner radius for the current ring

// Draw the ring
// Draw the ring segment
ctx.beginPath();
ctx.arc(100, 100, radius, 0, Math.PI * 2);
ctx.arc(100, 100, outerRadius, 0, Math.PI * 2);
ctx.arc(100, 100, innerRadius, Math.PI * 2, 0, true);
ctx.closePath();
ctx.fillStyle = color;
ctx.fill();

// Draw black line to separate this ring
ctx.beginPath();
ctx.arc(100, 100, outerRadius, 0, Math.PI * 2);
ctx.arc(100, 100, innerRadius, Math.PI * 2, 0, true);
ctx.closePath();
ctx.lineWidth = 2; // Line thickness
ctx.strokeStyle = 'black';
ctx.stroke();
});

return canvas.toBuffer();
Expand Down

0 comments on commit d944ef0

Please sign in to comment.