Html5系列(二十二)画布(阴影)
来源:互联网 发布:java底层书籍 编辑:程序博客网 时间:2024/05/17 01:47
案例1:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <script> function draw(){ var c=document.getElementById("myCanvas"); var cxt= c.getContext("2d"); cxt.fillStyle="#eeeeff"; cxt.fillRect(0,0,400,320); cxt.shadowOffsetX=10; cxt.shadowOffsetY=10; cxt.shadowColor='rgba(100,100,100,0.5)'; cxt.shadowBlur=7.5; cxt.translate(60,60); for( var i=0;i<6;i++) { cxt.translate(50,50); cxt.scale(0.8,0.8); cxt.rotate(Math.PI/10); createStar(cxt); cxt.fill(); } function createStar(cxt){ var n=0; var dx=0; var dy=0; var s=50; cxt.beginPath(); cxt.fillStyle='rgba(255,0,0,0.5)'; var x=Math.sin(0); var y=Math.cos(0); var dig=Math.PI/5*4; for(var i=0;i<5;i++) { var x=Math.sin(i*dig); var y=Math.cos(i*dig); cxt.lineTo(dx+x*s,dy+y*s); } cxt.closePath(); } } </script></head><body onload="draw()"><canvas id="myCanvas" width="450" height="350" style="border: 1px solid #dddddd">您的浏览器不支持</canvas></body></html>效果图:
注释:(1)shadowOffsetX--阴影的横向位移量,即图形横向方向移动的距离; shadowOffsetY--阴影的纵向位移量,即纵向方向移动的距离; shadowColor--阴影的颜色; shadowBlur--阴影的模糊范围,该属性是可选的。如果不希望阴影的边缘太清晰,需要将阴影的边缘模糊化时可以使用该属性。属性值一般设定在0-10之间;
0 0
- Html5系列(二十二)画布(阴影)
- Html5系列(二十五)画布(图像)
- HTML5系列(二十一)画布(变形)
- HTML5 canvas画布(二)
- 使用HTML5画布(canvas)生成阴影效果
- HTML5之画布(canvas)(二)
- HTML5边玩边学(1):画布
- HTML5边玩边学(1):画布
- HTML5 canvas画布(一)
- HTML5 canvas画布(三)
- HTML5 canvas画布(四)
- HTML5 canvas画布(五)
- HTML5 canvas画布(六)
- HTML5 Canvas进阶(二):模式,组合,阴影,状态,变形
- Redis系列~Sentinel使用(二十二)
- HTML5画布MeteorCharts系列样式
- HTML5学习记录二:画布
- HTML5之画布(canvas)(一)
- javascript的原型和构造函数
- Html5系列(二十) 学习之 Html5功能判断插件 Modernizr
- MFC读写文件CStdioFile(除此之外还有CFile,CArchive,CMemFile等等)
- codeforces535B:Tavas and SaDDas
- MapReduce实现自定义二次排序
- Html5系列(二十二)画布(阴影)
- HTML5系列(二十一)画布(变形)
- Ext4 关于表单中fieldset错位的问题
- Html5系列(十九) canvas 弧形描边渐变
- Heap sort
- CStringArray
- codeforces535C:Tavas and Karafs(二分)
- C-回文[顺序表]
- LeetCode 104 Maximum Depth of Binary Tree