成都创新互联网站制作重庆分公司

HTML5Canvas如何实现玫瑰曲线和心形图案

这篇文章主要介绍HTML5 Canvas如何实现玫瑰曲线和心形图案,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

创新互联2013年至今,先为城子河等服务建站,城子河等地企业,进行企业商务咨询服务。为城子河企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

提示:把代码复制到一个html文件中并保存,直接打开即可看到效果。

实现代码:

<!DOCTYPE html>

HTML5演示</ title></p><p><style type =“ text / css”></p><p>#apDiv1 {</p><p>position:absolute;</p><p>宽度:120像素;</p><p>高度:300像素;</p><p>z-index:1;</p><p>左:840px;</p><p>顶部:80px;</p><p>}</p><p></ style></p><p></ head></p><p><body></p><p><canvas id =“ canvas” width =“ 800” height =“ 600” style =“ border:1px solid#c3c3c3;”></p><p>您的浏览器不支持canvas元素。</ canvas></p><p><div id =“ apDiv1”></p><p><form></p><p>函数draw(){ var ctx = document.getElementById('canvas')。getContext('2d'); ctx.save(); ctx.translate(400,300); ctx.clearRect(-400,-300,800,600); ctx.strokeStyle =“#cc0000”;</p><p>var a = 0,b = 1,m = 6,n = 1;</p><p>m = document.forms [0] .m.value;</p><p>n = document.forms [0] .n.value;</p><p>a = document.forms [0] .a.value;</p><p>b = document.forms [0] .b.value;</p><p>drawRose(ctx,a,b,m,n);</p><p>ctx.restore();</p><p>}</p><p>函数drawRose(ctx,a,b,m,n){</p><p>ctx.beginPath();</p><p>var e = 0,c = 120;</p><p>var k = 2 * Math.PI / 360;</p><p>做{</p><p>var r = a / b + Math.sin(m * e / n * k);</p><p>r = r * c;</p><p>var x = r * Math.cos(e * k);</p><p>var y = r * Math.sin(e * k);</p><p>e + = 0.1;</p><p>ctx.lineTo(x,y);</p><p>} while(e <= 4320);</p><p>ctx.stroke();</p><p>}</p><p>函数draw2(){</p><p>var ctx = document.getElementById('canvas')。getContext('2d');</p><p>ctx.save();</p><p>ctx.translate(400,300);</p><p>ctx.clearRect(-400,-300,800,600);</p><p>ctx.strokeStyle =“#cc0000”;</p><p>ctx.beginPath(); //ctx.moveTo(0,0);</p><p>var e = 0,c = 150;</p><p>var k = 2 * Math.PI / 360;</p><p>做{</p><p>x = 150 * Math.cos(5/2 * e * k)+ 50 * Math.cos(15/16 * 5/2 * e * k);</p><p>y = 150 * Math.sin(5/2 * e * k)-50 * Math.sin(15/16 * 5/2 * e * k);</p><p>e + = 0.1;</p><p>ctx.lineTo(x,y);</p><p>} while(e <= 3600);</p><p>ctx.stroke();</p><p>ctx.restore();</p><p>}</p><p>函数draw3(){</p><p>var ctx = document.getElementById('canvas')。getContext('2d');</p><p>ctx。</p><p>ctx.translate(400,300);</p><p>ctx.clearRect(-400,-300,800,600);</p><p>ctx.strokeStyle =“#ff0000”;</p><p>ctx.beginPath();</p><p>var x = 1,y;</p><p>做{</p><p>y = -80 *(Math.sqrt(1-x * x)+ Math.pow(x * x,1/3));</p><p>x-= 0.001;</p><p>ctx.lineTo(100 * x,y);</p><p>} while(x> = -1);</p><p>做{</p><p>y = 80 *(Math.sqrt(1-x * x)-Math.pow(x * x,1/3));</p><p>x + = 0.001;</p><p>ctx.lineTo(100 * x,y);</p><p>} while(x <= 1);</p><p>ctx.closePath();</p><p>var grad = ctx.createRadialGradient(-40,-60,10,-40,-40,200);</p><p>grad.addColorStop(0,“#ffcc00”);</p><p>grad.addColorStop(1,“#ff0000”);</p><p>ctx.fillStyle = grad;</p><p>ctx.fill();</p><p>// ctx.stroke();</p><p>ctx.restore();</p><p>}</p><p>window.onload = function(){</p><p>draw();</p><p>}</p><p></ script></p><p></ body></p><p></ html></p><p>以上是“HTML5 Canvas如何实现玫瑰曲线和心形图案”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!</p> <br> 本文题目:HTML5Canvas如何实现玫瑰曲线和心形图案 <br> 当前网址:<a href="http://cxhlcq.com/article/gcgegs.html">http://cxhlcq.com/article/gcgegs.html</a> </div> </div> </div> <div class="other container"> <h3>其他资讯</h3> <ul> <li> <a href="/article/pjjjsp.html">(10)响应式宣言、响应式系统与响应式编程——响应式Spring的道法术器</a> </li><li> <a href="/article/pjjgjd.html">vueslots组件的组合/分发实例</a> </li><li> <a href="/article/pjjjss.html">win10怎么组家庭局域网</a> </li><li> <a href="/article/pjjjco.html">怎么在cmd控制台中运行java文件</a> </li><li> <a href="/article/pjjjoj.html">租用linux云服务器有哪些好处</a> </li> </ul> </div> <div class="footer"> <div class="foota container"> <div class="foot_nav fl col-lg-8 col-md-8 col-sm-12 col-xs-12"> <ul> <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6"> <h3>网站制作</h3> <a href="http://www.36103.cn/" target="_blank">成都网站制作</a><a href="http://chengdu.cdcxhl.com/" target="_blank">成都营销网站制作</a><a href="http://www.scyanting.com/" target="_blank">盐亭网站制作公司</a><a href="http://www.cdkjz.cn/" target="_blank">成都网站制作</a><a href="http://www.mywzjz.com/" target="_blank">绵阳网站制作公司</a><a href="http://www.cdxwcx.cn/" target="_blank">成都网站制作</a> </li> <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6"> <h3>企业服务</h3> <a href="https://www.cdcxhl.com/service/ssl.html" target="_blank">ssl证书</a><a href="https://www.cdcxhl.com/service/trademark.html" target="_blank">商标注册</a><a href="https://www.cdcxhl.com/service/ypfwzgz.html" target="_blank">互联网药品信息服务资格证</a><a href="https://www.cdcxhl.com/service/service.html" target="_blank">工商服务</a><a href="https://www.cdcxhl.com/service/shipinxuke.html" target="_blank">食品经营许可证</a><a href="https://www.cdcxhl.com/mianfei/jianzhan/" target="_blank">免费建站模板</a> </li> <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6"> <h3>网站建设</h3> <a href="http://m.cdxwcx.com/" target="_blank">成都网站建设</a><a href="http://www.cdkjz.cn/fangan/xuexiao/" target="_blank">校园网站建设方案</a><a href="https://www.cdxwcx.com/city/chongzhou/" target="_blank">崇州网站建设</a><a href="https://www.cdcxhl.com/" target="_blank">成都网站建设公司</a><a href="https://www.cdcxhl.com/pinpai.html" target="_blank">品牌网站建设</a><a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a> </li> <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6"> <h3>服务器托管</h3> <a href="http://www.cdxwcx.cn/tuoguan/mianyang.html" target="_blank">绵阳主机托管</a><a href="https://www.cdcxhl.com/idc/cqstsx.html" target="_blank">重庆水土双线托管</a><a href="https://www.cdcxhl.com/idc/zongshu.html" target="_blank">棕树服务器托管</a><a href="http://www.cdfuwuqi.com/tuoguan/duoxian/" target="_blank">多线服务器托管</a><a href="https://www.cdcxhl.com/idc/yaan.html" target="_blank">雅安服务器托管</a><a href="https://www.cdcxhl.com/idc/gysx.html" target="_blank">贵阳三线机房</a> </li> </ul> </div> <div class="footar fl col-lg-4 col-md-4 col-sm-12 col-xs-12"> <p>全国免费咨询:</p> <b>400-028-6601</b> <p>业务咨询:028-86922220 / 13518219792</p> <p>节假值班:18980820575 / 13518219792</p> <p>联系地址:成都市太升南路288号锦天国际A幢1002号</p> </div> </div> <div class="footb"> <div class="copy container"> <div class="fl">Copyright © 成都创新互联科技有限公司重庆分公司 <a href="https://beian.miit.gov.cn/" target="_blank">渝ICP备2021005571号</a></div> <!--<div class="fr"><a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>:<a href="https://www.cdcxhl.com/" target="_blank">创新互联</a></div>--> </div> </div> <div class="link"> <div class="container"> 友情链接:: <a href="https://www.cdcxhl.com/" target="_blank">成都网站建设</a> <a href="https://www.cdcxhl.com/city/chongqing.html" target="_blank">重庆网站建设</a> <a href="">四川网站建设</a> <a href="">重庆建设网站</a> <a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">移动服务器托管</a> <a href="http://www.cdfuwuqi.com/" target="_blank">成都服务器托管</a> <a href="https://www.cdcxhl.cn/" target="_blank">云服务器</a> <a href="http://www.cdhuace.com/" target="_blank">广告设计制作</a> <a href="https://www.cdcxhl.com/sheji/chongqing.html" target="_blank">重庆网页设计</a> <a href="https://www.cdcxhl.com/zuo/chongqing.html" target="_blank">重庆做网站</a> <a href="https://www.cdcxhl.com/zhizuo/chongqing.html" target="_blank">重庆网站制作</a> <a href="">重庆网站建设</a> <a href="">重庆网站公司</a> <a href="">渝中网站制作</a> <a href="">重庆网站设计</a> </div> </div> </div> <div class="foot"> <ul class="public-celan"> <li> <a href="https://p.qiao.baidu.com/cps3/chatIndex?siteToken=6ce441ff9e2d6bedbdfc2a4138de449e&speedLogId=162260383240185e3_1622603832401_02407&eid=6256368&reqParam=%7B%22from%22%3A1%2C%22sessionid%22%3A%22-100%22%2C%22siteId%22%3A%2211284691%22%2C%22tid%22%3A%22-1%22%2C%22userId%22%3A%226256368%22%2C%22ttype%22%3A1%2C%22pageId%22%3A0%7D" target="_blank" class="a1 db tc"> <img src="/Public/Home/img/icon-23.png" alt="" class="db auto"> <span class="span-txt">在线咨询</span> </a> </li> <li> <a href="tel:18980820575" class="a1 db tc"> <img src="/Public/Home/img/icon-24.png" alt="" class="db auto"> <span class="span-txt">电话咨询</span> </a> </li> <li> <a target="_blank" href="tencent://message/?uin=1683211881&Site=&Menu=yes" class="a1 db tc"> <img src="/Public/Home/img/icon-25.png" alt="" class="db auto"> <span class="span-txt">QQ咨询</span> </a> </li> <li> <a target="_blank" href="tencent://message/?uin=532337155&Site=&Menu=yes" class="a1 db tc public-yuyue-up"> <img src="/Public/Home/img/icon-26.png" alt="" class="db auto"> <span class="span-txt">预约顾问</span> </a> </li> </ul> </div> <div class="customer"> <dl class="icon1"> <dt> <a href="tencent://message/?uin=1683211881&Site=&Menu=yes"> <i class="iconT"><img src="/Public/Home/img/QQ.png" alt=""></i> <p>在线咨询</p> </a> </dt> </dl> <dl class="icon2"> <dt><i><img src="/Public/Home/img/weixin.png" alt=""></i><p>微信咨询</p></dt> <dd><img src="/Public/Home/img/ewm.png"></dd> </dl> <dl class="icon3"> <dt><i><img src="/Public/Home/img/dianhua.png" alt=""></i><p>电话咨询</p></dt> <dd> <p>028-86922220(工作日)</p> <p>18980820575(7×24)</p> </dd> </dl> <dl class="icon4"> <dt class="sShow"> <a href="tencent://message/?uin=244261566&Site=&Menu=yes"> <i><img src="/Public/Home/img/dengji.png" alt=""></i><p>提交需求</p> </a> </dt> </dl> <dl class="icon5"> <dt class="gotop"> <a href="#top"> <i><img src="/Public/Home/img/top.png" alt=""></i><p>返回顶部</p> </a> </dt> </dl> </div> </body> </html> <script> $(".con img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>