Jump to content

Yin and yang: Difference between revisions

m
m (→‎SVG (path evenodd): refactoring)
Line 3,224:
===SVG (path evenodd)===
Run this script from the browser console (F12) or from the <script> tag in the body of the html document.
<syntaxhighlight lang="javascript">constfunction NSsvgEl(tagName, =attrs) 'http://www.w3.org/2000/svg';{
const pathel = document.createElementNS(NS, 'pathhttp://www.w3.org/2000/svg', tagName);
for (const key in attrs) el.setAttribute(key, attrs[key]);
return pathel;
}
 
function yinYang(r, x, y, th = 1) {
Line 3,231 ⟶ 3,235:
const d = cR(0, r + th) + cR(r / 2, r / 6) + cR(-r / 2, r / 6)
+ `M${x},${y} ` + arc(r, r / 2, 0) + arc(-r, r) + arc(0, r / 2);
path.setAttributereturn svgEl('path', {d, 'fill-rule',: 'evenodd'});
const path = document.createElementNS(NS, 'path');
path.setAttribute('d', d);
path.setAttribute('fill-rule', 'evenodd');
return path;
}
 
const dialog = document.body.appendChild(document.createElement('dialog'));
const svg = dialog.appendChild(document.createElementNSsvgEl(NS, 'svg', {width: 170, height: 120}));
 
svg.setAttribute('width', 170);
svg.setAttribute('height', 120);
svg.appendChild(yinYang(50.0, 60, 60));
svg.appendChild(yinYang(20.0, 140, 30));
106

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.