|
| 1 | +import { wrapText } from '../utils'; |
| 2 | + |
| 3 | +export const luxe = (ctx, width, height, scale, data) => { |
| 4 | + const { repoOwner, repoName, description, language, stars, primaryColor, secondaryColor, bgColor } = data; |
| 5 | + |
| 6 | + // LCG Random Generator (Ported from LuxeArt.jsx) |
| 7 | + const seed = repoName + repoOwner; |
| 8 | + let h = 0xdeadbeef; |
| 9 | + for (let i = 0; i < seed.length; i++) { |
| 10 | + h = Math.imul(h ^ seed.charCodeAt(i), 2654435761); |
| 11 | + } |
| 12 | + const rng = () => { |
| 13 | + h = Math.imul(h ^ (h >>> 16), 2246822507); |
| 14 | + h = Math.imul(h ^ (h >>> 13), 3266489909); |
| 15 | + return ((h ^= h >>> 16) >>> 0) / 4294967296; |
| 16 | + }; |
| 17 | + |
| 18 | + // Background |
| 19 | + ctx.fillStyle = '#EBEBEB'; // Light grey/white as in LuxeArt |
| 20 | + ctx.fillRect(0, 0, width, height); |
| 21 | + |
| 22 | + // Organic Curves (Ported from LuxeArt.jsx) |
| 23 | + const curveCount = 8 + Math.floor(rng() * 5); |
| 24 | + const baseHue = Math.floor(rng() * 360); |
| 25 | + |
| 26 | + ctx.save(); |
| 27 | + // We'll use multiply blend mode for the curves as in LuxeArt |
| 28 | + ctx.globalCompositeOperation = 'multiply'; |
| 29 | + |
| 30 | + for (let i = 0; i < curveCount; i++) { |
| 31 | + const points = []; |
| 32 | + const segments = 4; |
| 33 | + const startY = rng() * height; |
| 34 | + |
| 35 | + points.push({ x: 0, y: startY }); |
| 36 | + |
| 37 | + for (let j = 1; j <= segments; j++) { |
| 38 | + points.push({ |
| 39 | + x: (j / segments) * width, |
| 40 | + y: startY + (rng() - 0.5) * (height * 0.5), |
| 41 | + }); |
| 42 | + } |
| 43 | + |
| 44 | + // Draw Smooth Curve |
| 45 | + ctx.beginPath(); |
| 46 | + ctx.moveTo(points[0].x, points[0].y); |
| 47 | + |
| 48 | + for (let j = 0; j < points.length - 1; j++) { |
| 49 | + const p0 = points[j]; |
| 50 | + const p1 = points[j + 1]; |
| 51 | + const cp1x = p0.x + (p1.x - p0.x) / 2; |
| 52 | + const cp1y = p0.y; |
| 53 | + const cp2x = p0.x + (p1.x - p0.x) / 2; |
| 54 | + const cp2y = p1.y; |
| 55 | + ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, p1.x, p1.y); |
| 56 | + } |
| 57 | + |
| 58 | + // Close shape to bottom |
| 59 | + ctx.lineTo(width, height); |
| 60 | + ctx.lineTo(0, height); |
| 61 | + ctx.closePath(); |
| 62 | + |
| 63 | + // Color generation (Ported from LuxeArt.jsx) |
| 64 | + const isGold = rng() > 0.8; |
| 65 | + const hue = isGold ? 45 : baseHue + (rng() - 0.5) * 30; |
| 66 | + const sat = isGold ? 60 : 0; |
| 67 | + const lit = isGold ? 60 : 90 - i * 5; |
| 68 | + const opacity = 0.05 + rng() * 0.15; |
| 69 | + |
| 70 | + ctx.fillStyle = `hsla(${hue}, ${sat}%, ${lit}%, ${opacity})`; |
| 71 | + ctx.fill(); |
| 72 | + |
| 73 | + ctx.strokeStyle = `hsla(${hue}, ${sat}%, ${lit - 20}%, ${opacity * 2})`; |
| 74 | + ctx.lineWidth = 1 * scale; |
| 75 | + ctx.stroke(); |
| 76 | + } |
| 77 | + ctx.restore(); |
| 78 | + |
| 79 | + // Noise specks |
| 80 | + ctx.save(); |
| 81 | + for (let k = 0; k < 100; k++) { |
| 82 | + const cx = rng() * width; |
| 83 | + const cy = rng() * height; |
| 84 | + const r = rng() * 3 * scale; |
| 85 | + ctx.beginPath(); |
| 86 | + ctx.arc(cx, cy, r, 0, Math.PI * 2); |
| 87 | + ctx.fillStyle = 'rgba(0,0,0,0.1)'; |
| 88 | + ctx.fill(); |
| 89 | + } |
| 90 | + ctx.restore(); |
| 91 | + |
| 92 | + // Typography & Content |
| 93 | + const serifFont = '"Playfair Display", "Times New Roman", serif'; |
| 94 | + const monoFont = '"JetBrains Mono", "Courier New", monospace'; |
| 95 | + |
| 96 | + // Decorative Line |
| 97 | + ctx.strokeStyle = '#000'; |
| 98 | + ctx.lineWidth = 1 * scale; |
| 99 | + ctx.beginPath(); |
| 100 | + ctx.moveTo(width * 0.1, height * 0.2); |
| 101 | + ctx.lineTo(width * 0.9, height * 0.2); |
| 102 | + ctx.stroke(); |
| 103 | + |
| 104 | + // Repo Owner (Brand) |
| 105 | + ctx.fillStyle = '#000'; |
| 106 | + ctx.font = `italic 300 ${24 * scale}px ${serifFont}`; |
| 107 | + ctx.textAlign = 'left'; |
| 108 | + ctx.letterSpacing = '10px'; |
| 109 | + ctx.fillText(repoOwner.toUpperCase(), width * 0.1, height * 0.15); |
| 110 | + |
| 111 | + // Repo Name |
| 112 | + ctx.font = `normal 900 ${120 * scale}px ${serifFont}`; |
| 113 | + ctx.letterSpacing = 'normal'; |
| 114 | + ctx.fillText(repoName, width * 0.1, height * 0.45); |
| 115 | + |
| 116 | + // Description |
| 117 | + ctx.font = `italic 300 ${32 * scale}px ${serifFont}`; |
| 118 | + ctx.fillStyle = '#333'; |
| 119 | + wrapText(ctx, description, width * 0.1, height * 0.6, width * 0.6, 45 * scale); |
| 120 | + |
| 121 | + // Language & Stats (Bottom Bar) |
| 122 | + ctx.font = `bold ${20 * scale}px ${monoFont}`; |
| 123 | + ctx.fillStyle = '#000'; |
| 124 | + ctx.textAlign = 'right'; |
| 125 | + ctx.fillText(language.toUpperCase(), width * 0.9, height * 0.85); |
| 126 | + |
| 127 | + ctx.font = `normal ${20 * scale}px ${monoFont}`; |
| 128 | + ctx.fillText(`${stars} STARS // ${repoOwner}`, width * 0.9, height * 0.9); |
| 129 | + |
| 130 | + // Accent Circle |
| 131 | + ctx.beginPath(); |
| 132 | + ctx.arc(width * 0.85, height * 0.4, 40 * scale, 0, Math.PI * 2); |
| 133 | + ctx.strokeStyle = '#000'; |
| 134 | + ctx.lineWidth = 0.5 * scale; |
| 135 | + ctx.stroke(); |
| 136 | +}; |
0 commit comments