当前位置:网站首页>Summer Challenge harmonyos realizes a hand-painted board
Summer Challenge harmonyos realizes a hand-painted board
2022-07-27 15:35:00 【51CTO】
This article is participating in the starlight project 3.0– Summer Challenge
Preface
Studying recently openHarmony, I know it just before canvas, So this article shares a hand-painted board I implemented , utilize openHarmony Built in API cnavas Component implementation .
Introduce
This is a hand drawn board , And according to the sliding screen speed , Dynamically generate line size , When the user touches the screen , Lines will be generated , And the faster , The thinner the lines .
Effect display

Principle analysis
1. Drawing principle
Before using , Need line understanding canvas Components , You can refer to harmonyOS Developer documentation , The documentation is very detailed , I won't go into that
First , We need to canvas Context object , It needs to be bound in the touch mobile event , Because we generate the corresponding lines by touching .
then , Attribute selection lineCap, There are three types of attribute values :butt、round、square, I tried and found round It works better .
- The property value is butt The effect of the
The property value is round
The property value is square
Actually butt The effect is not bad , The serration is too serious , although API There is built-in anti aliasing property in , But I don't know why it has no effect , Maybe the granularity is too large , Now the granularity is a little stuck , If the granularity is small, it is estimated to be more stuck
To sum up, I chose round, It will end the end of the line with a circle , So the effect is more rounded
Finally, take out the last value in the array , As moveTo Coordinates of , Take the point after moving the mouse as lineTo Coordinates of , And then through stroke Can draw an image .
Draw a straight line , Usually use moveTo () And lineTo () Two methods .. moveTo () Method is used to move the brush to the specified point and take the changed point as the starting point of the line ,lineTo () Is the end point .
2. Line thickness
Want to calculate the line thickness through speed , Then you need to get the time between two points , Get speed through time and distance
When triggered touchmove event , Store the current timestamp , The time obtained by the last trigger event - The time obtained by the current trigger event , You can get the event interval of two triggering events , At this point, we have time between two points
Then calculate the distance between two points ( Square sum and then root ), adopt distance / Time = Speed Calculate the speed between two points , Thus, the line thickness can be dynamically generated
Complete code
index.js
index.hml
index.css
summary
Shortcomings : The use experience is not very good , Further optimization is needed
Last , Through custom components , To deepen the HarmonyOS Development of , Build Hongmeng ecology !
Attachment link : https://ost.51cto.com/resource/2175
Want to know more about open source , Please visit :
边栏推荐
- Reading notes of lifelong growth (I)
- IJCAI 2022 outstanding papers were published, and 298 Chinese mainland authors won the first place in two items
- Network device hard core technology insider router Chapter 15 from deer by device to router (Part 2)
- EMC design scheme of USB2.0 Interface
- TL431-2.5v基准电压芯片几种基本用法
- JUC(JMM、Volatile)
- The design method of integral operation circuit is introduced in detail
- 2022-07-27 Daily: IJCAI 2022 outstanding papers were published, and 298 Chinese mainland authors won the first place in two items
- [0 basic operations research] [super detail] column generation
- Unity mouse controls the first person camera perspective
猜你喜欢

HaoChen CAD building 2022 software installation package download and installation tutorial

DIY ultra detailed tutorial on making oscilloscope: (1) I'm not trying to make an oscilloscope

EMC design scheme of RS485 interface

Record record record
Principle of MOS tube to prevent reverse connection of power supply

Spark TroubleShooting整理

华云数据打造完善的信创人才培养体系 助力信创产业高质量发展

/dev/loop1占用100%问题

QT (five) meta object properties

西瓜书《机器学习》阅读笔记之第一章绪论
随机推荐
Spark 3.0 Adaptive Execution 代码实现及数据倾斜优化
Overview of wechat public platform development
华为鸿蒙模拟器去除顶部导航栏方法
Usage of countdownlatch in multithreaded environment
How to package AssetBundle
EMC design scheme of RS485 interface
Cap theory and base theory
【剑指offer】面试题53-Ⅰ:在排序数组中查找数字1 —— 二分查找的三个模版
【剑指offer】面试题55 - Ⅰ/Ⅱ:二叉树的深度/平衡二叉树
Spark lazy list files 的实现
md 中超链接的解析问题:解析`this.$set()`,`$`前要加空格或转义符 `\`
Multi table query_ Exercise 1 & Exercise 2 & Exercise 3
Network equipment hard core technology insider router Chapter 10 Cisco asr9900 disassembly (III)
Leetcode 90. subset II backtracking /medium
Transactions_ Basic demonstrations and transactions_ Default auto submit & manual submit
微信公众平台开发概述
Leetcode 190. reverse binary bit operation /easy
Basic usage of kotlin
Network device hard core technology insider router Chapter 15 from deer by device to router (Part 2)
《终身成长》读书笔记(一)


