夜鹰教程网-程序员的加油站
 当前位置:文章中心 >> Css3.0_css2.0_html5
canvas绘制凤凰
夜鹰教程网 来源:www.yyjcw.com 日期:2017-10-26 17:01:08
canvas绘制凤凰

70296.gif


HTML代码:

<!doctype html>

 <html>

  <head>

   <meta charset="utf-8">

   <link href="style/style.css" rel="stylesheet" type="text/css">

   <title></title>

  </head>

 <body>

  <script src="js/jquery.js"></script>

  <canvas id="phoenix" width="460" height="450"></canvas>

  <script src="js/js.js" type="text/javascript"></script>

 </body>

</html>


JS 代码:


$(function() {

    var ctx = document.getElementById("phoenix").getContext("2d");

    var globalGradient = ctx.createLinearGradient(196, 279, 275, 207);

    globalGradient.addColorStop(0, "#d34700");

    globalGradient.addColorStop(.8, "#fdc000");

    drawBody();

    drawLeftWing();

    drawLeftWingDetails();

    drawRightWing();

    drawRightWingDetails();

    drawTheAss();

    // let the party start ------------------------------------------------------------

    // --------------------------------------------------------------------------------

    function drawBody() {

        var bg = ctx.createLinearGradient(275, 207, 196, 279);

        bg.addColorStop(0, "#fdc000");

        bg.addColorStop(.20, "#fc4e19");

        bg.addColorStop(.50, "#fdc000");

        ctx.beginPath();

        ctx.fillStyle = bg;

        // ass of the phoenix

        ctx.bezierCurveTo(196, 279, 202, 274, 201, 267);

        ctx.bezierCurveTo(199, 260, 201, 246, 208, 235);

        ctx.bezierCurveTo(215, 227, 217, 226, 220, 221);

        ctx.bezierCurveTo(223, 218, 227, 219, 234, 213);

        ctx.bezierCurveTo(249, 200, 263, 195, 270, 202);

        ctx.bezierCurveTo(277, 201, 277, 201, 284, 207);

        // head

        ctx.lineTo(275, 207);

        ctx.lineTo(280, 210);

        ctx.bezierCurveTo(280, 210, 279, 213, 270, 210);

        ctx.bezierCurveTo(259, 216, 251, 224, 247, 231);

        ctx.bezierCurveTo(245, 234, 246, 238, 246, 238);

        ctx.bezierCurveTo(246, 238, 237, 247, 235, 253);

        ctx.bezierCurveTo(232, 261, 213, 288, 196, 279);

        ctx.fill();

    }

    function drawLeftWing() {

        // left wing

        var bg = ctx.createLinearGradient(248, 240, 234, 254);

        bg.addColorStop(1, "#fdc000");

        ctx.beginPath();

        ctx.fillStyle = bg;

        ctx.bezierCurveTo(248, 240, 277, 260, 285, 238);

        ctx.bezierCurveTo(286, 231, 285, 227, 285, 227);

        ctx.bezierCurveTo(281, 202, 360, 228, 366, 250);

        ctx.bezierCurveTo(367, 261, 355, 270, 337, 279);

        ctx.bezierCurveTo(323, 284, 280, 288, 265, 277);

        ctx.bezierCurveTo(252, 271, 242, 266, 234, 254);

        ctx.bezierCurveTo(234, 254, 240, 241, 246, 239);

        ctx.fill();

    }

    function drawRightWing() {

        // right wing

        var bg = ctx.createLinearGradient(248, 240, 234, 254);

        bg.addColorStop(1, "#fdc000");

        ctx.beginPath();

        ctx.fillStyle = bg;

        ctx.bezierCurveTo(219, 220, 201, 200, 207, 188);

        ctx.bezierCurveTo(214, 175, 227, 179, 231, 179);

        ctx.bezierCurveTo(235, 179, 244, 169, 234, 156);

        ctx.bezierCurveTo(218, 136, 204, 109, 203, 102);

        ctx.bezierCurveTo(201, 94, 174, 107, 174, 145);

        ctx.bezierCurveTo(175, 163, 174, 186, 190, 200);

        ctx.bezierCurveTo(197, 219, 208, 235, 208, 239);

        ctx.bezierCurveTo(208, 239, 212, 229, 220, 223);

        ctx.fill();

    }

    function drawLeftWingDetails() {

        drawFeather(182, 18, 204, 104, 198, 104, 190, 58, 188, 66, 192, 94, 172, 54);

        drawFeather(160, 4, 198, 106, 190, 106, 174, 42, 184, 88, 172, 80, 158, 44);

        drawFeather(144, 32, 198, 110, 192, 120, 144, 32, 168, 80, 170, 86, 148, 60);

        drawFeather(118, 30, 189, 112, 185, 116, 142, 55, 179, 97, 152, 82, 136, 71);

        drawFeather(153, 30, 158, 54, 153, 46, 157, 47, 155, 49, 154, 42, 152, 24);

        drawFeather(134, 62, 184, 122, 179, 129, 150, 89, 174, 114, 138, 92, 136, 75);

        drawFeather(124, 57, 186, 116, 179, 122, 136, 80, 181, 113, 148, 108, 128, 69);

        drawFeather(118, 98, 177, 132, 175, 139, 148, 114, 168, 128, 162, 138, 135, 117);

        drawFeather(139, 95, 179, 129, 172, 134, 151, 108, 168, 123, 148, 119, 137, 96);

        drawFeather(123, 117, 177, 141, 176, 146, 153, 136, 167, 138, 162, 148, 119, 123);

        drawFeather(131, 128, 179, 151, 178, 159, 144, 140, 169, 148, 136, 144, 133, 134);

        drawFeather(152, 156, 180, 159, 178, 167, 161, 153, 176, 154, 177, 164, 164, 159);

        drawFeather(113, 159, 179, 178, 178, 185, 128, 164, 161, 179, 166, 185, 122, 175);

        drawFeather(128, 144, 181, 176, 178, 181, 142, 155, 177, 174, 173, 182, 140, 168);

        drawFeather(156, 153, 181, 180, 192, 190, 162, 163, 169, 175, 173, 187, 158, 177);

        drawFeather(119, 170, 187, 194, 192, 201, 141, 180, 172, 192, 180, 203, 129, 186);

        drawFeather(148, 147, 179, 194, 161, 193, 156, 180, 167, 189, 157, 190, 152, 184);

        drawFeather(145, 193, 192, 204, 202, 212, 145, 193, 186, 205, 171, 211, 158, 204);

        drawFeather(149, 190, 200, 213, 200, 223, 172, 208, 191, 213, 177, 222, 159, 201);

        drawFeather(172, 222, 201, 221, 204, 228, 184, 225, 198, 222, 189, 232, 171, 227);

        drawFeather(175, 237, 205, 228, 206, 235, 175, 237, 177, 229, 198, 231, 207, 240);

        drawFeather(189, 242, 207, 233, 209, 239, 196, 240, 205, 235, 198, 245, 192, 244);

    }

    function drawRightWingDetails() {

        drawFeather(454, 281, 342, 250, 362, 243, 443, 285, 396, 292, 393, 273, 420, 279);

        drawFeather(435, 286, 363, 259, 366, 249, 399, 291, 374, 273, 372, 260, 398, 279);

        drawFeather(450, 295, 345, 270, 353, 260, 448, 297, 430, 313, 368, 272, 409, 296);

        drawFeather(438, 310, 345, 249, 361, 252, 434, 315, 371, 290, 365, 263, 427, 306);

        drawFeather(450, 316, 344, 270, 350, 263, 447, 321, 405, 320, 355, 267, 373, 292);

        drawFeather(407, 300, 348, 270, 354, 261, 394, 301, 375, 301, 359, 271, 387, 296);

        drawFeather(378, 301, 340, 276, 344, 270, 373, 304, 340, 288, 346, 275, 352, 286);

        drawFeather(376, 320, 333, 276, 339, 272, 372, 318, 352, 306, 346, 286, 365, 306);

        drawFeather(355, 317, 324, 273, 329, 273, 350, 317, 329, 296, 330, 273, 333, 292);

        drawFeather(358, 321, 314, 275, 318, 271, 342, 316, 318, 295, 319, 271, 333, 301);

        drawFeather(318, 300, 304, 277, 314, 276, 314, 283, 309, 276, 317, 274, 319, 290);

        drawFeather(320, 296, 292, 282, 298, 276, 313, 293, 306, 291, 298, 273, 304, 283);

        drawFeather(333, 319, 290, 278, 298, 274, 324, 318, 300, 296, 300, 283, 324, 311);

        drawFeather(337, 334, 284, 283, 289, 280, 331, 334, 310, 327, 289, 280, 315, 322);

        drawFeather(307, 299, 267, 278, 282, 281, 302, 300, 292, 302, 283, 286, 297, 296);

        drawFeather(315, 332, 265, 275, 278, 282, 297, 320, 284, 307, 278, 282, 304, 319);

        drawFeather(276, 313, 251, 266, 262, 268, 272, 290, 251, 266, 271, 278, 278, 304);

        drawFeather(253, 287, 242, 261, 249, 266, 249, 283, 240, 276, 248, 266, 250, 279);

        drawFeather(236, 286, 235, 253, 243, 261, 240, 275, 231, 267, 244, 272, 239, 281);

    }

    function drawTheAss() {

        drawFeather(243, 308, 218, 272, 222, 271, 238, 311, 222, 296, 221, 271, 227, 296);

        drawFeather(236, 309, 218, 271, 223, 269, 236, 309, 223, 304, 222, 269, 225, 296);

        drawFeather(248, 373, 206, 277, 215, 274, 209, 323, 216, 290, 218, 295, 247, 359);

        drawFeather(269, 349, 211, 274, 218, 271, 250, 347, 214, 317, 218, 271, 224, 314);

        drawFeather(213, 325, 205, 279, 212, 275, 207, 314, 201, 300, 209, 288, 209, 302);

        drawFeather(203, 374, 197, 278, 207, 280, 189, 361, 196, 278, 200, 289, 204, 360);

        drawFeather(199, 328, 200, 278, 206, 278, 194, 313, 200, 278, 202, 285, 199, 328);

        drawFeather(189, 318, 201, 277, 205, 279, 185, 302, 201, 277, 200, 283, 192, 307);

        drawFeather(177, 314, 199, 274, 203, 280, 178, 301, 199, 274, 200, 281, 185, 303);

        drawFeather(144, 312, 196, 276, 199, 281, 166, 306, 195, 276, 196, 285, 161, 313);

        drawFeather(157, 297, 200, 273, 201, 278, 166, 285, 182, 280, 201, 278, 164, 291);

        drawFeather(152, 277, 200, 269, 201, 274, 152, 277, 193, 275, 201, 275, 177, 285);

        drawFeather(157, 263, 202, 262, 201, 268, 177, 266, 202, 262, 192, 274, 161, 270);

        drawFeather(125, 287, 202, 267, 202, 276, 151, 286, 201, 267, 138, 297, 125, 287);

    }

    // helper function for all feathers

    function drawFeather(pt1x, pt1y, pt2x, pt2y, pt3x, pt3y,

        bez1pt1x, bez1pt1y, bez2pt1x, bez2pt1y,

        bez1pt2x, bez1pt2y, bez2pt2x, bez2pt2y) {

        var gradient = ctx.createLinearGradient(pt1x, pt1y, pt2x, pt2y);

        ctx.beginPath();

        ctx.moveTo(pt1x, pt1y);

        ctx.bezierCurveTo(bez1pt1x, bez1pt1y, bez2pt1x, bez2pt1y, pt2x, pt2y);

        ctx.lineTo(pt3x, pt3y);

        ctx.bezierCurveTo(bez1pt2x, bez1pt2y, bez2pt2x, bez2pt2y, pt1x, pt1y);

        ctx.shadowBlur = 0;

        gradient.addColorStop(0, "#d34700");

        gradient.addColorStop(0.8, "#fdc000");

        ctx.fillStyle = gradient;

        ctx.fill();

    }

});


复制链接 网友评论 收藏本文 关闭此页
上一条: canvas绘制旋转的八卦图视频教程(…  下一条: HTML5新标签汇总(全)
夜鹰教程网成立于2008年,目前已经运营了将近 13 年,发布了大量关于 html5/css3/C#/asp.net/java/python/nodejs/mongodb/sql server/android/javascript/mysql/mvc/easyui/vue/echarts原创教程。 我们一直都在坚持的是:认证负责、一丝不苟、以工匠的精神来打磨每一套教程,让读者感受到作者的用心。我们默默投入的时间,确保每一套教程都是一件作品,而不是呆板的文字和视频! 目前我们推出在线辅导班试运营,模式为一对一辅导,教学工具为QQ。我们的辅导学科包括 java 、android原生开发、webapp开发、商城开发、C#和asp.net开发,winform和物联网开发、web前端开发,但不仅限于此。 普通班针对的是国内学员,例如想打好基础的大学生、想转行的有志青年、想深入学习的程序员、想开发软件的初学者或者业余爱好者等。 就业办针对即将毕业上岗的大四学生,或者打算转行的初级开发工程师。 留学生班针对的是在欧美、加拿大、澳洲、日本、韩国、新加坡等地留学的中国学子,目的是让大家熟练地掌握编程技能,按时完成老师布置的作业,并能顺利地通过考试。 详细咨询QQ:1416759661   夜鹰教程网  基于角色的权限管理系统(c-s/b-s)。
  夜鹰教程网  基于nodejs的聊天室开发视频教程
  夜鹰教程网  Git分布式版本管理视频教程
  夜鹰教程网  MVC+EasyUI视频教程
  夜鹰教程网  在线考试系统视频教程
  夜鹰教程网  MongoDB视频教程。
  夜鹰教程网 Canvas视频教程
  夜鹰教程网 报表开发视频教程
  热点推荐
什么是css框架
meta标签实现页面的动感效果
CSS半透明滤镜在FIREFOX和IE下面的…
div+css鼠标悬停在div上,div背景色…
纯css下拉菜单特效
div+css的浏览器兼容问题
CSS定义表格线为单一线
CSS滤镜效果收集(全)
列表显示文字和图片垂直居中对齐
在固定位置显示背景图片
网站变换图片的显示方法
在select外面套一个div或span, se…
常用的CSS命名规则
闪字闪字闪字闪字闪字闪字闪字闪字…
css让图片自动适应表格大小
  最近更新
HTTP协议实现文件断点续传
H5实现断点上传
行内元素和块级元素汇总
H5视频直播技术介绍
border-image详解
你必须知道的HTML5的新特性
html5 js控制音乐播放
HTML+CSS代码规范
css3学习笔记 transition与animat…
css3学习笔记Transform
css3学习笔记2D或3D转换
css3学习笔记文本特效
css3学习笔记颜色和透明度
css3学习笔记二
css3学习笔记一

关于我们 | 网站建设 | 技术辅导 | 常见问题 | 联系我们 | 友情链接

夜鹰教程网 版权所有 www.yyjcw.com All rights reserved 备案号:蜀ICP备08011740号3