Skip to content

Commit 3011e29

Browse files
author
Jinhua Wang
committed
bd
1 parent 2bb7c79 commit 3011e29

18 files changed

+887
-0
lines changed

README.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
A Pen created at CodePen.io. You can find this one at https://codepen.io/arcs/pen/XKKYZW.
2+
3+

css/style.css

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
body {
2+
margin: 0;
3+
background: #020202;
4+
cursor: crosshair;
5+
}
6+
canvas{display:block}
7+
h1 {
8+
position: absolute;
9+
top: 20%;
10+
left: 50%;
11+
transform: translate(-50%, -50%);
12+
color: #fff;
13+
font-family: "Source Sans Pro";
14+
font-size: 5em;
15+
font-weight: 900;
16+
-webkit-user-select: none;
17+
user-select: none;
18+
}

index.html

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en" >
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Happy Birthday</title>
7+
8+
9+
<link rel='stylesheet prefetch' href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:900'>
10+
11+
<link rel="stylesheet" href="css/style.css">
12+
13+
14+
</head>
15+
16+
<body>
17+
18+
<h1>Happy Birthday <br> 罗羽丝小盆友</h1>
19+
<canvas id="birthday"></canvas>
20+
21+
22+
23+
<script src="js/index.js"></script>
24+
25+
26+
27+
28+
</body>
29+
30+
</html>

js/index.js

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
'use strict'
2+
3+
const PI2 = Math.PI * 2
4+
let random = (min, max) => Math.random() * (max - min + 1) + min | 0
5+
6+
class Birthday {
7+
constructor() {
8+
this.resize()
9+
10+
// create a lovely place to store the firework
11+
this.fireworks = []
12+
this.counter = 0
13+
14+
}
15+
resize() {
16+
this.width = canvas.width = window.innerWidth
17+
let center = this.width / 2 | 0
18+
this.spawnA = center - center / 4 | 0
19+
this.spawnB = center + center / 4 | 0
20+
21+
this.height = canvas.height = window.innerHeight
22+
this.spawnC = this.height * .1
23+
this.spawnD = this.height * .5
24+
25+
}
26+
onClick(evt) {
27+
let x = evt.clientX || evt.touches && evt.touches[0].pageX
28+
let y = evt.clientY || evt.touches && evt.touches[0].pageY
29+
30+
let count = random(3,5)
31+
for(let i = 0; i < count; i++) this.fireworks.push(new Firework(
32+
random(this.spawnA, this.spawnB),
33+
this.height,
34+
x,
35+
y,
36+
random(300, 450),
37+
random(30, 110)))
38+
39+
this.counter = -30
40+
41+
}
42+
update() {
43+
ctx.globalCompositeOperation = 'hard-light'
44+
ctx.fillStyle = 'rgba(20,20,20,0.15)'
45+
ctx.fillRect(0, 0, this.width, this.height)
46+
47+
ctx.globalCompositeOperation = 'lighter'
48+
for (let firework of this.fireworks) firework.update()
49+
50+
// if enough time passed... create new new firework
51+
if (++this.counter === 15) {
52+
this.fireworks.push(new Firework(
53+
random(this.spawnA, this.spawnB),
54+
this.height,
55+
random(0, this.width),
56+
random(this.spawnC, this.spawnD),
57+
random(300, 450),
58+
random(30, 110)))
59+
this.counter = 0
60+
}
61+
62+
// remove the dead fireworks
63+
if (this.fireworks.length > 1000) this.fireworks = this.fireworks.filter(firework => !firework.dead)
64+
65+
}
66+
}
67+
68+
class Firework {
69+
constructor(x, y, targetX, targetY, shade, offsprings) {
70+
this.dead = false
71+
this.offsprings = offsprings
72+
73+
this.x = x
74+
this.y = y
75+
this.targetX = targetX
76+
this.targetY = targetY
77+
78+
this.shade = shade
79+
this.history = []
80+
}
81+
update() {
82+
if (this.dead) return;
83+
84+
let xDiff = this.targetX - this.x
85+
let yDiff = this.targetY - this.y
86+
if (Math.abs(xDiff) > 3 || Math.abs(yDiff) > 3) { // is still moving
87+
this.x += xDiff / 20
88+
this.y += yDiff / 20
89+
90+
this.history.push({
91+
x: this.x,
92+
y: this.y
93+
})
94+
95+
if (this.history.length > 20) this.history.shift()
96+
97+
} else {
98+
if (this.offsprings && !this.madeChilds) {
99+
100+
let babies = this.offsprings / 2;
101+
for (let i = 0; i < babies; i++) {
102+
let targetX = this.x + this.offsprings * Math.cos(PI2 * i / babies) | 0
103+
let targetY = this.y + this.offsprings * Math.sin(PI2 * i / babies) | 0
104+
105+
birthday.fireworks.push(new Firework(this.x, this.y, targetX, targetY, this.shade, 0))
106+
107+
}
108+
109+
}
110+
this.madeChilds = true
111+
this.history.shift()
112+
}
113+
114+
if (this.history.length === 0) this.dead = true
115+
else if (this.offsprings) {
116+
for (let i = 0; this.history.length > i; i++) {
117+
let point = this.history[i]
118+
ctx.beginPath()
119+
ctx.fillStyle = 'hsl(' + this.shade + ',100%,' + i + '%)'
120+
ctx.arc(point.x, point.y, 1, 0, PI2, false)
121+
ctx.fill()
122+
}
123+
} else {
124+
ctx.beginPath()
125+
ctx.fillStyle = 'hsl(' + this.shade + ',100%,50%)'
126+
ctx.arc(this.x, this.y, 1, 0, PI2, false)
127+
ctx.fill()
128+
}
129+
130+
}
131+
}
132+
133+
let canvas = document.getElementById('birthday')
134+
let ctx = canvas.getContext('2d')
135+
136+
let birthday = new Birthday
137+
window.onresize = () => birthday.resize()
138+
document.onclick = evt => birthday.onClick(evt)
139+
document.ontouchstart = evt => birthday.onClick(evt)
140+
141+
;(function update() {
142+
requestAnimationFrame(update)
143+
birthday.update()
144+
145+
}())

license.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
<!--
4+
Copyright (c) 2018 by Patrick Stillhart (https://codepen.io/arcs/pen/XKKYZW)
5+
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
-->

old/CNAME

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

old/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ginward.github.io
2+
3+
The MIT License (MIT) Copyright (c) Jinhua Wang <2016>
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

old/about.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
<head>
3+
4+
</head>
5+
6+
<body>
7+
8+
I wrote this app in the hope that people can understand weather information in 5 seconds rather than reading through a bunch of useless information.
9+
<br><br>
10+
It is in Chinese, because I am too lazy to make two versions. But feel free to adapt it, as the source code is released under the MIT License.
11+
<br><br>
12+
Thanks to icons8.com for their free icons.
13+
<br><br>
14+
15+
The MIT License (MIT)
16+
Copyright (c) <2016> <JINHUA WANG>
17+
<br>
18+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
19+
<br>
20+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
21+
<br>
22+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
</body>

old/deprecated.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<meta name="viewport" content="width=device-width, initial-scale=1">
3+
<meta charset="utf-8" />
4+
<title>龙王宝宝</title>
5+
<head>
6+
<script src="https://code.jquery.com/jquery-3.0.0.min.js" integrity="sha256-JmvOoLtYsmqlsWxa7mDSLMwa6dZ9rrIdtrrVYRnDRH0=" crossorigin="anonymous"></script>
7+
<script src="./weather.js" type="text/javascript"></script>
8+
</head>
9+
10+
<body style="background-color:#f3f5f7">
11+
<div id="main" style="text-align:center;font-family:Arial, Helvetica, sans-serif">
12+
<div style="margin-top:5%;"></div>
13+
<div id="loading"><span>奋力加载中...</span></div>
14+
<div id="city_name" style="margin-top:3%"></div>
15+
</div>
16+
</body>

0 commit comments

Comments
 (0)