HTML5 Canvas 绘制英国国旗
代码:
<!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 绘制英国国旗的更多相关文章
- HTML5 Canvas 绘制澳大利亚国旗
代码: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type ...
- HTML5 Canvas 绘制新西兰国旗
代码: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type ...
- 学习笔记:HTML5 Canvas绘制简单图形
HTML5 Canvas绘制简单图形 1.添加Canvas标签,添加id供js操作. <canvas id="mycanvas" height="700" ...
- 使用 HTML5 Canvas 绘制出惊艳的水滴效果
HTML5 在不久前正式成为推荐标准,标志着全新的 Web 时代已经来临.在众多 HTML5 特性中,Canvas 元素用于在网页上绘制图形,该元素标签强大之处在于可以直接在 HTML 上进行图形操作 ...
- 使用html5 canvas绘制图片
注意:本文属于<html5 Canvas绘制图形入门详解>系列文章中的一部分.如果你是html5初学者,仅仅阅读本文,可能无法较深入的理解canvas,甚至无法顺畅地通读本文.请点击上述链 ...
- 使用html5 canvas绘制圆形或弧线
注意:本文属于<html5 Canvas绘制图形入门详解>系列文章中的一部分.如果你是html5初学者,仅仅阅读本文,可能无法较深入的理解canvas,甚至无法顺畅地通读本文.请点击上述链 ...
- html5 Canvas绘制图形入门详解
html5,这个应该就不需要多作介绍了,只要是开发人员应该都不会陌生.html5是「新兴」的网页技术标准,目前,除IE8及其以下版本的IE浏览器之外,几乎所有主流浏览器(FireFox.Chrome. ...
- 解决html5 canvas 绘制字体、图片与图形模糊问题
html5 canvas 绘制字体.图片与图形模糊问题 发生情况 多出现在高dpi设备,这意味着每平方英寸有更多的像素,如手机,平板电脑.当然很多高端台式电脑也有高分辨率高dpi的显示器. canva ...
- 使用html5 Canvas绘制线条(直线、折线等)
使用html5 Canvas绘制直线所需的CanvasRenderingContext2D对象的主要属性和方法(有"()"者为方法)如下: 属性或方法 基本描述 strokeSty ...
随机推荐
- 201621123034 《Java程序设计》第4周学习总结
Week04-面向对象设计与继承 1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 答:对象.重载.继承.多态 1.2 尝试使用思维导图将这些关键词组织起来.注:思维导图一般不需 ...
- CodeForces Round #521 (Div.3) A. Frog Jumping
http://codeforces.com/contest/1077/problem/A A frog is currently at the point 00 on a coordinate axi ...
- Win10开启IIS
1.win+r control 2.程序
- [HAOI2018][bzoj5306] 染色 [容斥原理+NTT]
题面 传送门 思路 这道题的核心在于"恰好有$k$种颜色占了恰好$s$个格子" 这些"恰好",引导我们去思考,怎么求出总的方案数呢? 分开考虑 考虑把恰好有$s ...
- elasticsearch备份与恢复4_使用ES-Hadoop将ES中的索引数据写入HDFS中
背景知识见链接:elasticsearch备份与恢复3_使用ES-Hadoop将HDFS数据写入Elasticsearch中 项目参考<Elasticsearch集成Hadoop最佳实践> ...
- windows 批处理删除指定目录下 指定类型 指定天数之前文件
删除D:\test下5天前所有文件,如下: @echo offset SrcDir=D:\testset DaysAgo=5forfiles /p %SrcDir% /s /m *.* /d -%Da ...
- Flask request获取参数问题
https://www.jianshu.com/p/ecd97b1c21c1 https://blog.csdn.net/lovebyz/article/details/52244330 https: ...
- nodejs+express+mongodb搭建博客
https://github.com/lanleilin/sayHelloBlog 是可以运行的 https://github.com/lanleilin/sayHelloBlog 文件结构如下: c ...
- python(7)-- 文件I/O
1 打印到屏幕:print 语句.你可以给它传递零个或多个用逗号隔开的表达式.此函数把你传递的表达式转换成一个字符串表达式,并将结果写到标准输出,eg:print "Python 是一个非常 ...
- 遍历简单XML节点
原文发布时间为:2009-08-26 -- 来源于本人的百度文章 [由搬家工具导入] <?xml version="1.0" encoding="gb2312&qu ...