PHP前端开发

canvas绘制奥运五环代码分享

百变鹏仔 2个月前 (10-18) #H5教程
文章标签 奥运

运行效果:

nbsp;html&gt;<canvas>A drawing of someing!</canvas>    <script>var drawing = document.getElementById(&#39;drawing&#39;);if(drawing.getContext) {//绘制奥运五环,画圆var context = drawing.getContext(&#39;2d&#39;);            context.lineWidth = 7;            context.strokeStyle = &#39;#0180C3&#39;;            context.beginPath();            context.arc(70, 70, 40, 0, 2*Math.PI, false);            context.stroke();            context.strokeStyle = &#39;#000&#39;;            context.beginPath();            context.arc(160, 70, 40, 0, 2*Math.PI, false);            context.stroke();            context.strokeStyle = &#39;#BF0628&#39;;            context.beginPath();            context.arc(250, 70, 40, 0, 2*Math.PI, false);            context.stroke();            context.strokeStyle = &#39;#EBC41F&#39;;            context.beginPath();            context.arc(115, 110, 40, 0, 2*Math.PI, false);            context.stroke();            context.strokeStyle = &#39;#198E4A&#39;;            context.beginPath();            context.arc(205, 110, 40, 0, 2*Math.PI, false);            context.stroke();//环环相扣,画弧(实现相关圆弧的覆盖)context.strokeStyle = &#39;#0180C3&#39;;            context.beginPath();            context.arc(70, 70, 40, 1.9*Math.PI, 2.1*Math.PI, false);            context.stroke();            context.strokeStyle = &#39;#000&#39;;            context.beginPath();            context.arc(160, 70, 40, 1.9*Math.PI, 2.1*Math.PI, false);            context.stroke();            context.beginPath();            context.arc(160, 70, 40, 0.5*Math.PI, 0.7*Math.PI, false);            context.stroke();            context.strokeStyle = &#39;#BF0628&#39;;            context.beginPath();            context.arc(250, 70, 40, 0.5*Math.PI, 0.7*Math.PI, false);            context.stroke();        }</script>