Html5+JavaScript 在Canvas上绘制五星红旗,具体思路如下图所示:

绘制思路在上图中已有说明,具体代码如下:

 <script type="text/javascript">

         //绘制五角星,其中一点垂直向上,相隔的点相连,即可绘制。
function drawStar(ctx,starCenterX,starCenterY,starRadius) {
var aX = starCenterX;
var aY = starCenterY - starRadius;
var bX = starCenterX - Math.cos(18 * Math.PI / 180) * starRadius;
var bY = starCenterY - Math.sin(18 * Math.PI / 180) * starRadius;
var cX = starCenterX - Math.cos(54 * Math.PI / 180) * starRadius;
var cY = starCenterY + Math.sin(54 * Math.PI / 180) * starRadius;
var dX = starCenterX + Math.cos(54 * Math.PI / 180) * starRadius;
var dY = starCenterY + Math.sin(54 * Math.PI / 180) * starRadius;
var eX = starCenterX + Math.cos(18 * Math.PI / 180) * starRadius;
var eY = starCenterY - Math.sin(18 * Math.PI / 180) * starRadius;
ctx.beginPath();
ctx.fillStyle = "yellow";
ctx.moveTo(aX, aY);
ctx.lineTo(cX, cY);
ctx.lineTo(eX, eY);
ctx.lineTo(bX, bY);
ctx.lineTo(dX, dY);
ctx.lineTo(aX, aY);
ctx.fill();
ctx.closePath();
} window.onload = function () {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
var width = 300*1.5;
var height = 200*1.5;
var sX = 50; //其实坐标
var sY = 50; //其实坐标
var step = 10*1.5;
//绘制矩形
ctx.beginPath();
ctx.lineWidth = 1;
ctx.fillStyle = "red";
ctx.fillRect(sX, sY, width, height);
ctx.closePath();
//绘制大五角星
var bigStarCenterX = sX + 5 * step;
var bigStarCenterY = sY + 5 * step;
var bigStarRadius = (height * 3 / 10) / 2; //外接圆直径为旗高3/10,半径要再除以2
drawStar(ctx, bigStarCenterX, bigStarCenterY, bigStarRadius);
//绘制小五角星
var smallStarRadius = (height * 1 / 10) / 2; //外接圆直径为旗高1/10,半径要再除以2 var smallStarCenterX_1 = sX + 10 * step;
var smallStarCenterY_1 = sY + 2 * step;
drawStar(ctx, smallStarCenterX_1, smallStarCenterY_1, smallStarRadius);
var smallStarCenterX_2 = sX + 12 * step;
var smallStarCenterY_2 = sY + 4 * step;
drawStar(ctx, smallStarCenterX_2, smallStarCenterY_2, smallStarRadius);
var smallStarCenterX_3 = sX + 12 * step;
var smallStarCenterY_3 = sY + 7 * step;
drawStar(ctx, smallStarCenterX_3, smallStarCenterY_3, smallStarRadius);
var smallStarCenterX_4 = sX + 10 * step;
var smallStarCenterY_4 = sY + 9 * step;
drawStar(ctx, smallStarCenterX_4, smallStarCenterY_4, smallStarRadius);
};
</script>

Html5 绘制五星红旗的更多相关文章

  1. HTML5 canvas 绘制五星红旗

    这个例子并不是自己写的,在网上找的案列,仿照写的,,,自己真的公布董这些算法,看完这个例子还是有一点模糊,,, 如果谁看的比较明白,指点一下,,,多谢!!!! <!doctype html> ...

  2. Html5绘制饼图统计图

    这里要介绍的是一个jQuery插件:jquery.easysector.js Html5提供了强大的绘图API,让我们能够使用javascript轻松绘制各种图形.本文将主要讲解使用HTML5绘制饼图 ...

  3. html5绘制折线图

    html5绘制折线图详细代码 <html> <canvas id="a_canvas" width="1000" height="7 ...

  4. HTML5绘制矩形和圆形并且还有获取在这个图层内的坐标的思路和代码 - feilong_12的专栏 - 博客频道 - CSDN.NET

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  5. 用HTML5绘制的一个星空特效图

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. canvas绘制五星红旗

    代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8& ...

  7. HTML5用canvas绘制五星红旗

    在HTML5一览中,我们提到html 5被冠以很多高帽,其中最高的一顶.备受争议的就是"Flash杀手".IT评论界老喜欢用这个词了,杀手无处不在.不管是不是杀手,HTML 5引进 ...

  8. HTML5 绘制简单圆形 loading. . . .

    现在有很多的 loading 组件 什么js 等等 闲来没事就写一个 H5的 loading  有很多的Loading 是一张张图片 js 控制的  有了 canvas的 出现 你就可以体验不同之处了 ...

  9. Html5 绘制旋转的太极图

    采用Html5+JavaScript在Canvas中绘制旋转的太极图,如下图所示: 具体思路和绘制逻辑,在上图中已有说明,代码如下: <script type="text/javasc ...

随机推荐

  1. 【web maven】新建的项目 controller也有,从前台跳转后台 无法找到对应的controller

    碰上很 愣的问题: 使用maven搭建项目完成,项目页面写好,实体.Dao.Service.Controller都有了,但是指定Controller中的某个方法中一直不能从前台进入后台 原因: 没有w ...

  2. IMap 对map的功能的强化

    为了解决表单提交获得数据的方便性,我们将map的功能进行加强,表单提交的数据会自动将页面数据放入PageData对象中,当从页面获取数据时 new的时候要传request.request.getPar ...

  3. VS下运行项目时,检测到在集成的托管管道模式下不适用的 ASP.NET 设置。

    vs2012调试时默认会是集成模式,vs2012调试时怎么使用传统模式哪? 这个时候只要选中启动项目按F4,在托管管道模式里选传统模式即可!

  4. Echart地图城市用json返回格式

    用Echarts中,使用地图的series部分中展示城市如果用json返回数据的话,js不能直接用字符串使用.需要处理一下. php中的部分 json返回的数据 js中获取json信息 用ajax实现 ...

  5. 在HyperlinkButton的URL地址里附加多个参数(以http get的方式)

    1.使用 Uri(string uriString,UriType type)创建Uri对象:new Uri("/navigatingPage?key1=value1&key2=va ...

  6. log4j:WARN Please initialize the log4j system properly 问题解决

    log4j:WARN No appenders could be found for logger (com.netease.qa.testng.TestngRetry).log4j:WARN Ple ...

  7. python求数字位数的方法

    第一种:利用str()函数将数字转化成字符串,再利用len()函数判断位长. a=Int(raw_input("the number you want type in:") b=l ...

  8. Android 开源项目及其学习

    Android 系统研究:http://blog.csdn.net/luoshengyang/article/details/8923485 Android 腾讯技术人员博客 http://hukai ...

  9. [知识点]字符串Hash

    1.前言 字符串的几大主要算法都多少提及过,现在来讲讲一个称不上什么算法, 但是非常常用的东西——字符串Hash. 2.Hash的概念 Hash更详细的概念不多说了,它的作用在于能够对复杂的状态进行简 ...

  10. Android 学习笔记之三—— 音效的使用

    在开发手电筒应用的处理音效的过程中,看网上使用的是MediaPlayer,因为音效一般都比较短,所以这里使用的是SoundPool,如下: SoundPool soundPool=new SoundP ...