canvas教程

玩转html5canvas画图(6)

字号+ 作者:H5之家 来源:H5之家 2015-09-07 13:15 我要评论( )

View Code 1 function draw10(id) { 2 var canvas = document.getElementById(id); 3 if (canvas == null ) { ; 5 } 6 var context = canvas.getContext("2d" ); 7 var oprtns = new Array( 8 "source-over" , 9 "d

View Code

1 function draw10(id) { 2 var canvas = document.getElementById(id); 3 if (canvas == null) { ; 5 } 6 var context = canvas.getContext("2d"); 7 var oprtns = new Array( 8 "source-over", 9 "destination-over", 10 "source-in", 11 "destination-in", 12 "source-out", 13 "destination-out", 14 "source-atop", 15 "destination-atop", 16 "lighter", 17 "xor", 18 "copy" 19 ); interal = setInterval(function () { 24 if (i == 10) { 25 i=0; 26 } 27 else { 28 i++; 29 } context.fillStyle = "blue"; 32 context.fillRect(10, 10, 60, 60); context.globalCompositeOperation = oprtns[i]; context.beginPath(); 37 context.fillStyle = "red"; 38 context.arc(60, 60, 30, 0, Math.PI * 2, false); 39 context.fill(); 40 }, 1000); 41 42 }

 结果是动态的切换各种组合

 

给图形绘制阴影

    context.shadowOffsetX :阴影的横向位移量(默认值为0)
    context.shadowOffsetY :阴影的纵向位移量(默认值为0)
    context.shadowColor :阴影的颜色
    context.shadowBlur :阴影的模糊范围(值越大越模糊)

先来个简单的例子

View Code

1 function draw27(id) { 2 var canvas = document.getElementById(id); 3 if (canvas == null) ; 5 var context = canvas.getContext('2d'); 6 context.shadowOffsetX = 10; 7 context.shadowOffsetY = 10; 8 context.shadowColor = 'rgba(100,100,100,0.5)'; 9 context.shadowBlur = 1.5; 10 context.fillStyle = 'rgba(255,0,0,0.5)'; 11 context.fillRect(100, 100, 200, 100); 12 }

 再来个书本上的五角星的例子

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • html5canvas核心技术图形、动画与游戏开发源码

    html5canvas核心技术图形、动画与游戏开发源码

    2017-05-02 17:42

  • HTML5 canvas 作画板画图 可以做电子白板

    HTML5 canvas 作画板画图 可以做电子白板

    2017-04-27 12:02

  • Android画图学习免费下载

    Android画图学习免费下载

    2017-04-27 11:01

  • CAD迷你画图 V2017R4 官方版下载

    CAD迷你画图 V2017R4 官方版下载

    2017-04-27 10:03

网友点评
i