当前位置: 移动技术网 > IT编程>网页制作>Html5 > Html5学习------canvas绘制径向渐变图形

Html5学习------canvas绘制径向渐变图形

2018年03月07日  | 移动技术网IT编程  | 我要评论

初中生作文范文,张实杰,强心脏120110

[html] 
<!DOCTYPE HTML> 
<html> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
        <title>HTML5绘制径向渐变图形</title> 
        <script type="text/javascript"> 
        window.onload = function() 
        { 
                        var canvas = document.getElementById("canvas"); 
                        var context = canvas.getContext("2d"); 
                        var g1 = context.createRadialGradient(400, 0, 0, 400, 0, 400); 
                        g1.addColorStop(0.1, "rgb(255, 255, 0)"); 
                        g1.addColorStop(0.3, "rgb(255, 0, 255)"); 
                        g1.addColorStop(1, "rgb(0, 255, 255)"); 
                        context.fillStyle = g1; 
                        context.fillRect(0, 0, 400, 350); 
                        var g2 = context.createRadialGradient(250, 250, 0, 250, 250, 300); 
                        g2.addColorStop(0.1, "rgba(255, 0, 0, 0.5)"); 
                        g2.addColorStop(0.7, "rgba(255, 255, 0, 0.5)"); 
                        g2.addColorStop(1, "rgba(0, 0, 255, 0.5)"); 
                        for(var i = 0; i < 10; i++) 
                        { 
                                context.beginPath(); 
                                context.fillStyle = g2; 
                                context.arc(i * 25, i * 25, i * 10, 0, Math.PI * 2, true); 
                                context.closePath(); 
                                context.fill(); 
                        } 
                } 
        </script> 
    </head> 
 
    <body> 
            <canvas id="canvas" width="600" height="400"></canvas> 
    </body> 
</html> 

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网