1. 程式人生 > >html canvas 化一個彩虹

html canvas 化一個彩虹

</<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
123
<canvas id="canvas">該瀏覽器不支援canvas,請更換瀏覽器後檢視</canvas>
<script>
    window.onload=function () {
        var canvas = document.getElementById('canvas');
        var a = 1000;
        var a2 = a*2;
        var aa2 = a/2;
        canvas.width=a2;
        canvas.height=a;
        var sc = canvas.getContext("2d");
        sc.lineWidth = 5;
        sc.strokeStyle = "#00ffff";
        for(var i = 300;i<=aa2;i+=100){

            sc.beginPath();
            sc.arc(a,a,i,0,0.5*Math.PI,true);
            sc.stroke();

        }

    }
</script>
</body>
</html>

這也不能叫彩虹,叫橋洞吧