Remove lines, add polygons
This commit is contained in:
@@ -36,6 +36,13 @@
|
|||||||
stroke: limegreen;
|
stroke: limegreen;
|
||||||
stroke-width: 0.5px;
|
stroke-width: 0.5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#lines polygon {
|
||||||
|
fill: white;
|
||||||
|
stroke: teal;
|
||||||
|
fill-opacity: 0.2;
|
||||||
|
stroke-width: 0.5px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<rect id="bg" x="-200" y="-150" width="400" height="300"/>
|
<rect id="bg" x="-200" y="-150" width="400" height="300"/>
|
||||||
@@ -113,14 +120,40 @@
|
|||||||
|
|
||||||
const lineContainer = document.querySelector('#lines');
|
const lineContainer = document.querySelector('#lines');
|
||||||
|
|
||||||
points.forEach(([x, y]) => {
|
// points.forEach(([x, y]) => {
|
||||||
const el = document.createElementNS(namespaceURIsvg, 'line');
|
// const el = document.createElementNS(namespaceURIsvg, 'line');
|
||||||
el.setAttribute('x1', x);
|
// el.setAttribute('x1', x);
|
||||||
el.setAttribute('y1', y);
|
// el.setAttribute('y1', y);
|
||||||
el.setAttribute('x2', x);
|
// el.setAttribute('x2', x);
|
||||||
el.setAttribute('y2', y);
|
// el.setAttribute('y2', y);
|
||||||
lineContainer.appendChild(el)
|
// lineContainer.appendChild(el)
|
||||||
});
|
// });
|
||||||
|
|
||||||
|
const triangleContainer = document.querySelector('#lines');
|
||||||
|
const trianglePts = points.map((pt, i) => [pt, points[(i + 1) % points.length]]);
|
||||||
|
|
||||||
|
function drawTriangles(container, pts, [positionX, positionY]) {
|
||||||
|
pts.forEach(([[x1, y1], [x2, y2]]) => {
|
||||||
|
const el = document.createElementNS(namespaceURIsvg, 'polygon');
|
||||||
|
const attr = `${x1},${y1} ${x2},${y2} ${positionX},${positionY}`
|
||||||
|
el.setAttribute('points', attr);
|
||||||
|
container.appendChild(el)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
drawTriangles(triangleContainer, trianglePts, [0, 0]);
|
||||||
|
const triangles = triangleContainer.querySelectorAll('polygon');
|
||||||
|
|
||||||
|
function updateTriangles([positionX, positionY]) {
|
||||||
|
const delim = ' ';
|
||||||
|
|
||||||
|
triangles.forEach(triangle => {
|
||||||
|
const attr = triangle.getAttribute('points').split(delim)
|
||||||
|
attr.pop();
|
||||||
|
attr.push(`${positionX},${positionY}`);
|
||||||
|
triangle.setAttribute('points', attr.join(delim));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const lines = lineContainer.querySelectorAll('line');
|
const lines = lineContainer.querySelectorAll('line');
|
||||||
|
|
||||||
@@ -278,7 +311,8 @@
|
|||||||
let position = [positionX, positionY] = wrapPos(changeX + x, changeY + y);
|
let position = [positionX, positionY] = wrapPos(changeX + x, changeY + y);
|
||||||
|
|
||||||
updateBullets(elapsed);
|
updateBullets(elapsed);
|
||||||
updateLines(position);
|
// updateLines(position);
|
||||||
|
updateTriangles(position);
|
||||||
|
|
||||||
pt.x = positionX;
|
pt.x = positionX;
|
||||||
pt.y = positionY;
|
pt.y = positionY;
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 14 KiB |
Reference in New Issue
Block a user