canvas教程

HTML5 Canvas 学习笔记(canvas绘制线条、矩形、多边形、圆、自

字号+ 作者:H5之家 来源:H5之家 2017-09-30 15:02 我要评论( )

1 function draw5(id) { 2 var canvas = document.getElementById(id); 3 if (canvas == null ) ; context = canvas.getContext("2d" ); context.fillStyle = "#EEEEFF" ; 10 context.fillRect(0, 0, 400, 300 ); 11 12 context.fillStyle = "rgba(255,0,0,0

1 function draw5(id) { 2 var canvas = document.getElementById(id); 3 if (canvas == null) ; context = canvas.getContext("2d"); context.fillStyle = "#EEEEFF"; 10 context.fillRect(0, 0, 400, 300); 11 12 context.fillStyle = "rgba(255,0,0,0.1)"; context.translate(100, 100); 15 context.scale(0.5, 0.5); 16 context.rotate(Math.PI / 4); 17 context.fillRect(0, 0, 100, 100); context.restore(); context.save(); context.fillStyle = "rgba(255,0,0,0.2)"; context.translate(100, 100); 25 context.rotate(Math.PI / 4); 26 context.scale(0.5, 0.5); 27 context.fillRect(0, 0, 100, 100); context.save(); context.fillStyle = "rgba(255,0,0,0.3)"; context.scale(0.5, 0.5); 34 context.translate(100, 100); 35 context.rotate(Math.PI / 4); 36 context.fillRect(0, 0, 100, 100); context.save(); context.fillStyle = "rgba(255,0,0,0.4)"; context.scale(0.5, 0.5); 43 context.rotate(Math.PI / 4); 44 context.translate(100, 100); 45 context.fillRect(0, 0, 100, 100); context.save(); context.fillStyle = "rgba(255,0,0,0.5)"; context.rotate(Math.PI / 4); 52 context.translate(100, 100); 53 context.scale(0.5, 0.5); 54 context.fillRect(0, 0, 100, 100); context.save(); context.fillStyle = "rgba(255,0,0,1)"; context.rotate(Math.PI / 4); 61 context.scale(0.5, 0.5); 62 context.translate(100, 100); 63 context.fillRect(0, 0, 100, 100); }

 

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

相关文章
  • 在canvas类里调用textbox

    在canvas类里调用textbox

    2017-09-29 14:02

  • HTML5中的Canvas结合公式绘制粒子运动的教程

    HTML5中的Canvas结合公式绘制粒子运动的教程

    2017-09-29 14:01

  • HTML5 Canvas快速入门学习教程

    HTML5 Canvas快速入门学习教程

    2017-09-29 12:03

  • Canvas 绘制八大行星

    Canvas 绘制八大行星

    2017-09-29 12:01

网友点评