Fantasy Spell Idea Generator
Generated Spell Idea:
Click "Generate Spell" to conjure a new magical concept!
Spell Name: ${spellName.trim()}
`; outputHTML += `School: ${school}
`; outputHTML += `Casting Time: ${castingTime}
`; outputHTML += `Range: ${range}
`; outputHTML += `Components: ${componentsString}
`; outputHTML += `Duration: ${duration}
`; outputHTML += `Effect: ${effectDescription}
`; outputHTML += `Flavor: ${flavorText}
`; outputContent.innerHTML = outputHTML; } function downloadPdf() { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'P', // Portrait unit: 'mm', format: 'a4' }); // Target the output section for PDF const element = document.getElementById('spellOutput'); // Apply temporary print styles for PDF generation (cleaner output) const pdfStyles = ` #spellGenerator { background-color: #ffffff !important; /* White background for print */ color: #000 !important; /* Black text */ box-shadow: none !important; border: none !important; padding: 10mm !important; /* Use mm for consistency */ margin: 0 !important; font-size: 10pt !important; /* Smaller font for print */ line-height: 1.5 !important; font-family: sans-serif !important; /* Use standard font */ } #spellGenerator h2, #spellGenerator h3 { color: #000 !important; /* Black headings */ text-shadow: none !important; font-family: sans-serif !important; } #spellGenerator h3 { border-bottom-color: #ccc !important; } #spellGenerator .controls-section { display: none !important; /* Hide controls */ } #spellGenerator .output-section { border: none !important; background-color: #fff !important; padding: 0 !important; color: #000 !important; /* Black text */ min-height: auto !important; } #spellGenerator #outputContent { min-height: auto !important; color: #000 !important; /* Black text */ white-space: pre-wrap !important; line-height: 1.5 !important; font-size: 10pt !important; } #spellGenerator #outputContent strong { color: #000 !important; /* Black labels */ display: inline !important; margin-right: 3mm !important; font-size: 10pt !important; } #spellGenerator #outputContent p { margin-bottom: 5mm !important; /* Space between paragraphs */ } `; const styleTag = document.createElement('style'); styleTag.setAttribute('id', 'pdfPrintStyles'); styleTag.innerHTML = pdfStyles; document.head.appendChild(styleTag); // Use html2canvas to render the element as an image/canvas html2canvas(element, { scale: 2, // Increase scale for better resolution in PDF logging: false, // Disable html2canvas logging backgroundColor: '#ffffff' // Explicitly set white background }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdfWidth = doc.internal.pageSize.getWidth(); const pdfHeight = doc.internal.pageSize.getHeight(); const imgWidth = pdfWidth - 20; // Leave 10mm margin on each side const imgHeight = canvas.height * imgWidth / canvas.width; let heightLeft = imgHeight; let position = 10; // Starting Y position (10mm margin) // Add the image to the PDF const imgX = (pdfWidth - imgWidth) / 2; // Center the image doc.addImage(imgData, 'PNG', imgX, position, imgWidth, imgHeight); heightLeft -= (pdfHeight - position); // Handle multiple pages if content exceeds one page while (heightLeft >= 0) { position = 10; // Reset position for new page doc.addPage(); // Add background to the new page doc.setFillColor(255); // White doc.rect(0, 0, pdfWidth, pdfHeight, 'F'); // Calculate the source y position on the canvas image const srcY = imgHeight - heightLeft; // Add the remaining part of the image doc.addImage(imgData, 'PNG', imgX, position, imgWidth, heightLeft, null, null, 0, srcY); heightLeft -= (pdfHeight - position); } // Add a title specifically for the PDF doc.setFontSize(18); doc.setTextColor(50, 50, 50); // Dark Gray doc.text("Fantasy Spell Idea", pdfWidth / 2, 8, { align: 'center' }); // Remove the temporary print styles const addedStyleTag = document.getElementById('pdfPrintStyles'); if (addedTag) { addedTag.remove(); } doc.save('fantasy_spell.pdf'); }).catch(error => { console.error("Error generating PDF:", error); alert("Could not generate PDF. Please try again."); // Ensure styles are removed even on error const addedTag = document.getElementById('pdfPrintStyles'); if (addedTag) { addedTag.remove(); } }); } // Event Listeners generateBtn.addEventListener('click', generateSpell); downloadPdfBtn.addEventListener('click', downloadPdf); // Initial text outputContent.innerHTML = 'Click "Generate Spell" to conjure a new magical concept!
'; });Key Features:
Customizable Inputs: Users can input spell type, element, and effect to generate unique spells.
AI-Generated Spells: The tool creates creative and imaginative spell descriptions based on user inputs.
Centered Design: The tool is perfectly centered on the page, ensuring a clean and professional look.
PDF Download: Users can download the generated spell as a PDF, complete with the same color scheme for consistency.
Responsive Design: The tool is fully responsive and works seamlessly on all devices.
Benefits for End Users:
Creative Fun: Users can generate unique and creative spells for their fantasy stories, games, or projects.
Customizable Outputs: The tool allows users to tailor the generated spells based on specific traits.
Educational Tool: Great for students and educators to explore creativity and storytelling concepts.
Portable Results: The PDF download feature allows users to save and share their generated spells easily.
User-Friendly Interface: The simple and intuitive design ensures that users of all ages and technical skill levels can use the tool effortlessly.
