当前位置:网站首页>Konva series Tutorial 4: drawing attributes
Konva series Tutorial 4: drawing attributes
2022-06-29 14:57:00 【Front end watermelon brother】
Hello everyone , I'm brother watermelon , Let's take a look at some common attributes of graphics today .
Geometric properties
{
x: 10,
y: 10,
width: 50,
height: 50
}
x and y It represents a graphic Location , For rectangles , It's the upper left corner . For circles 、 For these , At the center of the circle .
This position is also the reference point for the deformation of the figure , Or the center of rotation .
offsetX and offsetY You can change the position of the graph .offset It actually moves the origin of the canvas coordinate system a certain distance , Then draw the graph .
For example, for Rectangles , We will offsetX and offsetY Set to width/2 and height/2, We can make the position of the rectangle go to the midpoint of the rectangle .
width and height Is the width and height of the graph . But for circular shapes , Is through the radius radius To set the size .
fill (fill)
usage :fill: #f04
Change the graphic color :
rect.fill('green');
fill Method can not only set the color , You can also get colors , As long as no parameters are passed in :
const fill = rect.fill();
Of course, we can also use advanced fill images 、 Gradient function , Need to use fillPatternImage 、fillLinearGradientStartPoint 、fillLinearGradientEndPoint 、fillLinearGradientColorStops Other methods , It's a little bit too much , Let's not talk about it here .
Stroke (stroke)
There are many styles related to stroke , Only the most commonly used stroke and strokeWidth.
usage :stroke: '#000'strokeWidth: 4
Change the stroke color of the drawing 、 Line width :
rect.stroke('blue').strokeWidth(8);
konva Support chain writing .
Chain writing , It's actually an object , After executing the method , This object is returned again .
In this way, we can link the calls of multiple methods , Improve code readability , It is often used to modify object attribute values .
Get stroke color 、 Line width
const stroke = rect.stroke();
const strokeWidth = rect.strokeWidth();
The opacity (opacity)
usage :opcity: 0.5
Set transparency :
rect.opcity(0.3)
Get the value of opacity :
const opcity = rect.opcity();
Show / hide (visible)
usage :visible: true
The graphics :
rect.show();
// perhaps
rect.visible(true);
Hide graphics :
rect.hide();
// or
rect.visible(false);
The essence is to modify the graphics visible attribute , Then re render .show and hide Just semantic encapsulation .
Mouse style
We can't operate like DOM The elements are the same , Set... Directly to graphic elements cursor attribute .
But we can move the cursor over the graph , The dynamic change canvas Mounted DOM Elemental cursor attribute .
rect.addEventListener('mouseenter', () => {
stage.container().style.cursor = 'move'
})
rect.addEventListener('mouseleave', () => {
stage.container().style.cursor = ''
})
ending
Different shapes have their own properties , For details, see konva Documents :
https://konvajs.org/api/Konva.html
边栏推荐
- 宜明昂科冲刺港股:年内亏损7.3亿 礼来与阳光人寿是股东
- MCS:离散随机变量——Poisson分布
- The 5th China software open source innovation competition | opengauss track live training
- Unity C# 基础复习29——泛型委托(P451)
- 自动注入@Resource和@Autowired注解的区别:
- Can futures accounts be opened offline? Is it safe to open an account online?
- Uniapp problem list and experience
- Netease strict selection offline data warehouse quality construction practice
- Imitation headline news information DZ template discuz news information business version GBK template source code
- MCS:多元随机变量——多项式分布
猜你喜欢

ModStartBlog 现代化个人博客系统 v5.2.0 主题开发增强,新增联系方式

How does a two character name become a three character name with spaces

MCS:离散随机变量——几何分布

Whitelabel Error Page访问

MySQL 数据库 - 通用语法 DDL DML DQL DCL

两个字的名字如何变成有空格的3个字符的名字

部署搭建decentraland流程讲解

Paper study -- accurate accounting of annual total runoff control rate considering the interannual variation characteristics of rainfall

Transport layer user datagram protocol (UDP)

MySQL的json 数组操作 json_array_append、json_array_insert
随机推荐
MCS:离散随机变量——Pascal分布
Heavyweight! The latest SCI impact factors were released in 2022, and the ranking of the three famous journals NCS and the top10 of domestic journals has changed (the latest impact factors in 2022 are
阿里云体验有奖:使用PolarDB-X与Flink搭建实时数据大屏
Differences between @resource and @autowired annotations automatically injected:
EXCEL的查询功能Vlookup
China arsenic trioxide industry research and future forecast report (2022 Edition)
wieshark抓包mysql协议简单分析
织梦dedecms资源素材教程下载网站模板源码(带手机移动端)附安装教程
Illustration of Ctrip quarterly report: net revenue of RMB 4.1 billion has been "halved" compared with that before the outbreak
MCS:多元随机变量——离散随机变量
Stm32 mbed tutorial (IV) --pwm
The first lesson on cloud - how easy is it to build a small broken station? The old driver of cloud computing will take you one hour to finish it
Whitelabel Error Page访问
墨滴排版
Draw a slash on a plane coordinate
Yi Ming ang Ke rushed to Hong Kong shares: loss of 730million in the year Lilly and sunshine life insurance were shareholders
. Net program configuration file operation (INI, CFG, config)
我登录RDB的数据库,提示需要主账号授权,这个我怎么知道该找谁?
MySQL的json 数组操作 json_array_append、json_array_insert
Chapter 8 pixel operation of canvas