当前位置:网站首页>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
边栏推荐
- MCS:离散随机变量——Binomial分布
- MCS:多元随机变量——离散随机变量
- MCS:离散随机变量——Pascal分布
- EMC surge protection and decoupling design
- 熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
- Chapter 6 picture operation of canvas
- China arsenic trioxide industry research and future forecast report (2022 Edition)
- Can futures accounts be opened offline? Is it safe to open an account online?
- Laravel - composer installs the specified laravel version
- 阿里云体验有奖:使用PolarDB-X与Flink搭建实时数据大屏
猜你喜欢

墨滴排版

MCS:多元随机变量——多项式分布

Alibaba cloud experience Award: use polardb-x and Flink to build a large real-time data screen

信息学奥赛一本通1194:移动路线

The 5th China software open source innovation competition | opengauss track live training

MySQL中100w数据表比1000w数据表查询更快吗?

卫星运动的微分方程

Source code of campus secondary market

MySQL的json 数组操作 json_array_append、json_array_insert

Whitelabel Error Page访问
随机推荐
Chapter 12 other applications of canvas
Chapter 14 of canvas physical animation
Is 100W data table faster than 1000W data table query in MySQL?
JS will have variable promotion and function promotion
华理生物冲刺科创板:年营收2.26亿 拟募资8亿
信息学奥赛一本通1001:Hello,World!
How word automatically generates directories
Uncover the secret! Pay attention to those machines under the membership system!
Class template case - array class encapsulation
信息学奥赛一本通2061:梯形面积
中国二氧化硫脲行业研究与发展前景研究报告(2022版)
You need to know about project procurement management
Laravel - Composer 安装指定 Laravel 版本
Imitation headline news information DZ template discuz news information business version GBK template source code
const用法精讲
驱动器实际运用案例
redis在window和Linux环境下的安装
Thanos store component
中国三氧化二砷行业研究与未来预测报告(2022版)
Evaluation index of high concurrency software (website, server interface)