In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to make a digital clock with HTML5". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to make a digital clock with HTML5.
Copy the code
XML/HTML Code copies content to the clipboard
Var numData = [
"1111ax 1001max 1001max 1001max 1111", / / 0
"00010001Compact 0001GUBE 0001GUBE 0001", / / 1
"11110001GUP 0001ax 1111G 1000UX 1111", / 2
"11110001amp 0001max 1111", / / 3
"1010, 10, 10, 10, 10, 10, 10, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0010, / / 4.
"1111Universe 1000Compare 1000Universe 0001Compact 0001Uniq1111", / / 5
"1111lime 1000amp 1000amp 1111prime 1001max 1001max 1111", / / 6
"11110001amp 0001max 0001max 0001max 0001", / / 7
"1111Accord 1001Compare 1001According to 1001According to 1001plash 1111", / / 8
"1111Accord1001Compare 1001According to 0001Unix0001Unix1111", / / 9
"00000.0000Universe 00100.0000000000000000000000000000000.000", / /:
]
0 means there are no pixels, 1 means there are pixels, / in order to look better, that is, branches, to put it simply: for example, 0 is:
XML/HTML Code copies content to the clipboard
1 1 1
1 0 0 1
1 0 0 1
1 0 0 1
1 0 0 1
1 0 0 1
1 1 1
That makes it very clear. From 0 to 9, there is also a: sign is represented by a string.
Then write a particle object, that is, a pixel:
XML/HTML Code copies content to the clipboard
Var P_radius = 8pm Gravity = 9.8
Var Particle = function () {
This.x = 0
This.y = 0
This.vx = 0
This.vy = 0
This.color = ""
This.visible = false
This.drop = false
}
Particle.prototype = {
Constructors:Particle
Paint:function () {/ / draw itself
Ctx.fillStyle = this.color
Ctx.beginPath ()
Ctx.arc (this.x,this.y,P_radius,0,2*Math.PI)
Ctx.fill ()
}
Reset:function (xmeny color) {/ / reset
This.x = x
This.y = y
This.vx = 0
This.vy = 0
This.color = color
This.visible = true
This.drop = false
}
IsDrop:function () {/ / fall
This.drop = true
Var vx = Math.random () * 20,15
This.vx = Math.random () > = 0.5?-vx: vx
}
Update:function (time) {/ / actions at each frame
If (this.drop) {
This.x + = this.vx*time
This.y + = this.vy*time
Var vy = this.vy+Gravity*time
If (this.y > = canvas.height-P_radius) {
This.y = canvas.height-P_radius
Vy =-vy*0.7
}
This.vy = vy
If (this.xcanvas.width+P_radius | | this.ycanvas.height+P_radius) {
This.visible = false
}
}
}
}
The properties of particle objects are relatively simple, in terms of position, speed, and whether they are visual or not. Method, paint is the drawing method, reset is the reset (because the particles are to be recycled, to improve performance), isDrop is the particle falling method, update is the action to update the particles every frame, and when the particle moves beyond the drawing area of the canvas, its visualization is set to false and saved in the particle container waiting for the next call.
After you have written the particle object, you have to consider how to draw the particle according to its position, and allow the particle to animate freefall when it is not needed.
Draw the background first (that is, the white dot without pixels):
XML/HTML Code copies content to the clipboard
Function drawBg () {
Var tx = (canvas.width- ((P_radius*2+X_J) * 4*8+7*xjg)) / 2
For (var iTuno Bandi)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.