Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Rose Curve and Heart pattern by HTML5 Canvas

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces HTML5 Canvas how to achieve the rose curve and heart-shaped pattern, the article is very detailed, has a certain reference value, interested friends must read it!

Tip: copy the code to a html file and save it, and you can see the effect by opening it directly.

Implementation code:

HTML5 demo

# apDiv1 {

Position:absolute

Width: 120 pixels

Height: 300 pixels

Z-index:1

Left: 840px

Top: 80px

}

Your browser does not support canvas elements.

The function draw () {var ctx = document.getElementById ('canvas'). GetContext ('2d'); ctx.save (); ctx.translate (400300); ctx.clearRect (- 400 copyright 300800600); ctx.strokeStyle = "# cc0000"

Var a = 0 ~ (th) b = 1 ~ (th) m = 6 ~ (th) n = 1

M = document.forms [0] .m.value

N = document.forms [0] .n.value

A = document.forms [0] .a.value

B = document.forms [0] .b.value

DrawRose (ctx,a,b,m,n)

Ctx.restore ()

}

Function drawRose (ctx,a,b,m,n) {

Ctx.beginPath ()

Var e = 0BZ c = 120m

Var k = 2 * Math.PI / 360

Do {

Var r = a / b + Math.sin (m * e / n * k)

R = r * c

Var x = r * Math.cos (e * k)

Var y = r * Math.sin (e * k)

E + = 0.1

Ctx.lineTo (XBI y)

} while (e

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report