/
index.html
81 lines (71 loc) · 2.08 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>GLSL Example No.014</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<script id="vs" type="x-shader/x-vertex">
attribute vec3 position;
attribute vec2 textureCoord;
varying vec2 vTextureCoord;
void main()
{
vTextureCoord = textureCoord;
gl_Position = vec4(position, 1.0);
}
</script>
<script id="fs" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D texture;
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
varying vec4 vColor;
varying vec2 vTextureCoord;
const vec3 black = vec3(0.0, 0.0, 0.0);
const vec3 white = vec3(1.0, 1.0, 1.0);
const vec3 beige = vec3(1.0, 0.8, 0.8);
const vec3 orange = vec3(1.0, 0.5, 0.0);
const vec3 brown = vec3(0.5, 0.0, 0.0);
const vec3 red = vec3(1.0, 0.0, 0.0);
const vec3 yellow = vec3(1.0 ,1.0, 0.0);
const vec3 green = vec3(0.0, 1.0, 0.0);
const vec3 water = vec3(0.0, 1.0, 1.0);
const vec3 blue = vec3(0.0, 0.0, 1.0);
const vec3 purple = vec3(0.5, 0.0, 0.5);
const vec3 indigo = vec3(0.1, 0.1, 0.5);
void rainbow(vec2 p, vec2 offset, float size, inout vec3 i) {
float l = length(p - offset);
if (l < size ) {
if (l > (size * 9.0/10.0) ) {
i = red;
} else if (l > (size * 8.0/10.0) ) {
i = orange;
} else if (l > (size * 7.0/10.0) ) {
i = yellow;
} else if (l > (size * 6.0/10.0) ) {
i = green;
} else if (l > (size * 5.0/10.0) ) {
i = blue;
} else if (l > (size * 4.0/10.0) ) {
i = indigo;
} else if (l > (size * 3.0/10.0) ) {
i = purple;
}
}
}
void main( void ) {
vec3 destColor = black;
vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y);
rainbow (p, vec2( 0.0, 0.0), 1.0, destColor);
vec2 uv = vTextureCoord;
vec4 color = texture2D(texture, uv);
destColor.rgb += color.rgb;
gl_FragColor = vec4(destColor, 1.0);
}
</script>
<canvas id="c" width="465" height="465"></canvas>
<script src="index.js"></script>
</body>
</html>