Sure! Below is a single HTML file that:
- Displays an ASCII drawing of Edifier R1280 speakers.
- Includes a JavaScript function that parses the ASCII art and converts it into an SVG image.
- Renders the SVG version below the ASCII art using clean lines and shapes.
📄 Save this as r1280_ascii_to_svg.html and open it in a browser:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Edifier R1280 – ASCII to SVG</title>
<style>
body {
background: #111;
color: #eee;
font-family: "Courier New", monospace;
margin: 0;
padding: 20px;
}
pre {
white-space: pre;
font-size: 14px;
line-height: 1.1em;
}
#svgContainer {
margin-top: 30px;
background: #fff;
padding: 10px;
display: inline-block;
}
</style>
</head>
<body>
<h2>ASCII Drawing</h2>
<pre id="asciiArt">
+------------------+ +------------------+
| | | |
| ________ | | |
| / () \ | | |
| | ____ | | | |
| \ / \ / | | |
| \______/ | | |
| | | |
| __________ | | |
| / () ()\ | | |
| | ____ | | | |
| \ / \ / | | |
| \______/ | | |
| | | |
+------------------+ +------------------+
</pre>
<h2>SVG Version</h2>
<div id="svgContainer"></div>
<script>
function asciiToSvg(ascii, cellSize = 10) {
const lines = ascii.split('\n');
const rows = lines.length;
const cols = Math.max(...lines.map(line => line.length));
const width = cols * cellSize;
const height = rows * cellSize;
const svgNS = "http://www.w3.org/2000/svg";
const svg = document.createElementNS(svgNS, "svg");
svg.setAttribute("width", width);
svg.setAttribute("height", height);
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
svg.setAttribute("xmlns", svgNS);
svg.setAttribute("style", "background:#fff");
// Draw lines based on ASCII characters
for (let y = 0; y < rows; y++) {
const line = lines[y];
for (let x = 0; x < line.length; x++) {
const ch = line[x];
const x1 = x * cellSize;
const y1 = y * cellSize;
const x2 = x1 + cellSize;
const y2 = y1 + cellSize;
switch (ch) {
case '+':
drawCircle(x1 + cellSize / 2, y1 + cellSize / 2, 1.5);
break;
case '-':
drawLine(x1, y1 + cellSize / 2, x2, y1 + cellSize / 2);
break;
case '|':
drawLine(x1 + cellSize / 2, y1, x1 + cellSize / 2, y2);
break;
case '/':
drawLine(x2, y1, x1, y2);
break;
case '\\':
drawLine(x1, y1, x2, y2);
break;
case '_':
drawLine(x1, y2 - 2, x2, y2 - 2);
break;
case '(':
case ')':
case 'o':
case 'O':
case '0':
case '●':
case '•':
case '()':
drawCircle(x1 + cellSize / 2, y1 + cellSize / 2, 2);
break;
default:
// ignore other characters
break;
}
}
}
function drawLine(x1, y1, x2, y2) {
const line = document.createElementNS(svgNS, "line");
line.setAttribute("x1", x1);
line.setAttribute("y1", y1);
line.setAttribute("x2", x2);
line.setAttribute("y2", y2);
line.setAttribute("stroke", "#000");
line.setAttribute("stroke-width", 1);
svg.appendChild(line);
}
function drawCircle(cx, cy, r) {
const circle = document.createElementNS(svgNS, "circle");
circle.setAttribute("cx", cx);
circle.setAttribute("cy", cy);
circle.setAttribute("r", r);
circle.setAttribute("fill", "#000");
svg.appendChild(circle);
}
return svg;
}
// Get ASCII art and convert to SVG
const ascii = document.getElementById("asciiArt").textContent;
const svg = asciiToSvg(ascii, 10);
document.getElementById("svgContainer").appendChild(svg);
</script>
</body>
</html>
🧠 How it works:
- The ASCII art is stored in a block.
- JavaScript reads each character and maps certain characters to SVG shapes:
-
- becomes a small circle (corner)
-
- becomes a horizontal line
- | becomes a vertical line
- / and \ become diagonal lines
- _ becomes a bottom line
- () and similar characters become small circles (for speaker cones)
- The result is a clean SVG rendering of the ASCII layout.
🛠️ You can customize:
- cellSize to scale the SVG
- Add more character mappings for richer detail
Let me know if you want to export the SVG or add interactivity!