当前位置:网站首页>Yyds dry goods inventory Spring Festival "make" your own fireworks
Yyds dry goods inventory Spring Festival "make" your own fireworks
2022-07-03 22:09:00 【liuzhen007】
Preface
Unconscious , The Spring Festival is almost over , Annual leave is insufficient . Because of the recurrence of the epidemic , I responded to the government's call to celebrate the new year on the spot , So I stayed “ Imperial Capital ” Beijing Festival . There are many inconvenient places to celebrate the festival in the imperial capital , For example, setting off fireworks is not very free . therefore , Do something by yourself , Satisfy your mood of setting off fireworks .
Text
Presentation mode
I have decided to make a fireworks program , So which presentation method to choose ? Like an applet 、Android、iOS、 Webpage 、windows client 、mac client 、linux client ?
Have your best PC Client , And support windows、mac、linux Three platforms . without doubt , Use Electron The architecture is the most cost-effective .Electron Is an open source cross platform PC Architecture .
Choose a special background image
I am an outgoing blogger who likes sharing and helping others , In the developer community of Youmeng, I helped many small partners , Therefore, it has also been officially recognized , Won the honorary title of quarterly star , And the official also sent out certificates of honor and custom gift boxes , Just use them as the background of fireworks .
Next , Setting the background , Pay attention to the settings canvas Background image , You need to wait until the picture is loaded before drawing .
First , obtain canvas The context of the object , The code is as follows :
var ctx = canvas. getContext( "2d");
- 1.
then , Create background objects and listen for events , The code is as follows :
var img = new Image();
img. src = "img/bg.png";
img. onload = function () {
draw();
}
- 1.
- 2.
- 3.
- 4.
- 5.
Last , Define the drawing method , Draw the picture to canvas in , The code is as follows :
function draw() {
ctx. drawImage( img, 0, 0, img. width, img. height);
}
- 1.
- 2.
- 3.
Define fireworks
Define the basic attributes of fireworks , Including fireworks x Axis and y Axis coordinates 、 Fireworks radius 、 Launch speed 、 Blooming range, etc , The reference codes are as follows :
function Fire() {
this. x = canvas. width / 2, // Fireworks x coordinate
this. y = canvas. height, // Fireworks y coordinate
this. radius = 2, // The radius of fireworks
this. speed = getRandom( 6, 8), // Speed of launch
this. angle = getRandom( 1.1 * Math. PI, 1.9 * Math. PI), // The scope of blooming
this. color = Math. random() > 0.5 ? 'white' : ( '#' + Math. random(). toString( 16). substr( 2, 6). toUpperCase());
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
Define the blooming fragments of fireworks
We all know , After the fireworks bloom , Will produce countless pieces , The appearance of these fragments finally determines the beauty of fireworks , Therefore, design is very important , Fireworks fragments include coordinates 、 radius 、 Number of fragments 、 Speed 、 gravity 、 The frictional force 、 Angle, etc. , The reference codes are as follows :
function ChildFire() {
this. x = 0, // Fireworks fragments x Location
this. y = 0, // Fireworks fragments y Location
this. radius = 1, // Fireworks fragment radius
this. n = 2, // Number of fireworks fragments
this. speed = getRandom( 1, 10) / 5, // Firework fragment speed
this. g = 0.98, // gravity
this. mocha = 0.96, // The frictional force
this. color = Math. random() > 0.5 ? 'white' : ( '#' + Math. random(). toString( 16). substr( 2, 6). toUpperCase()), // The angle of the fragment
this. angle = getRandom( 0, 2 * Math. PI); //0-2π Between random
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
Final rendering
Because nuggets can't upload videos , I made the video gif chart , It doesn't seem to affect the blooming effect of fireworks . Please enjoy , As shown in the figure below :
summary
All right. , Even if the fireworks effect you want is achieved . Dynamic effect of text , It's OK . Interested friends are welcome to comment , Communication , Let fireworks bloom more beautiful .
Author's brief introduction : Hello everyone , I am a Data-Mining(liuzhen007), Is a typical audio and video technology enthusiast , Before and after working in traditional radio and television giants and audio and video internet companies , Rich experience in audio and video live and on demand , Yes WebRTC、FFmpeg and Electron Have a very deep understanding of , official account : Play with audio and video . It's also CSDN Blogger 、 Huawei cloud sharing expert ( Co creation editor )、InfoQ Signed on , Welcome to follow me and share more dry goods !
边栏推荐
- How does sentinel, a traffic management artifact, make it easy for business parties to access?
- DOM light switch case
- Base ring tree Cartesian tree
- js demo 计算本年度还剩下多少天
- Kali2021.4a build PWN environment
- What if the Flink SQL client exits and the table is emptied?
- Leetcode problem solving - 235 Nearest common ancestor of binary search tree
- [template summary] - binary search tree BST - Basics
- js demo 計算本年度還剩下多少天
- The White House held an open source security summit, attended by many technology giants
猜你喜欢
treevalue——Master Nested Data Like Tensor
Some 5000+ likes, the development notes of a director of cosmic factory, leaked
常用sql集合
Collections SQL communes
QGIS grid processing DEM data reclassification
常用sql集合
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
(5) User login - services and processes - History Du touch date stat CP
Common SQL sets
随机推荐
Correlation
How to store null value on the disk of yyds dry inventory?
What is the difference between res.send() and res.end() in the node express framework
Cognitive fallacy: Wittgenstein's ruler
China's Call Center Industry 14th five year plan direction and operation analysis report Ⓔ 2022 ~ 2028
(POJ - 2912) rochambau (weighted concurrent search + enumeration)
Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
What if the Flink SQL client exits and the table is emptied?
Pengcheng cup Web_ WP
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
Morning flowers and evening flowers
JS Demo calcule combien de jours il reste de l'année
Preliminary analysis of smart microwave radar module
Après 90 ans, j'ai démissionné pour démarrer une entreprise et j'ai dit que j'allais détruire la base de données Cloud.
This time, thoroughly understand bidirectional data binding 01
股票炒股开户注册安全靠谱吗?有没有风险的?
Electronic tube: Literature Research on basic characteristics of 6j1
Tidb's initial experience of ticdc6.0
Why use pycharm to run the use case successfully but cannot exit?