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. JAVA 引入 junit工具框架

    我遇到的麻烦 : 开始直接按照视频上的来做,直接也是引入的他上面的jar ,但是我只引入了一个,就是上面的junit-4.4.jar,然后就会报错,会出现,空指针的错误, 后面我又按照网上的教程 这里 ...

  2. Hdu4311 || 4312Meeting point-1/-2 n个点中任意选一个点使得其余点到该点曼哈顿距离之和最小

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  3. 如何理解typedef void (*pfun)(void)

    问题: 在刚接触typedef void (*pfun)(void) 这个结构的时候,存在疑惑,为什么typedef后只有一"块"东西,而不是两"块"东西呢?那 ...

  4. iOS Real Stuff

    Ray Wenderlich     AppCoda(English)   AppCoda(TW) Awesome iOS      Code4App代码库     CocoaChina代码库   o ...

  5. Errors occurred during the build. Errors running builder 'JavaScript Validator' on project

    1.问题:Errors occurred during the build. Errors running builder 'JavaScript Validator' on project 2.解决 ...

  6. bootstrap之伪元素

    bootstrap之伪元素 参考地址:http://www.cnblogs.com/keyi/p/5943178.html http://www.runoob.com/css/css-pseudo-e ...

  7. Hibernate中Criteria的完整用法

    1,CriteriaHibernate 设计了 CriteriaSpecification 作为 Criteria 的父接口,下面提供了 Criteria和DetachedCriteria .2,De ...

  8. c和oc小知识

    1.const const 修饰了*p1 / *p2 const int * p1=&age; int const * p2=&age;//和上面的意义一样 ,换句话说就是 在 “ * ...

  9. 在linux下Ant的环境配置

    Ant(英文全称为another neat tool,另一个简洁的工具)是一个基于Java的生成工具,Ant将会被应用到Java项目中. 同样的,现在要来安装Ant(最近要安装的东西还蛮多的=m=), ...

  10. 日常关键字:定时关机、该任务映像已损坏或已篡改.(0x80041321)、ChaZD生词同步扇贝

    我在床上用chinanet网络慢得简直令人发指,12B/S.是的你没有看错,这是我最常看到的网速.但是我最近发现电脑联网开出一个WiFi,在床上用手机上网时,网速会一点提升,可达到1KB/S(⊙﹏⊙) ...