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 html5's canvas canvas draws arcs and rotated graphics

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about the html5 canvas canvas how to draw arcs and rotation graphics, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.

Before doing the rotation operation, you must understand one sentence: it is the coordinate system of the canvas that is rotated, not the graphic itself. Well, after understanding this sentence, the next step is very simple.

The code is as follows:

Var cxt=document.getElementById ('demo'). GetContext ("2d")

Cxt.beginPath ()

Cxt.arc / * draw a semicircle with center coordinates 100100; the start Radian is 0.75 and the end Radian is 1.75; the last parameter False = clockwise, true = counterclockwise, of course, this parameter is optional * /

Cxt.fillStyle= "# F00"; / * choose the color to use * /

Cxt.fill (); / * the step of actually drawing a figure on the canvas, drawing the first semicircle * /

/ * draw the second semicircle in the same way * /

Cxt.beginPath ()

Cxt.arc (170pje 100pr 50gm. PIQR 1.25ct Math.PIQR 0.25pr false)

Cxt.fillStyle= "# F00"

Cxt.fill (); / * draw the drawing on the canvas * /

Cxt.beginPath ()

/ * rotate the canvas 45 degrees clockwise, and the parameter of the rotate function is radians, so convert it * /

Cxt.rotate (45*Math.PI/180)

Cxt.fillRect (141.1 fuzz 50100100); / * the start coordinate is 141.1 meme 50, and the width and height are both 100cm /

Cxt.fillStyle= "# F00"

Cxt.fill ()

Cxt.beginPath ()

/ * rotate the canvas to a normal angle * /

Cxt.rotate (- 45*Math.PI/180)

Cxt.font= "60px Microsoft Yahei"

Cxt.strokeStyle= "# f00"

Cxt.strokeText ("I love html5", 0300); / * two parameters, the first is the x-axis coordinate to start drawing the text, and the second is the Y coordinate to start drawing the text * /

Cxt.stroke ()

/ * create a gradient * /

Var grd=cxt.createLinearGradient / * the four parameters are the start point of the gradient x, the end point of the gradient x, and the end point of the gradient x, y

Grd.addColorStop (0, "# FF0000")

Grd.addColorStop (0.25, "# FFFF00")

Grd.addColorStop (0.5, "# 00FF00")

Grd.addColorStop (.75, "# 00FFFF")

Grd.addColorStop (1, "# FFFF00")

Cxt.strokeStyle=grd

Cxt.strokeText ("I love canvas", 0400); / * two parameters, the first is the x-axis coordinate to start drawing the text, and the second is the Y coordinate to start drawing the text * /

Cxt.stroke ()

This is how html5's canvas canvas draws arcs and rotations. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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