Yin and yang: Difference between revisions
Content added Content deleted
m (→SVG (path evenodd): cosmetics) |
m (→SVG (path evenodd): refactoring) |
||
Line 3,224: | Line 3,224: | ||
===SVG (path evenodd)=== |
===SVG (path evenodd)=== |
||
Run this script from the browser console (F12) or from the <script> tag in the body of the html document. |
Run this script from the browser console (F12) or from the <script> tag in the body of the html document. |
||
<syntaxhighlight lang="javascript"> |
<syntaxhighlight lang="javascript">function svgEl(tagName, attrs) { |
||
⚫ | |||
for (const key in attrs) el.setAttribute(key, attrs[key]); |
|||
⚫ | |||
} |
|||
function yinYang(r, x, y, th = 1) { |
function yinYang(r, x, y, th = 1) { |
||
Line 3,231: | Line 3,235: | ||
const d = cR(0, r + th) + cR(r / 2, r / 6) + cR(-r / 2, r / 6) |
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); |
+ `M${x},${y} ` + arc(r, r / 2, 0) + arc(-r, r) + arc(0, r / 2); |
||
⚫ | |||
⚫ | |||
path.setAttribute('d', d); |
|||
⚫ | |||
⚫ | |||
} |
} |
||
const dialog = document.body.appendChild(document.createElement('dialog')); |
const dialog = document.body.appendChild(document.createElement('dialog')); |
||
const svg = dialog.appendChild( |
const svg = dialog.appendChild(svgEl('svg', {width: 170, height: 120})); |
||
svg.setAttribute('width', 170); |
|||
svg.setAttribute('height', 120); |
|||
svg.appendChild(yinYang(50.0, 60, 60)); |
svg.appendChild(yinYang(50.0, 60, 60)); |
||
svg.appendChild(yinYang(20.0, 140, 30)); |
svg.appendChild(yinYang(20.0, 140, 30)); |