Okay, here is detailed SVG code for a butterfly. This code includes:
- A defined
viewBox for scalability.
- Groups (
<g>) for organization (body, wings, antennae).
- Symmetry using the
<use> element and a transform to mirror the left wing and antenna to create the right side.
- Paths (
<path>) with Bezier curves for smooth, organic shapes for the wings and body.
- Gradient fills (
<linearGradient>, <radialGradient>) within <defs> for richer wing and spot colors.
- Multiple shapes for wing patterns (spots).
- Stroke attributes for outlines and details (like veins).
- Comments to explain different sections of the code.
<title> and <desc> for accessibility.
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="300px" height="250px" viewBox="0 0 300 250" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- SVG Butterfly - Detailed Example -->
<title>Detailed Blue Butterfly</title>
<desc>A detailed illustration of a blue butterfly with patterned wings, viewed from above.</desc>
<defs>
<!-- Define Gradients -->
<linearGradient id="blueWingGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#3a7bd5; stop-opacity:1" />
<stop offset="100%" style="stop-color:#00d2ff; stop-opacity:1" />
</linearGradient>
<linearGradient id="darkWingGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#2c3e50; stop-opacity:1" />
<stop offset="100%" style="stop-color:#4ca1af; stop-opacity:0.9" />
</linearGradient>
<radialGradient id="whiteSpotGradient" cx="50%" cy="50%" r="50%">
<stop offset="0%" style="stop-color:white; stop-opacity:1" />
<stop offset="70%" style="stop-color:white; stop-opacity:0.9" />
<stop offset="100%" style="stop-color:#f0f0f0; stop-opacity:0.7" />
</radialGradient>
<radialGradient id="bodyGradient" cx="50%" cy="50%" r="70%">
<stop offset="0%" style="stop-color:#555; stop-opacity:1" />
<stop offset="100%" style="stop-color:#222; stop-opacity:1" />
</radialGradient>
<!-- Define Left Wing Group (to be re-used for the right wing) -->
<g id="left-wing">
<!-- Left Forewing (Upper) -->
<path d="M 150 100
Q 80 20, 20 50
C 0 80, 10 130, 60 160
Q 100 150, 130 130
L 145 115 Z"
fill="url(#blueWingGradient)" stroke="#1a3a5f" stroke-width="1.5" />
<!-- Left Hindwing (Lower) -->
<path d="M 145 118
Q 100 160, 70 190
C 50 220, 90 240, 120 210
Q 140 180, 148 145 Z"
fill="url(#darkWingGradient)" stroke="#111" stroke-width="1"/>
<!-- Wing Veins/Details - Forewing -->
<path d="M 145 115 Q 100 80, 60 70" fill="none" stroke="#1a3a5f" stroke-width="0.8" stroke-opacity="0.7"/>
<path d="M 130 130 Q 90 110, 40 100" fill="none" stroke="#1a3a5f" stroke-width="0.8" stroke-opacity="0.7"/>
<path d="M 130 130 Q 80 140, 70 160" fill="none" stroke="#1a3a5f" stroke-width="0.8" stroke-opacity="0.7"/>
<!-- Wing Veins/Details - Hindwing -->
<path d="M 148 145 Q 110 170, 90 185" fill="none" stroke="#eee" stroke-width="0.7" stroke-opacity="0.6"/>
<path d="M 120 210 Q 120 180, 148 145" fill="none" stroke="#eee" stroke-width="0.7" stroke-opacity="0.6"/>
<!-- Wing Spots/Patterns - Forewing -->
<circle cx="50" cy="70" r="8" fill="url(#whiteSpotGradient)" stroke="black" stroke-width="0.5"/>
<ellipse cx="80" cy="100" rx="10" ry="6" fill="url(#whiteSpotGradient)" stroke="black" stroke-width="0.5" transform="rotate(-20 80 100)"/>
<circle cx="45" cy="135" r="5" fill="white" fill-opacity="0.8"/>
<!-- Wing Spots/Patterns - Hindwing -->
<circle cx="95" cy="195" r="7" fill="url(#blueWingGradient)" stroke="white" stroke-width="0.7"/>
<circle cx="115" cy="170" r="5" fill="url(#whiteSpotGradient)" stroke="black" stroke-width="0.3"/>
</g>
<!-- Define Left Antenna (to be re-used for the right antenna) -->
<g id="left-antenna">
<path d="M 150 85 Q 130 50, 110 30" stroke="black" stroke-width="1.5" fill="none" />
<circle cx="110" cy="30" r="3" fill="black" />
</g>
</defs>
<!-- Main Butterfly Drawing -->
<g id="butterfly" transform="translate(0, 5)"> <!-- Added slight top margin -->
<!-- Wings Group -->
<g id="wings">
<!-- Left Wing (using the definition) -->
<use xlink:href="#left-wing" />
<!-- Right Wing (mirroring the left wing) -->
<!-- The transform mirrors across the vertical line x=150 (center of viewBox) -->
<use xlink:href="#left-wing" transform="translate(300, 0) scale(-1, 1)" />
</g>
<!-- Body Group (drawn on top of wing bases) -->
<g id="body" transform="translate(150, 0)"> <!-- Center body horizontally -->
<!-- Abdomen -->
<ellipse cx="0" cy="160" rx="8" ry="35" fill="url(#bodyGradient)" stroke="#111" stroke-width="1"/>
<!-- Thorax -->
<ellipse cx="0" cy="115" rx="12" ry="25" fill="url(#bodyGradient)" stroke="#111" stroke-width="1"/>
<!-- Head -->
<circle cx="0" cy="85" r="8" fill="url(#bodyGradient)" stroke="#111" stroke-width="1"/>
</g>
<!-- Antennae Group (drawn on top of head) -->
<g id="antennae">
<!-- Left Antenna (using the definition) -->
<use xlink:href="#left-antenna"/>
<!-- Right Antenna (mirroring the left antenna) -->
<use xlink:href="#left-antenna" transform="translate(300, 0) scale(-1, 1)"/>
</g>
</g>
</svg>
How to Use:
- Copy the code above.
- Save it in a text file with an
.svg extension (e.g., butterfly.svg).
- Open the file in a web browser (like Chrome, Firefox, Edge) that supports SVG, or import it into vector graphics software (like Inkscape or Adobe Illustrator).
Explanation of Key Parts:
<svg>: The root element defining the canvas size (width, height) and the coordinate system (viewBox). 0 0 300 250 means the internal coordinate system goes from (0,0) top-left to (300,250) bottom-right.
<defs>: Holds definitions that can be reused. We define gradients (<linearGradient>, <radialGradient>) and, importantly, the entire left wing (<g id="left-wing">) and left antenna (<g id="left-antenna">) here.
<g> (Group): Used to group related elements. This helps in organizing the code and applying transformations or styles to multiple elements at once.
<path>: The most powerful shape element. The d attribute defines the shape using commands:
M x y: Move to coordinates (start point).
L x y: Line to coordinates.
Q cx cy, x y: Quadratic Bezier curve (one control point cx cy, end point x y).
C c1x c1y, c2x c2y, x y: Cubic Bezier curve (two control points, end point).
Z: Close the path (draw a line back to the start point M).
<circle>, <ellipse>: Simpler geometric shapes defined by center (cx, cy) and radius (r) or radii (rx, ry).
fill: Sets the color or gradient inside the shape. url(#gradientId) references a gradient defined in <defs>.
stroke: Sets the color of the outline.
stroke-width: Sets the thickness of the outline.
<use>: Reuses an element defined in <defs>. xlink:href="#id" points to the element to reuse.
transform="...": Applies transformations like translate (move), scale (resize/mirror), and rotate.
transform="translate(300, 0) scale(-1, 1)": This is used for mirroring. scale(-1, 1) flips the element horizontally around the y-axis (x=0). then moves the flipped element 300 units to the right. Since our width is 300, this effectively mirrors the left side (drawn relative to x=0, but intended for the left half around x=150) across the center line (x=150) to create the right side. The body is also centered at x=150 using on its group.
This code provides a good balance between detail and readability. You can modify the coordinates in the d attributes, change colors, add more spots, or adjust strokes to customize the butterfly further.