forked from xcatliu/rose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
166 lines (152 loc) · 5.2 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="x-ua-compatible" content="ie=edge"/>
<title>Rose</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<style>
html, body {
width: 100%;
height: 100%;
}
body, pre {
margin: 0;
padding: 0;
color: #333;
font-family: PingFang SC, Lantinghei SC, Microsoft Yahei, Hiragino Sans GB, Microsoft Sans Serif, WenQuanYi Micro Hei, sans;
}
body {
font-size: 16px;
line-height: 1.5em;
overflow: hidden;
margin: 0 auto;
}
button, input {
color: #333;
border: 1px solid #ccc;
background-color: #f2f2f2;
font-size: 1.5em;
line-height: 1.5em;
padding: 0.2rem 0.5em;
box-sizing: border-box;
border-radius: 0;
box-shadow: none;
}
#content {
z-index: 10;
position: relative;
overflow: auto;
}
#content pre {
margin: 1rem 0;
line-height: 1.8em;
font-size: 1.8em;
text-align: center;
}
.canvas-container {
position: absolute;
bottom: 0;
width: 100%;
line-height: 0;
}
.create-button {
position: absolute;
top: 0;
right: 0;
opacity: 0.5;
font-size: 1.2em;
}
.create-form {
margin: 1rem 2rem;
}
.create-form input {
margin: 0.5rem 0;
width: 100%;
}
</style>
</head>
<body>
<div id="content"></div>
<div class="canvas-container"><canvas height=256 width=200></canvas></div>
<script>
// http://js1k.com/2012-love/demo/1100
// http://js1k.com/2012-love/demo/1022
var c = document.getElementsByTagName("canvas")[0];
var a = c.getContext("2d");
with(m=Math)C=cos,S=sin,P=pow;O=a.getImageData(0,0,c.height=f=W=256,f);U=O.data;D={};F=[];function J(p){p[5]=Q=0;for(j=3;j--;)if(!D[Q=(p[j]>>=2)+Q*f])D[Q]=F.push(p)}setInterval(function(){for(i=1e3;i--;){c=i%42*1.35;H=T;T=m.random();A=H*2-1;B=T*2-1;J([S(H*7)*(o=13+5/(.2+P(T*4,4)))-T*50,T*550+500,(l=C(H*7))*o,(G=l/7+.5)-T/4,G]);if(A*A+B*B<1)if(c>32){J([(o=.5/(H+.01)-H*300)*C(n=(j=c&1)?6:4)+(w=T*-f)*S(n)+j*630-390,o*S(n)-w*C(n)+999-j*350,C(B+A)*99-j*50,(P(l=1-B*B,f*6)+C(H+T)+P(C((o*H+o+(B>0?w:-w))/25),30)*l-H+2)/5,o/1e3+.7-o*w/3e5]);J([(o=H*45-20)*C(l=c/.86)+(w=T*T)*f*S(l),C(B/2)*99-w*T*60+436,o*S(l)-w*f*C(l),w*.3+.3,T*.7])}else J([(o=A*(2-T)*(80-c*2))*C(c)-(w=99-C(A)*120-C(T)*(f-c*5)+C(P(1-T,7))*50+c*2)*S(c),(B*2-C(P(T,7))+9)*50,o*S(c)+w*C(c),1-T*.7,P(1-T,9)/4])}for(i=0;i<f*f;m[i++]=f)for(l=4;l--;)U[i*4+l]=255;for(c=C(W),s=S(W),j=F.length;j--;){k=F[j],x=k[0]*c+k[2]*s+99,z=k[0]*s-k[2]*c,y=k[1]-z*.4<<8;for(i=3;i--;)if(z<m[p=y-~x+[0,1,f][i]])for(m[p]=z,l=3;l--;)U[p*4+l]=k[l+3]*f}a.putImageData(O,0,0);W+=.03},T=0)
// http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
var urlParams;
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
if (window.document.body.clientWidth > window.document.body.clientHeight / 1.6) {
window.document.body.style.width = window.document.body.clientHeight / 1.6 + 'px';
}
var SCALE = window.document.body.clientWidth / 200;
c.style.transform = 'scale(' + SCALE + ')';
c.style.transformOrigin = '0% 100%';
c.style.WebkitTransform = 'scale(' + SCALE + ')';
c.style.WebkitTransformOrigin = '0% 100%';
// http://www.w3cfuns.com/blog-5445837-5399730.html
function prints(target, str, speed) {
var timer = null;
var count = 0;
timer = setInterval(function() {
if (count > str.length) {
clearInterval(timer);
} else {
target.innerHTML = str.substring(0, count);
count++;
}
}, speed);
}
var content = document.getElementById('content');
var lines = [urlParams.line0, urlParams.line1, urlParams.line2];
if (lines[0] && lines[1] && lines[2]) {
var pre = document.createElement('pre');
content.appendChild(pre);
prints(pre, lines.join('\n'), 200);
setTimeout(function() {
var createButton = document.createElement('button');
createButton.className = 'create-button';
createButton.innerHTML = 'Create';
content.appendChild(createButton);
createButton.addEventListener('click', function(e) {
e.preventDefault();
window.location.href = window.location.pathname;
});
}, 3000);
} else {
var form = document.createElement('form');
form.method = 'GET';
form.className = 'create-form';
lines.forEach(function(line, index) {
var lineInput = document.createElement('input');
lineInput.type = 'text';
lineInput.name = 'line' + index;
lineInput.placeholder = 'line' + index;
form.appendChild(lineInput);
});
var submitButton = document.createElement('input');
submitButton.type = 'submit';
submitButton.value = 'Submit';
form.appendChild(submitButton);
content.appendChild(form);
}
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-45256157-5', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>