/************* * SVG * ************/ var oView = document.getElementById('svg'), nHue = 360, oCircle, nAngle; while (nHue--) { nAngle = nHue * Math.PI / 180; oCircle = document.createElementNS('http://www.w3.org/2000/svg', 'circle'); oCircle.setAttribute('cx', 50 - Math.sin(nAngle) * 45); oCircle.setAttribute('cy', 50 - Math.cos(nAngle) * 45); oCircle.setAttribute('r', '5'); oCircle.setAttribute('fill', 'hsl(' + nHue + ', 100%, 50%)'); oView.appendChild(oCircle); } /************** * CANVAS * *************/ var cnv = document.getElementById('cnv'); var ctx = cnv.getContext('2d'); var nCY = cnv.height / 2; var nCX = cnv.width / 2; var nR = cnv.width / 2; var nHues = 360; while (nHues--) { nStartCX = nCX + (Math.cos(nHues * Math.PI / 180) * nR * 0.8); nStartCY = nCY + (Math.sin(nHues * Math.PI / 180) * nR * 0.8); nStopCX = nCX + (Math.cos((nHues + 2) * Math.PI / 180) * nR * 0.8); nStopCY = nCY + (Math.sin((nHues + 2) * Math.PI / 180) * nR * 0.8); nStartDX = nCX + (Math.cos(nHues * Math.PI / 180) * nR); nStartDY = nCY + (Math.sin(nHues * Math.PI / 180) * nR); nStopDX = nCX + (Math.cos((nHues + 2) * Math.PI / 180) * nR); nStopDY = nCY + (Math.sin((nHues + 2) * Math.PI / 180) * nR); ctx.save(); ctx.beginPath(); ctx.moveTo(nStartCX, nStartCY); ctx.lineTo(nStartDX, nStartDY); ctx.lineTo(nStopDX, nStopDY); ctx.lineTo(nStopCX, nStopCY); ctx.fillStyle = 'hsl(' + nHues + ', 100%, 50%)'; ctx.fill(); ctx.closePath(); } ctx.restore();
/************* * CSS * *************/ .rgb { border-radius: 50%; position: relative; background: radial-gradient(ellipse at center, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 56%, rgba(255, 255, 255, 0) 57%, rgba(255, 255, 255, 0) 100%), /* white hole */ linear-gradient(10deg, rgb(255, 0, 0) 0%, rgba(255, 0, 0, 0) 40%), /* red */ linear-gradient(70deg, rgb(255, 255, 0) 0%, rgba(255, 255, 0, 0) 50%), /* yeloow */ linear-gradient(130deg, rgb(0, 255, 0) 0%, rgba( 0, 255, 0, 0) 45%), /* gren */ linear-gradient(190deg, rgb(0, 255, 255) 0%, rgba(0, 255, 255, 0) 50%), /* cyan */ linear-gradient(250deg, rgb(0, 0, 255) 0%, rgba(0, 0, 255, 0) 50%), /* blue */ linear-gradient(310deg, rgb(255, 0, 255) 0%, rgba(255, 0, 255, 0) 50%)/* magenta */ ; } canvas, svg, div { display: inline-block; height: 180px; width: 180px; } pre { top: 55px; position: absolute; font: bold 26px monospace; text-shadow: 1px 3px 3px rgba(0, 0, 0, 0.75); }
<svg viewBox="0 0 100 100" id='svg'></svg> <canvas id="cnv" width="180" height="180"></canvas> <div class="rgb"></div> <pre> SVG Canvas CSS</pre>