×

canvas小应用:七彩太阳发光效果

作者:Terry2021.06.01来源:Web前端之家浏览:6320评论:0
关键词:canvas

canvas小应用:七彩太阳发光效果。废话不多说,直接上代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>canvas小应用:七彩太阳发光效果 | Web前端之家www.jiangweishan.com</title>
    <script>
        window.onload=function(){
            var canvas=document.getElementById('canvas');
            var cx=canvas.getContext("2d");
            cx.fillStyle='pink';
            cx.strokeStyle='pink';
            for(var i=0;i<10;i++){
                var g=cx.createLinearGradient(0,0,290,290);
                g.addColorStop(0,'rgba(255,0,0,1)');
                g.addColorStop(0.1,'rgba(255,0,0,0.5)');
                g.addColorStop(0.2,'rgba(255,165,0,0.4)');
                g.addColorStop(0.4,'rgba(205,255,0,0.5)');
                g.addColorStop(0.6,'rgba(230,145,0,0.5)');
                g.addColorStop(0.8,'rgba(0,127,255,0.5)');
                g.addColorStop(0.9,'rgba(100,200,205,0.9)');
                g.addColorStop(1,'rgba(0,255,255,0.5)');;
                cx.fillStyle=g;
                cx.beginPath();
                cx.arc(i*25,i*25,i*10,0,Math.PI*2,true);
                cx.closePath();
                cx.fill();
            }
        }
    </script>
</head>
<body>
    <canvas id="canvas" width="600px" height="600px" style="background-color: #ccc;"></canvas>
    
</body>
</html>

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/qianduan20210601a3.html

网友评论文明上网理性发言 已有0人参与

发表评论: