forked from edankwan/advanced_frontend_development_exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise_particles.html
144 lines (106 loc) · 3.09 KB
/
exercise_particles.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<html>
<head>
<meta charset="utf-8">
<title>Particle effect with three.js</title>
<meta name="viewport" content="initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link href='http://fonts.googleapis.com/css?family=Oswald:400' rel='stylesheet' type='text/css'>
<script src="//ajax.googleapis.com/ajax/libs/webfont/1.5.10/webfont.js"></script>
<style>
html, body {
position: absolute;
width: 100%;
height: 100%;
margin: 0 0;
overflow: hidden;
background-color: #000;
font-family: 'Oswald', sans-serif;
color: #fff;
}
a {
color: #ff5f5f;
}
</style>
</head>
<body>
<script src="js/dat.gui.js"></script>
<script src="js/three.js"></script>
<script src="js/TweenMax.js"></script>
<script id="shader-vs" type="x-shader/x-vertex">
// uniform mat4 modelViewMatrix;
// uniform mat4 projectionMatrix;
// attribute vec3 position;
attribute vec2 extras;
uniform vec2 uOffset;
void main() {
vec3 pos = position;
pos.xy += uOffset;
pos.y *= -1.0;
gl_Position = projectionMatrix * modelViewMatrix * vec4( pos, 1.0 );
gl_PointSize = 1.0;
}
</script>
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
void main() {
gl_FragColor = vec4(1.0);
}
</script>
<script>
var config = {
str: 'Edan Kwan',
fontSize: 120,
lineHeight: 1.4,
baseLine: 0.7
};
var windowWidth;
var windowHeight;
var renderer;
var scene;
var camera;
var geometry;
var material;
var mesh;
var fixedScale;
var canvas;
var ctx;
var width;
var height;
var gui;
function init() {
canvas = document.createElement('canvas');
ctx = canvas.getContext('2d');
document.body.appendChild(canvas);
gui = new dat.GUI();
gui.add(config, 'str').onChange(updateText);
updateText();
window.onresize = onResize;
onResize();
loop();
}
function updateText () {
var str = config.str;
ctx.font = config.fontSize + 'px Oswald';
var metrics = ctx.measureText(str);
width = canvas.width = Math.ceil(metrics.width) || 1;
height = canvas.height = Math.ceil(config.lineHeight * config.fontSize);
ctx.font = config.fontSize + 'px Oswald';
ctx.fillStyle = '#fff';
ctx.fillText(str, 0, config.lineHeight * config.fontSize *config.baseLine);
}
function onResize() {
windowWidth = window.innerWidth;
windowHeight = window.innerHeight;
render();
}
function loop() {
requestAnimationFrame(loop);
render();
}
function render() {
}
WebFont.load({google: {families: ['Oswald']}, active: init});
</script>
</body>
</html>