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 c8b010e commit 3896bdf
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions scripts/generate-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@ const charToColor = (char) => {
return `hsl(${hue}, 100%, 50%)`;
};

// Generate donut-shaped flag for a given locale code
// Generate circular flag for a given locale code
const generateFlag = (isoCode) => {
const parts = isoCode.split('-'); // Split into language and region
const canvas = createCanvas(200, 200);
const ctx = canvas.getContext('2d');
const centerRadius = 50; // Radius of the empty center
const ringWidth = (100 - centerRadius) / parts.length; // Width of each ring
const ringWidth = 100 / parts.length; // Width of each ring

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

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

0 comments on commit 3896bdf

Please sign in to comment.