代码:

<!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="240px" height="120px" 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, canvasHeight);

        // 先画角上蓝色方块
        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);
    }

    function getRad(degree){
        return degree/180*Math.PI;
    }
//-->
</script>

关于英国国旗怎么画,请参考https://jingyan.baidu.com/article/46650658c93d6cf548e5f877.html

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. java简易DVD影片管理系统—面向对象

    public class DvdSet { String name [] =new String[15]; // DVD电影名称 String date [] =new String[15]; //D ...

  2. location.origin兼容

    if (!window.location.origin) { window.location.origin = window.location.protocol + "//" + ...

  3. CodeChef Counting on a directed graph

    Counting on a directed graph Problem Code: GRAPHCNT All submissions for this problem are available. ...

  4. 子Repeater获取父级Repeater绑定项的值

    原文发布时间为:2010-12-27 -- 来源于本人的百度文章 [由搬家工具导入] 1.子级Repeater中绑定父级的某个字段: <%# DataBinder.Eval((Container ...

  5. loj 6278 6279 数列分块入门 2 3

    参考:「分块」数列分块入门1 – 9 by hzwer 2 Description 给出一个长为\(n\)的数列,以及\(n\)个操作,操作涉及区间加法,询问区间内小于某个值\(x\)的元素个数. 思 ...

  6. android基本控件学习-----SeekBar&RatingBar

    SeekBar(拖动条)和RatingBar(星级评分条)讲解 一.SeekBar(拖动条) (1)拖动条简单理解就是可以拖动的线,这个对我们来讲很常见,比如视频播放或者音乐播放我们拖动播放的进度,下 ...

  7. Android大神 博客

    https://github.com/yeungeek/awesome-android-person Android大神 受Trinea的开源项目的启发和参考,也准备列一列Android圈里的大神们. ...

  8. Pacman常用命令

    Pacman是Arch Linux 的包管理器.它将一个简单的二进制包格式和易用的构建系统结合了起来.不管软件包是来自官方的 Arch 库还是用户自己创建,Pacman 都能方便得管理. 更新系统 在 ...

  9. EOJ 3.30 A. 打工时不可能打工的【贪心】

    [链接]:https://acm.ecnu.edu.cn/contest/59/problem/A/ A. 打工时不可能打工的 Time limit per test: 2.0 seconds Mem ...

  10. Ueditor 在线编辑器使用

    ueditor在线编辑器插件 地址:http://ueditor.baidu.com/website/ 试用体验: 帮助文档:http://fex.baidu.com/ueditor/   实操 引入 ...