-
Notifications
You must be signed in to change notification settings - Fork 0
/
greensweep.html
127 lines (115 loc) · 3.81 KB
/
greensweep.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
<!-- https://bkimmel.github.io/ -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Greensweep</title>
<meta name="description" content="Sample page">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
h1 {
text-align: center;
}
svg {
display: block;
width: 50%;
height: 40vh;
outline: 1px solid red;
margin: 20px auto;
}
svg rect {
fill: #00FF00;
stroke: red;
stroke-width: 5px;
}
svg circle {
fill: url(#GREEN_COVER);
stroke: red;
stroke-width: 5px;
}
svg text {
font-family: Helvetica, sans-serif;
text-anchor: middle;
}
svg text.display {
fill: #00FF00;
stroke: #00FF00;
stroke-width: 0px;
font-family: Helvetica, sans-serif;
font-kerning: normal;
font-size: 1.3em;
}
svg.filter circle {
filter: url(#GreenWash);
}
svg.filter image {
filter: url(#GreenWash);
}
img {
filter: url(#GreenWash);
}
</style>
</head>
<body>
<h1>GreenSweep Example</h1>
<svg class="normal" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet">
<defs>
<radialGradient id="GREEN_COVER"
r="70%"
spreadMethod="pad">
<stop offset="0%" stop-color="#00ff00" stop-opacity="1"/>
<stop offset="100%" stop-color="#000000" stop-opacity="1" />
</radialGradient>
<filter id="GreenWash">
<feColorMatrix data-at=".4" type="matrix" values=
"1 0 0 0 0,
0 1 0 0 0,
0 0 1 0 0,
0 0 0 0 -1"
in="SourceGraphic" result="GREEN_LOWERBOUND" />
<feComposite operator="in" in="SourceGraphic" in2="GREEN_LOWERBOUND"/>
</filter>
</defs>
<text x="50" y="13">Normal</text>
<circle cx="50" cy="50" r="30" />
</svg>
<svg class="filter" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet">
<text x="50" y="13">With Sweeping Filter:</text>
<circle cx="50" cy="50" r="30" />
</svg>
<svg style="width: 90%; height: 65vh;" class="filter" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet">
<text x="50" y="13">Image With Sweeping Filter:</text>
<image x="0" y="0" width="100" height="100" xlink:href="http://assets.worldwildlife.org/photos/946/images/story_full_width/forests-why-matter_63516847.jpg?1345534028" />
</svg>
<img src="http://assets.worldwildlife.org/photos/946/images/story_full_width/forests-why-matter_63516847.jpg?1345534028" style="width: 80%; max-width: 2000px; height: auto; display: block; margin: 0 auto;">
<script>
var sweepmatrix = document.querySelector('#GreenWash [result="GREEN_LOWERBOUND"]');
var sweepval = 0;
function sweepGreenTo(n){
//console.log(n)
sweepmatrix.setAttribute('values', '1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 ' + 5*n + ' 0 0 ' + (n) );
}
var anframe = null;
function linearSweep(duration, fromval, tgtval){
cancelAnimationFrame(anframe);
var t = Date.now();
var tgt = t + duration;
var len = tgt - t;
var dist = tgtval - fromval;
anframe = requestAnimationFrame(function sweeper(){
if(t >= tgt){
sweepGreenTo(tgtval);
return true;
}
t = Date.now();
var progresspct = 1 - ((tgt - t)/len);
sweepGreenTo( fromval + ( progresspct * dist ) );
requestAnimationFrame(sweeper);
})
}
setTimeout(function(){ linearSweep(7000, 0, 1) }, 2000);
setTimeout(function(){ linearSweep(7000, 1, 0) }, 10000);
setInterval(function(){ linearSweep(7000, 0, 1); setTimeout(function(){ linearSweep(7000, 1, 0) }, 8000); }, 18000);
</script>
</body>
</html>