代码:

<!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 canvas=document.getElementById("myCanvus");
        var canvasWidth=240;
        var canvasHeight=120;

        var context=canvas.getContext("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();
        context.translate(120,60);
        context.rotate(getRad(26.56));
        context.fillStyle = "white";
        context.fillRect(-300, -12, 600, 24);
        context.restore();

        context.save();
        context.translate(120,60);
        context.rotate(getRad(-26.56));
        context.fillStyle = "white";
        context.fillRect(-300, -12, 600, 24);
        context.restore();

        // 四个红条
        context.save();
        context.translate(120,60);
        context.rotate(getRad(26.56));
        context.fillStyle = "red";
        context.fillRect(-300, 0, 300, 8);
        context.restore();

        context.save();
        context.translate(120,60);
        context.rotate(getRad(-26.56));
        context.fillStyle = "red";
        context.fillRect(-300, 0, 300, 8);
        context.restore();

        context.save();
        context.translate(120,60);
        context.rotate(getRad(-26.56));
        context.fillStyle = "red";
        context.fillRect(0, -8, 300, 8);
        context.restore();

        context.save();
        context.translate(120,60);
        context.rotate(getRad(26.56));
        context.fillStyle = "red";
        context.fillRect(0, -8, 300, 8);
        context.restore();

        // 用一个白条去把中间部分的多余红边去掉
        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")
        context.restore();

        context.save();
        drawSevenStar(context,360,45,15,"white")
        context.restore();

        context.save();
        drawSevenStar(context,360,200,15,"white")
        context.restore();

        context.save();
        drawSevenStar(context,300,110,15,"white")
        context.restore();

        context.save();
        drawSevenStar(context,420,100,15,"white")
        context.restore();

        // 最后一颗五角星
        context.save();
        drawFiveStar(context,390,140,10,"white")
        context.restore();

    }

    function drawSevenStar(context,x,y,r,color){
        context.strokeStyle = color;
        context.fillStyle = color;

        context.translate(x,y);

        for(var i=0;i<7;i++){
            context.save();
            context.rotate(getRad(360/7*i));

            context.beginPath();
            context.moveTo(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();
            context.restore();
        }
    }

    function drawFiveStar(context,x,y,r,color){
        context.translate(x-r,y-r);
        context.strokeStyle = color;
        context.fillStyle = color;
        context.beginPath();
        context.moveTo(r, 0);
        context.lineTo(r+Math.cos(Math.PI*3/10)*r, r+Math.sin(Math.PI*3/10)*r);
        context.lineTo(r-Math.cos(Math.PI*1/10)*r, r-Math.sin(Math.PI*1/10)*r);
        context.lineTo(r+Math.cos(Math.PI*1/10)*r, r-Math.sin(Math.PI*1/10)*r);
        context.lineTo(r-Math.cos(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>

到这里英美加澳新的国旗都全了。

HTML5 Canvas 绘制澳大利亚国旗的更多相关文章

  1. HTML5 Canvas 绘制新西兰国旗

    代码: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type ...

  2. HTML5 Canvas 绘制英国国旗

    代码: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type ...

  3. 学习笔记:HTML5 Canvas绘制简单图形

    HTML5 Canvas绘制简单图形 1.添加Canvas标签,添加id供js操作. <canvas id="mycanvas" height="700" ...

  4. 使用 HTML5 Canvas 绘制出惊艳的水滴效果

    HTML5 在不久前正式成为推荐标准,标志着全新的 Web 时代已经来临.在众多 HTML5 特性中,Canvas 元素用于在网页上绘制图形,该元素标签强大之处在于可以直接在 HTML 上进行图形操作 ...

  5. 使用html5 canvas绘制图片

    注意:本文属于<html5 Canvas绘制图形入门详解>系列文章中的一部分.如果你是html5初学者,仅仅阅读本文,可能无法较深入的理解canvas,甚至无法顺畅地通读本文.请点击上述链 ...

  6. 使用html5 canvas绘制圆形或弧线

    注意:本文属于<html5 Canvas绘制图形入门详解>系列文章中的一部分.如果你是html5初学者,仅仅阅读本文,可能无法较深入的理解canvas,甚至无法顺畅地通读本文.请点击上述链 ...

  7. html5 Canvas绘制图形入门详解

    html5,这个应该就不需要多作介绍了,只要是开发人员应该都不会陌生.html5是「新兴」的网页技术标准,目前,除IE8及其以下版本的IE浏览器之外,几乎所有主流浏览器(FireFox.Chrome. ...

  8. 解决html5 canvas 绘制字体、图片与图形模糊问题

    html5 canvas 绘制字体.图片与图形模糊问题 发生情况 多出现在高dpi设备,这意味着每平方英寸有更多的像素,如手机,平板电脑.当然很多高端台式电脑也有高分辨率高dpi的显示器. canva ...

  9. 使用html5 Canvas绘制线条(直线、折线等)

    使用html5 Canvas绘制直线所需的CanvasRenderingContext2D对象的主要属性和方法(有"()"者为方法)如下: 属性或方法 基本描述 strokeSty ...

随机推荐

  1. idea热部署设置(复制)

    提出问题 IntelliJ IDEA工具如何设置热部署??? 解决问题 我的IDEA的版本是:IntelliJ IDEA 14.0.2 第一步:打开tomcat配置 这里写图片描述 第二步: 这里写图 ...

  2. Groovy安装

    进入Groovy的官网下载安装SDKMAN() 以下是官网的下载方法(http://www.groovy-lang.org/download.html) This tool makes install ...

  3. BZOJ 1877:[SDOI2009]晨跑(最小费用最大流)

    晨跑DescriptionElaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个 ...

  4. 【bzoj2431】[HAOI2009]逆序对数列 dp

    题目描述 对于一个数列{ai},如果有i<j且ai>aj,那么我们称ai与aj为一对逆序对数.若对于任意一个由1~n自然数组成的 数列,可以很容易求出有多少个逆序对数.那么逆序对数为k的这 ...

  5. ZOJ 3781 Paint the Grid Reloaded(BFS+缩点思想)

    Paint the Grid Reloaded Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N rows ...

  6. xml的并发

    网站整站的缓存方式都是依靠的DataSet的ReadXml和WriteXml的方式实现的,这种方式在访问量不是很大的网站中是一点问题都没有的(最大可承受的日IP估计在8000-15000左右),但是当 ...

  7. HTML+CSS 滚动条样式自定义 - 适用于 div,iframe, html 等

    友言:这两天被滚动条整的无与伦比,在此做下总结: 首先自定义浏览器滚动条的实现原理:计算浏览器滚动条的高度,层级1的高度与滚动条的总高度是一样的,通过相似比例计算: 浏览器滚动条总高度 :滚动条高度 ...

  8. 【SPOJ61】Brackets(线段树)

    题意:给出一个括号序列,要求维护两种操作: 1.将第x位上的括号取反 2.查询当前整个括号序列是否匹配 n<=3e4 思路:线段树维护区间内没有匹配的左右括号数量 pushup时t[p].r=t ...

  9. 【DirectX SDK Extra】提示缺少Qedit.h问题 (转)

    原文转自 http://blog.csdn.net/joeblackzqq/article/details/10944005 DirectX 9.0 SDK 开发包以及扩展包下载(February 2 ...

  10. 将一个二叉树左右翻转(Java 版)

    public class Solution { public TreeNode invertTree(TreeNode root) { if (root == null) { return null; ...