Fantasy Story Idea Generator

Fantasy Story Idea Generator

Forge your next epic tale from the elements of legend.

Choose Your Hero

...must ${goal}

The Obstacle

...while facing ${obstacle}

The Setting

...all taking place ${setting}.

`; document.getElementById('output-display').innerHTML = idea; formContainer.classList.add('hidden'); document.getElementById('tab-container').classList.add('hidden'); navButtons.classList.add('hidden'); outputSection.classList.remove('hidden'); } function downloadPDF() { const { jsPDF } = window.jspdf; const downloadButton = downloadBtn; if (!downloadButton) return; downloadButton.textContent = 'Forging Scroll...'; downloadButton.disabled = true; try { const protagonist = document.getElementById('protagonist').value; const goal = document.getElementById('goal').value; const obstacle = document.getElementById('obstacle').value; const setting = document.getElementById('setting').value; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); // Add custom fonts if available (jsPDF requires font files) // For simplicity, we use built-in serif fonts doc.setFont('times', 'normal'); const margin = 20; const pageHeight = doc.internal.pageSize.getHeight(); const pageWidth = doc.internal.pageSize.getWidth(); const usableWidth = pageWidth - margin * 2; let yPos = margin; // --- PDF Template: Quest Scroll --- // Background color to simulate parchment doc.setFillColor(245, 245, 220); // Beige doc.rect(0, 0, pageWidth, pageHeight, 'F'); // Ornate border doc.setDrawColor(139, 69, 19); // SaddleBrown doc.setLineWidth(0.5); doc.rect(margin / 2, margin / 2, pageWidth - margin, pageHeight - margin); doc.setLineWidth(0.2); doc.rect(margin / 2 + 2, margin / 2 + 2, pageWidth - margin - 4, pageHeight - margin - 4); // Title yPos += 10; doc.setFont('times', 'bold'); doc.setFontSize(24); doc.setTextColor(83, 53, 10); doc.text('A New Legend Begins...', pageWidth / 2, yPos, { align: 'center' }); yPos += 15; // Helper to draw a section const drawSection = (title, text) => { doc.setFont('times', 'bold'); doc.setFontSize(16); doc.setTextColor(139, 69, 19); doc.text(title, margin, yPos); yPos += 8; doc.setFont('times', 'normal'); doc.setFontSize(12); doc.setTextColor(30, 30, 30); const lines = doc.splitTextToSize(text, usableWidth); doc.text(lines, margin, yPos); yPos += (lines.length * 5) + 10; }; drawSection('The Protagonist:', protagonist); drawSection('The Quest:', `Must ${goal}.`); drawSection('The Obstacle:', `Must face ${obstacle}.`); drawSection('The Setting:', `The story takes place ${setting}.`); yPos += 10; doc.setDrawColor(139, 69, 19); doc.line(margin, yPos, pageWidth - margin, yPos); yPos += 15; // Combined Story Prompt doc.setFont('times', 'bold'); doc.setFontSize(14); doc.setTextColor(83, 53, 10); doc.text('The Story Prompt:', margin, yPos); yPos += 8; doc.setFont('times', 'normal'); doc.setFontSize(12); const promptText = `${protagonist} must ${goal}, all while facing ${obstacle} ${setting}.`; const promptLines = doc.splitTextToSize(promptText, usableWidth); doc.text(promptLines, margin, yPos); // Save the PDF doc.save(`Fantasy_Story_Idea.pdf`); } catch (error) { console.error("Error generating PDF:", error); alert("An error occurred while generating the PDF. Please try again."); } finally { downloadButton.textContent = 'Download as Quest Scroll (PDF)'; downloadButton.disabled = false; } } // --- Initial Setup --- showTab(currentTab); });
Scroll to Top