In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use canvas to draw workflow nodes, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Before drawing, we need to prepare a node picture, for example:
All right, let's get to the point:
1. Add the canvas tag in the html:
Here, pay attention to setting the width and height of the canvas tag, that is, setting the width and height of the canvas.
two。 Get canvas objects and initialize canvas parameters
Var _ canvas= document.getElementById ("canvasId"); var _ height = _ canvas.height;// get the canvas height var _ width = _ canvas.width;// get the canvas width Var ctx = _ canvas.getContext ('2d'); / / draw a rectangle the size of the canvas in order to have a nice small border ctx.clearRect (0,0, _ width, _ height); / * draw the background line of the canvas * / / set the linewidth ctx.lineWidth = 0.1 / / draw the longitudinal background line for (var I = 1; I
< _width / 15; i++) { ctx.beginPath(); ctx.moveTo(i * 15, 0); ctx.lineTo(i * 15, _height); ctx.stroke();}//绘制横向背景线for(var i = 1; i < _ height / 15; i++) { ctx.beginPath(); ctx.moveTo(0, i * 15); ctx.lineTo(_width, i * 15); ctx.stroke();} 绘制完效果如图:3. Get node picture object
/ / create a new picture object var _ img = new Image (); / / specify the URL _ img.src= "node.png" of the picture
Here, in order to give an example to create a picture object directly, you can get the picture object directly in the actual drawing process, because the dynamic creation of picture object has a time to load the picture.
4. Draw a node picture
Ctx.drawImage (_ img,_x,_y,_imgWidth, _ imgHeight)
Where _ img is the image object obtained above, _ x is the x coordinate of the picture to be drawn on the canvas, _ y is the _ y coordinate of the picture to be drawn on the canvas, _ imgWidth is the width of the picture to be drawn, and _ imgHeight is the width of the picture to be drawn.
In the process of practical application, the position of the mouse is generally regarded as x-coordinate and y-coordinate, which will be described in a later article.
Effect drawing drawn:
Thank you for reading this article carefully. I hope the article "how to use canvas to draw workflow nodes" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.