星空网 > 软件开发 > 网页设计

HTML5填充颜色的fillStyle测试

效果:
http://hovertree.com/texiao/html5/canvas/1/

代码:

 1 <html> 2 <head> 3 <meta http-equiv="Content-Type" content="text/html;charset=gbk" />  4 <script type="text/javascript"> 5 function draw(){ 6 var ctx = document.getElementById('canvas').getContext('2d'); 7 for (var i=0;i<6;i++){  8 for (var j=0;j<6;j++){  9 ctx.fillStyle = 'rgb(' + Math.floor(255-42.5*i) + ',' +Math.floor(255-42.5*j) + ',0)';10 ctx.fillRect(j*25,i*25,25,25);11 }12 }13 }14 </script>15 <title>测试fillStyle - 何问起</title>16 <meta name="description" content="何问起,hovertree.com" /><meta name="keywords" content=" hovertree.com,何问起" />17 18 </head>19 <body onload="draw();" > 20 <canvas id="canvas" width="400" height="300">21 </canvas>22 <a href="http://hovertree.com/h/bjaf/a064shrh.htm">何问起</a>23 </body>24 </html>

更多:http://www.cnblogs.com/roucheng/p/texiao.html

http://hovertree.com/texiao/html5/canvas/2/

如果我们想要给图形上色,有两个重要的属性可以做到:fillStyle 和 strokeStyle。

fillStyle = color
strokeStyle = color

strokeStyle 是用于设置图形轮廓的颜色,而 fillStyle 用于设置填充颜色。color 可以是表示 CSS 颜色值的字符串,渐变对象或者图案对象。默认情况下,线条和填充颜色都是黑色(CSS 颜色值 #000000)。

下面的例子都表示同一种颜色。
// 这些 fillStyle 的值均为 '橙色'
ctx.fillStyle = "orange"; 
ctx.fillStyle = "#FFA500";
ctx.fillStyle = "rgb(255,165,0)";
ctx.fillStyle = "rgba(255,165,0,1)";

注意: 目前 Gecko 引擎并没有提供对所有的 CSS 3 颜色值的支持。例如,hsl(100%,25%,0) 或者 rgb(0,100%,0) 都不可用。

注意: 一旦您设置了 strokeStyle 或者 fillStyle 的值,那么这个新值就会成为新绘制的图形的默认值。如果你要给每个图形上不同的颜色,你需要重新设置 fillStyle 或 strokeStyle 的值。

http://hovertree.com/texiao/html5/canvas/3/


Canvas填充样式fillStyle
说明
在本示例里,我会再度用两层for循环来绘制方格阵列,每个方格不同的颜色。结果如图,但实现所用的代码却没那么绚丽。我用了两个变量i和j 为每一个方格产生唯一的RGB色彩值,其中仅修改红色和绿色通道的值,而保持蓝色通道的值不变。你可以通过修改这些颜色通道的值来产生各种各样的色板。通过增加渐变的频率,你还可以绘制出类似 Photoshop 里面的那样的调色板。

 




原标题:HTML5填充颜色的fillStyle测试

关键词:HTML

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

化妆用品:https://www.goluckyvip.com/tag/13266.html
派对用品:https://www.goluckyvip.com/tag/13267.html
法国队:https://www.goluckyvip.com/tag/13268.html
中国足球:https://www.goluckyvip.com/tag/13269.html
LD费用:https://www.goluckyvip.com/tag/13270.html
周秒杀:https://www.goluckyvip.com/tag/13271.html
长治婚庆女司仪和主持人:https://www.vstour.cn/a/366176.html
北京丰台区水上乐园哪家好玩?:https://www.vstour.cn/a/366177.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流