HTML5Canvas如何实现玫瑰曲线和心形图案-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

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://kswsj.cn/article/gcgegs.html">http://kswsj.cn/article/gcgegs.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/hdjioo.html">linux退出循环命令,linux常用命令退出</a> </li><li> <a href="/article/hdjepd.html">nosql近况,noSQL特点</a> </li><li> <a href="/article/hdjich.html">oracle如何报错,oracle常见报错</a> </li><li> <a href="/article/hdjicp.html">nosql数据库配置,常见nosql数据库</a> </li><li> <a href="/article/hdjico.html">oracle锁怎么处理,oracle锁表了怎么解锁</a> </li> </ul> </div> </div> <div class="line"></div> <!--底部--> <footer id="5"> <div class="foot1 container"> <div class="list"> <div class="item"> <a href="javascript:;"> <span class="ico1"><i class="iconfont"></i><img src="/Public/Home/img/ewm.png" alt=""></span> <strong>关注我们</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>索要报价</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>我要咨询</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>找到我们</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>投诉建议</strong> </a> </div> </div> <div class="tel"> <dl> <tel><a href="tel:400-028-6601" target="_blank">400-028-6601</a></tel><br> <span>也许您需要专业的服务,欢迎来电咨询</span> </dl> <dl> <tel><a href="tel:18980820575" target="_blank">18980820575</a></tel><br> <span>您的需求,是我们前进的动力</span> </dl> </div> </div> <div class="friend"> <div class="container"> <span class="tit">友情链接:</span> <div class="inner"> <a href="https://www.cdcxhl.com/" target="_blank">建站公司</a><a href="https://www.cdcxhl.com/xiyun.html" target="_blank">成都移动机房</a><a href="https://www.cdcxhl.com/yunying.html" target="_blank">成都网站托管</a><a href="https://www.cdcxhl.com/jigui/" target="_blank">服务器托管机柜</a><a href="https://www.cdcxhl.com/link/" target="_blank">买友情链接</a><a href="https://www.cdcxhl.com/douyin/" target="_blank">抖音运营公司</a><a href="https://www.cdcxhl.com/tuoguan/" target="_blank">成都托管服务器</a><a href="https://www.cdcxhl.com/hangyead/" target="_blank">1元广告</a><a href="https://www.cdcxhl.com/xiaochengx.html" target="_blank">成都微信小程序开发公司</a><a href="https://www.cdcxhl.com/pinpai.html" target="_blank">品牌网站建设公司</a><a href="https://www.cdcxhl.com/tuoguan/yaan/" target="_blank">雅安服务器托管</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">软文推广</a><a href="https://www.cdcxhl.com/link/" target="_blank">外链</a><a href="https://www.cdcxhl.com/pinpai.html" target="_blank">成都品牌网站建设</a><a href="https://www.cdcxhl.com/shop.html" target="_blank">成都商城网站建设</a><a href="https://www.cdcxhl.com/waimao.html" target="_blank">成都外贸网站建设</a><a href="https://www.cdcxhl.com/" target="_blank">网站建设公司</a><a href="https://www.cdcxhl.com/mobile.html" target="_blank">手机网站制作公司</a> </div> </div> </div> <div class="foot"> <div class="container"> <div class="footNav"> <h3>网站建设</h3> <a href="http://www.cdkjz.cn/fangan/finance/" target="_blank">金融行业网站建设方案</a><a href="http://www.4006tel.net/" target="_blank">app网站建设</a><a href="http://www.kswjz.cn/" target="_blank">成都网站建设</a> </div> <div class="footNav"> <h3>服务器托管</h3> <a href="https://www.cdcxhl.com/idc/gysx.html" target="_blank">贵阳三线机房</a><a href="https://www.cdcxhl.com/idc/ershu.html" target="_blank">二枢服务器托管</a><a href="https://www.cdxwcx.com/jifang/yaan.html" target="_blank">雅安服务器托管</a> </div> <div class="footNav"> <h3>网站制作</h3> <a href="https://www.cdxwcx.com/" target="_blank">网站制作</a><a href="http://m.xwcx.net/" target="_blank">H5网站制作</a><a href="http://m.cdcxhl.cn/mobile/" target="_blank">手机网站制作</a> </div> <div class="footNav"> <h3>企业服务</h3> <a href="https://www.cdcxhl.com/shoulu/" target="_blank">网站收录</a><a href="https://www.cdcxhl.com/service/licence.html" target="_blank">药房许可证</a><a href="https://www.cdcxhl.com/service/gongsizhuce.html" target="_blank">注册公司</a> </div> <div class="fr ecode"> <div class="fl"> <img src="/Public/Home/img/ewm.jpg"> <p>关注企业微信</p> </div> <div class="fr slogan"> <p class="icon"> <a class="ph" href=""><i class="iconfont"></i></a> <a class="qq" href="tencent://message/?uin=1683211881&Site=&Menu=yes"><i class="iconfont"></i></a> </p> <p> <i>想要找 </i> <a href="">小程序开发</a>、<a href="">APP开发</a>、 <a href="">营销型网站建设</a>、<a href="">网站建设</a>、 <i><a href="">网站定制开发</a></i> ,就选<a href="">创新互联</a> </p> </div> </div> </div> <div class="bottom container"> <p class="fl"> 版权所有:成都创新互联科技有限公司 备案号:<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备19037934号</a> 服务热线:028-86922220 </p> <p class="fr"> <a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>: <a href="https://www.cdcxhl.com/" target="_blank">创新互联</a> </p> </div> </div> </footer> <!--在线咨询--> <div class="fot"> <ul> <li> <a href="https://p.qiao.baidu.com/cps/mobileChat?siteId=11284691&userId=6256368&type=1&reqParam=%20{%22from%22:0,%22sessionid%22:%22%22,%22siteId%22:%2211284691%22,%22tid%22:%22-1%22,%22userId%22:%226256368%22,%22ttype%22:1,%22siteConfig%22:%20{%22eid%22:%226256368%22,%22queuing%22:%22%22,%22siteToken%22:%226ce441ff9e2d6bedbdfc2a4138de449e%22,%22userId%22:%226256368%22,%22isGray%22:%22false%22,%22wsUrl%22:%22wss://p.qiao.baidu.com/cps3/websocket%22,%22likeVersion%22:%22generic%22,%22siteId%22:%2211284691%22,%22online%22:%22true%22,%22webRoot%22:%22//p.qiao.baidu.com/cps3/%22,%22bid%22:%22160142915792139572%22,%22isSmallFlow%22:0,%22isPreonline%22:0,%22invited%22:0%20},%22config%22:%20{%22themeColor%22:%224d74fa%22%20}%20}&appId=&referer=&iswechat=0&expectWaiter=-1&openid=null&otherParam=null&telephone=null&speedLogId=null&eid=null&siteToken=6ce441ff9e2d6bedbdfc2a4138de449e" target="_blank"> <img src="/Public/Home/img/fot1.png" alt=""> <p>在线咨询</p> </a> </li> <li> <a href="tel:18980820575" target="_blank"> <img src="/Public/Home/img/fot2.png" alt=""> <p>拨打电话</p> </a> </li> </ul> </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>