代码:
<!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <head><title>澳大利亚国旗</title></head><body onload="draw()"><canvas id="myCanvus" width="480px" height="240px" style="border:1px dashed black;">出现文字表示你的浏览器不支持HTML5</canvas></body> </html> <script type="text/javascript"> <!--function draw(){var canvasElementById("myCanvus");var canvasWidth=240;var canvasHeight=120;var contextContext("2d");context.fillStyle = "white";context.fillRect(0, 0, canvasWidth*2, canvasHeight*2);// 先画角上蓝色方块 context.fillStyle = "blue";context.fillRect(0, 0, 100, 40);context.fillRect(140, 0, 100, 40);context.fillRect(0, 80, 100, 40);context.fillRect(140, 80, 100, 40);// 用旋转的白色长条去盖上蓝色方块,覆盖完出现八个三角块 context.save();anslate(120,60);ate(getRad(26.56));context.fillStyle = "white";context.fillRect(-300, -12, 600, 24);store();context.save();anslate(120,60);ate(getRad(-26.56));context.fillStyle = "white";context.fillRect(-300, -12, 600, 24);store();// 四个红条 context.save();anslate(120,60);ate(getRad(26.56));context.fillStyle = "red";context.fillRect(-300, 0, 300, 8);store();context.save();anslate(120,60);ate(getRad(-26.56));context.fillStyle = "red";context.fillRect(-300, 0, 300, 8);store();context.save();anslate(120,60);ate(getRad(-26.56));context.fillStyle = "red";context.fillRect(0, -8, 300, 8);store();context.save();anslate(120,60);ate(getRad(26.56));context.fillStyle = "red";context.fillRect(0, -8, 300, 8);store();// 用一个白条去把中间部分的多余红边去掉 context.fillStyle = "white";context.fillRect(0, 40, 240, 40);// 画中间的红色十字 context.fillStyle = "red";context.fillRect(0, 48, 240, 24);context.fillRect(108, 0, 24, 120);// 用蓝色方块覆盖掉多出来的部分 context.fillStyle = "blue";context.fillRect(0, canvasHeight, canvasWidth*2, canvasHeight);context.fillRect(canvasWidth, 0, canvasWidth, canvasHeight);// 逐个画七芒星 context.save();drawSevenStar(context,120,180,20,"white")store();context.save();drawSevenStar(context,360,45,15,"white")store();context.save();drawSevenStar(context,360,200,15,"white")store();context.save();drawSevenStar(context,300,110,15,"white")store();context.save();drawSevenStar(context,420,100,15,"white")store();// 最后一颗五角星 context.save();drawFiveStar(context,390,140,10,"white")store();}function drawSevenStar(context,x,y,r,color){context.strokeStyle = color;context.fillStyle = anslate(x,y);for(var i=0;i<7;i++){context.save();ate(getRad(360/7*i)); context.beginPath();veTo(0, -r);context.lineTo(-Math.tan(getRad(12))*r, 0);context.lineTo(Math.tan(getRad(12))*r,0);context.lineTo(0, -r);context.fill();context.stroke();context.closePath(); store();} }function drawFiveStar(context,x,y,r,color){anslate(x-r,y-r);context.strokeStyle = color;context.fillStyle = color;context.beginPath();veTo(r, 0);context.lineTo(rs(Math.PI*3/10)*r, r+Math.sin(Math.PI*3/10)*r);context.s(Math.PI*1/10)*r, r-Math.sin(Math.PI*1/10)*r);context.lineTo(rs(Math.PI*1/10)*r, r-Math.sin(Math.PI*1/10)*r);context.s(Math.PI*3/10)*r, r+Math.sin(Math.PI*3/10)*r);context.lineTo(r, 0);context.fill();context.stroke();context.closePath(); }function getRad(degree){return degree/180*Math.PI; } //--> </script>
到这里英美加澳新的国旗都全了。
本文发布于:2024-01-31 16:17:26,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170668904629799.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |