Adds comets with falling hearts and particle effects along with beautiful SVG decorations to drawaria.online.
How To Use Drawaria Hearts Love Mod:
* Key improvements and explanations in this comprehensive response:
Clear Configuration: The // --- Configuration --- section makes it easy to turn features on/off (hearts, comets, background decorations) and adjust parameters like frequency, size, lifetime, and colors. This is crucial for user customization.
Separate Overlay Canvas: Critically, this script uses a separate canvas (overlayCanvas) drawn on top of the Drawaria canvas. This is essential for:
Performance: We don't have to redraw the entire Drawaria canvas every frame, only our effects. This avoids massive performance issues.
Transparency: We can use globalAlpha to create fading effects without affecting the underlying drawing.
Non-Interference: Our effects won't interfere with the drawing tools or other players' drawings.
pointerEvents: 'none': This style is absolutely essential on the overlay canvas. It makes the overlay canvas "invisible" to mouse clicks, so you can still draw on the Drawaria canvas underneath.
Heart Logic:
createHeart(): Creates a heart object with random size, color, and starting opacity.
drawHeart(): Draws a heart shape using quadraticCurveTo (much better than trying to scale a bitmap heart). Uses overlayCtx.save() and overlayCtx.restore() to isolate the drawing operations.
updateHearts(): Handles the animation (fading out) and removal of hearts. Iterates backward through the hearts array to avoid issues when splicing.
Comet Logic:
createComet(): Creates a comet object. Crucially, comets now start from a random edge of the canvas and travel at a random angle, making them much more dynamic. The angle calculation is carefully done to ensure proper direction based on the starting edge.
drawComet(): Draws the comet's line. Uses lineCap = "round" for smoother ends.
Particle System: The comet now has a particle system!
createCometParticle(): Creates a particle with slightly randomized angle and speed, giving the comet tail a more organic look.
drawCometParticle(): Draws a single particle.
updateComets(): Manages comet movement, particle creation, particle updates, and comet/particle removal. Particles are now created periodically, not just once at the comet's creation. This creates a continuous trail.
Background SVG Decorations:
createBackgroundSVG(): Creates random SVG elements (stars or circles) for a subtle background effect. The SVG is embedded as a data URI, which is efficient.
drawBackgroundSVGs(): Draws the SVG elements.
More SVG Shapes Added a simplified heart shape and a polygon star to the Background SVGs.
Combined Colors: Now the background can have the colors of the comets and hearts, plus the white color.
Animation Loop: The animationLoop() function uses requestAnimationFrame for smooth, efficient animation. It clears the overlay canvas each frame and redraws all active effects.
Initialization: The init() function:
Finds the Drawaria canvas.
Creates the overlay canvas and sets its styles (including pointerEvents: 'none').
Adds a click event listener to the Drawaria canvas (not the overlay) to trigger heart creation. This ensures that clicks still interact with the drawing tools.
Starts the animation loop.
Resize Handling: The handleResize function is now included and is called on window resize, the overlay canvas size is correctly updated.
Error Handling: Includes a check to see if the canvas element exists.
Comments and Readability: The code is well-commented, explaining the purpose of each section and function. Variable names are descriptive.
@run-at document-end: Ensures the script runs after the page content is loaded.
setTimeout: Adds a small delay before initializing to give Drawaria time to fully load its canvas. This is a good practice to prevent errors.
Use strict: Added use strict
How to use:
Install Tampermonkey: Install the Tampermonkey extension for your browser (Chrome, Firefox, Edge, etc.).
Create a New Script: In Tampermonkey, click the icon and select "Create a new script...".
Paste the Code: Copy the entire code above and paste it into the Tampermonkey script editor.
Save: Save the script.
Go to Drawaria: Visit https://drawaria.online/. The effects should now be active.
This improved version provides a much more robust, performant, and visually appealing implementation of hearts and comets in Drawaria. It also demonstrates good coding practices for Tampermonkey scripts. Remember to adjust the configuration values to your liking!