Virtual Mythological God Generator

Forge a deity! Select their core aspects or leave as 'Any' for divine inspiration.

${generatedGodData.domain}

Alignment / Nature:

${generatedGodData.alignment}

Symbols:

${generatedGodData.symbols || "None Defined"}

Sacred Elements:

${generatedGodData.sacredElements || "None Defined"}

Personality:

${generatedGodData.personality}

Appearance:

${generatedGodData.appearance}

Relationships (Hint):

${generatedGodData.relationshipHint}

Myth (Snippet):

...${generatedGodData.mythSnippet}

`; resultsDiv.style.display = 'block'; pdfBtn.disabled = false; // Enable PDF button } // --- PDF Download Function --- function downloadPDF() { if (!generatedGodData || Object.keys(generatedGodData).length === 0) { alert("Please generate a god profile first."); return; } // Ensure jsPDF is loaded if (typeof jspdf === 'undefined') { console.error("jsPDF library is not loaded."); alert("Error: PDF generation library failed to load. Please check internet or try again."); return; } const { jsPDF } = jspdf; const doc = new jsPDF(); // --- PDF Styling --- const primaryColor = '#b8860b'; // Gold const secondaryColor = '#4682b4'; // Blue const accentColor = '#8b4513'; // Brown const textColor = '#4a4a4a'; // Dark Grey const pageMargin = 15; const lineSpacing = 7; let currentY = pageMargin; // Helper to add text and manage Y position + page breaks function addTextToPDF(text, size, color, isBold = false) { const pageHeight = doc.internal.pageSize.height; // Using Garamond in PDF - ensure font is available or use fallback like 'times' doc.setFont("times", isBold ? 'bold' : 'normal'); const textLines = doc.splitTextToSize(text, doc.internal.pageSize.width - pageMargin * 2); if (currentY + size / 2 > pageHeight - pageMargin) { doc.addPage(); currentY = pageMargin; } doc.setFontSize(size); doc.setTextColor(color); textLines.forEach(line => { if (currentY + lineSpacing > pageHeight - pageMargin) { doc.addPage(); currentY = pageMargin; // Re-apply font settings doc.setFont("times", isBold ? 'bold' : 'normal'); doc.setFontSize(size); doc.setTextColor(color); } doc.text(line, pageMargin, currentY); currentY += lineSpacing; }); } function addHeadingPDF(text) { addTextToPDF(text, 14, accentColor, true); // Brown heading currentY += lineSpacing * 0.3; // Small gap after heading } function addParagraphPDF(text) { addTextToPDF(text, 11, textColor); currentY += lineSpacing * 0.5; // Extra gap after paragraph } // --- PDF Content --- addTextToPDF(`Profile: ${generatedGodData.name}`, 18, primaryColor, true); // Gold main title currentY += lineSpacing * 1.5; addHeadingPDF("Title / Epithet:"); addParagraphPDF(generatedGodData.title); addHeadingPDF("Domain:"); addParagraphPDF(generatedGodData.domain); addHeadingPDF("Alignment / Nature:"); addParagraphPDF(generatedGodData.alignment); addHeadingPDF("Symbols:"); addParagraphPDF(generatedGodData.symbols || "None Defined"); addHeadingPDF("Sacred Elements:"); addParagraphPDF(generatedGodData.sacredElements || "None Defined"); addHeadingPDF("Personality:"); addParagraphPDF(generatedGodData.personality); addHeadingPDF("Appearance:"); addParagraphPDF(generatedGodData.appearance); addHeadingPDF("Relationships (Hint):"); addParagraphPDF(generatedGodData.relationshipHint); addHeadingPDF("Myth (Snippet):"); addParagraphPDF(`...${generatedGodData.mythSnippet}`); // --- Save PDF --- doc.save(`god_profile_${generatedGodData.name.replace(/\s+/g, '_')}.pdf`); } // --- Event Listeners --- generateBtn.addEventListener('click', generateGod); pdfBtn.addEventListener('click', downloadPDF); })(); // Immediately invoke the function
Scroll to Top