canvas教程

HTML5 Canvas 画纸飞机组件

字号+ 作者:H5之家 来源:H5之家 2017-08-04 09:00 我要评论( )

HTML5 Canvas 画纸飞机组件,纸飞机模拟一个物体在规定设计轴线偏离方位。1 //三角形2 function DrawTriangle(canvas, A, B, C) {3 //画个三角形,A、B、C是顶点4

正文

纸飞机模拟一个物体在规定设计轴线偏离方位。

DrawTriangle(canvas, A, B, C) { (canvas) { 5 moveTo(A[0], A[1]); 6 lineTo(B[0], B[1]); 7 lineTo(C[0], C[1]); 8 lineTo(A[0], A[1]); 9 } 10 } DrawDarts(canvas, headx, heady, footx, footy) { 16 var c = document.getElementById(canvas); 17 var cxt = c.getContext("2d"); R = 150; headx1 = R + headx; 24 var heady1 = R - heady; footx1 = R + footx; 27 var footy1 = R - footy; footxl = R + (footx - 50); 31 var footyl = R - footy; footxr = R + (footx + 50); 35 var footyr = R - footy; footxu = R + footx; 39 var footyu = R - (footy - 50); footxd = R + footx; 43 var footyd = R - (footy + 50); cxt.beginPath(); 48 cxt.strokeStyle = "black"; 49 cxt.fillStyle = "#6C8D9F"; 50 var A = new Array(headx1, heady1); 51 var B = new Array(footx1, footy1); (parseInt(headx1) - parseInt(footx1) <= 0) 55 var C = new Array(footxr, footyr); C = new Array(footxl, footyl); 58 DrawTriangle(cxt, A, B, C); 59 60 cxt.fill(); 61 cxt.closePath(); 62 cxt.stroke(); cxt.beginPath(); 66 cxt.strokeStyle = "black"; 67 cxt.fillStyle = "#6C8D9F"; 68 var A1 = new Array(headx1, heady1); 69 var B1 = new Array(footxu, footyu); 70 var C1 = new Array(footxd, footyd); 71 DrawTriangle(cxt, A1, B1, C1); 72 cxt.fill(); 73 cxt.closePath(); 74 cxt.stroke(); 75 76 cxt.beginPath(); 77 cxt.strokeStyle = "black"; 78 cxt.fillStyle = "#6C8D9F"; 79 var A2 = new Array(headx1, heady1); 80 var B2 = new Array(footx1, footy1); 81 if (parseInt(headx1) - parseInt(footx1) <= 0) 82 var C2 = new Array(footxl, footyl); C2 = new Array(footxr, footyr); 85 DrawTriangle(cxt, A2, B2, C2); 86 cxt.fill(); 87 cxt.closePath(); 88 cxt.stroke(); 89 }

html 页面调用

HTML Canvas 画纸飞机浏览器不支持HTML5! DrawDarts()

预览效果图

效果图2:

 

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

相关文章
  • nest.js 源码

    nest.js 源码

    2017-08-01 13:06

  • Fieldset 对象

    Fieldset 对象

    2017-07-30 18:01

  • HTML5 Canvas 爆炸动画特效

    HTML5 Canvas 爆炸动画特效

    2017-07-27 11:10

  • HTML5 Canvas动态的正弦余弦波形动画效果演示

    HTML5 Canvas动态的正弦余弦波形动画效果演示

    2017-07-26 18:00

网友点评
i