当前位置:网站首页>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 to store null value on the disk of yyds dry inventory?
- (5) User login - services and processes - History Du touch date stat CP
- Common SQL sets
- Let me ask you a question. Have you ever used the asynchronous io of Flink SQL to associate dimension tables in MySQL? I set various settings according to the official website
- Global and Chinese market of AC induction motors 2022-2028: Research Report on technology, participants, trends, market size and share
- WiFi 2.4g/5g/6g channel distribution
- Global and Chinese market of wireless hard disk 2022-2028: Research Report on technology, participants, trends, market size and share
- 6.0 kernel driver character driver
- Why use pycharm to run the use case successfully but cannot exit?
- regular expression
猜你喜欢

Electronic tube: Literature Research on basic characteristics of 6j1

Farmersworld farmers world, no faith, how to talk about success?

JS closure knowledge points essence

Morning flowers and evening flowers

Persistence of Nacos

Common SQL sets

Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)

QGIS grid processing DEM data reclassification

Summary of basic knowledge of exception handling

Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
随机推荐
gslb(global server load balance)技术的一点理解
[sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
WiFi 2.4g/5g/6g channel distribution
What if the Flink SQL client exits and the table is emptied?
The 14th five year plan and investment feasibility study report of China's industry university research cooperation Ⓧ 2022 ~ 2028
Luogu deep foundation part 1 Introduction to language Chapter 7 functions and structures
How to store null value on the disk of yyds dry inventory?
Market layout planning and latest dynamic analysis report of China's smart public security industry Ⓕ 2022 ~ 2028
(5) User login - services and processes - History Du touch date stat CP
JS demo calculate how many days are left in this year
Teach you how to install aidlux (1 installation)
Exness: the Central Bank of England will raise interest rates again in March, and inflation is coming
regular expression
Cognitive fallacy: what is Fredkin's paradox
treevalue——Master Nested Data Like Tensor
English topic assignment (28)
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
[SRS] build a specified version of SRS
Preliminary understanding of C program design
China's coal industry investment strategic planning future production and marketing demand forecast report Ⓘ 2022 ~ 2028