-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpooklm.html
283 lines (217 loc) · 7.99 KB
/
pooklm.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<link rel="apple-touch-icon" type="image/png" href="https://cpwebassets.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png" />
<meta name="apple-mobile-web-app-title" content="CodePen">
<link rel="shortcut icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico" />
<link rel="mask-icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/logo-pin-8f3771b1072e3c38bd662872f6b673a722f4b3ca2421637d5596661b4e2132cc.svg" color="#111" />
<title>CodePen - Click and draw some flowers</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<style>
body{--t:.5; --scale:3;}
svg.root{width:1px;height:1px;position:absolute;left:-100em;}
svg{
width: 100vw;
height: 100vh;
background:#c5d9fe;
fill-opacity:0.75;
}
symbol{overflow:visible}
svg use{transform:rotate(0deg)); transition:transform calc(var(--t) * 1s);}
svg g.a{transition:transform calc(var(--t) * 1s);}
svg g.a{transform:scale(var(--scale)) rotate(-90deg);
filter:url('#f')
}
._2{--n : 2;}
._3{--n : 3;}
._4{--n : 4;}
._5{--n : 5;}
svg .a g:nth-of-type(1){transform:rotate(calc(-.5 * 180deg / var(--n)));}
svg .a g:nth-of-type(2){transform:rotate(calc( .5 * 180deg / var(--n)));}
svg .a g:nth-of-type(1) use:nth-of-type(2){transform:rotate(calc(-1deg * 180 / var(--n)));}
svg .a g:nth-of-type(1) use:nth-of-type(3){transform:rotate(calc(-2deg * 180 / var(--n)));}
svg .a g:nth-of-type(1) use:nth-of-type(4){transform:rotate(calc(-3deg * 180 / var(--n)));}
svg .a g:nth-of-type(1) use:nth-of-type(5){transform:rotate(calc(-4deg * 180 / var(--n)));}
svg .a g:nth-of-type(2) use:nth-of-type(2){transform:rotate(calc(1deg * 180 / var(--n)));}
svg .a g:nth-of-type(2) use:nth-of-type(3){transform:rotate(calc(2deg * 180 / var(--n)));}
svg .a g:nth-of-type(2) use:nth-of-type(4){transform:rotate(calc(3deg * 180 / var(--n)));}
svg .a g:nth-of-type(2) use:nth-of-type(5){transform:rotate(calc(4deg * 180 / var(--n)));}
</style>
<script>
if (document.location.search.match(/type=embed/gi)) {
window.parent.postMessage("resize", "*");
}
</script>
</head>
<body translate="no" >
<svg class="root">
<defs>
<filter id="f" width="200" height="200" x="-100" y="-100" >
<feGaussianBlur in="SourceAlpha" stdDeviation="3" result="blur"></feGaussianBlur>
<feFlood flood-color="rgb(60,10,60)" result="color"/>
<feComposite in="color" in2="blur" operator="in" result="shadow" />
<feOffset in="shadow" dx="3" dy="3" result="offset"></feOffset>
<feMerge>
<feMergeNode in="offset" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
<symbol id="petal2" viewBox = "0 -100 200 200" >
<!--<polygon points="0,0 120,80 200,0 120,-80 0,0" />-->
<path transform="translate(0,-100)" d="M25.91,-15.12 Q0,0 25.91,15.12L94.09,54.889 Q120,70 142.58,50.24L177.42,19.76 Q200,0 177.42,-19.756L142.58,-50.24 Q120,-70 94.087,-54.88Z"></path>
</symbol>
<symbol id="petal3" viewBox = "0 -100 200 200" >
<!--<polygon points="0,0 120,50 200,0 120,-50 0,0" />-->
<path transform="translate(0,-100)" d="M27.69,-11.54 Q0,0 27.69,11.54 L92.3,38.46 Q120,50 145.44,34.1 L174.56,15.9 Q200,0 174.56,-15.9 L145.44,-34.1 Q120,-50 92.3,-38.46Z" ></path>
</symbol>
<symbol id="petal4" viewBox = "0 -100 200 200" >
<!--<polygon points="0,0 120,50 200,0 120,-50 0,0" />-->
<path transform="translate(0,-100)" d="M28.09,-10.53 Q0,0 28.09,10.53L91.91,34.47 Q120,45 146.147,30.29L173.85,14.7 Q200,0 173.85,-14.7L146.15,-30.29 Q120,-45 91.91,-34.467Z"></path>
</symbol>
<symbol id="petal5" viewBox = "0 -100 200 200" >
<!--<polygon points="0,0 140,40 200,0 140,-40 0,0" />-->
<path transform="translate(0,-100)" d="M28.85,-8.24 Q0,0 28.85,8.24L111.15,31.76 Q140,40 164.96,23.36L175.04,16.64 Q200,0 175.038,-16.64L164.96,-23.36 Q140,-40 111.15,-31.76Z"></path>
</symbol>
</defs>
</svg>
<svg viewBox="0 0 10000 10000" id="svg" preserveAspectRatio="xMidYMid slice">
</svg>
<script src="https://cpwebassets.codepen.io/assets/common/stopExecutionOnTimeout-1b93190375e9ccc259df3a57c1abc0e64599724ae30d7ea4c6877eb615f89387.js"></script>
<script id="rendered-js" >
const SVG_NS = "http://www.w3.org/2000/svg";
const SVG_XLINK = "http://www.w3.org/1999/xlink";
let rid = null;
let gon = 7; // 3,4,5,6....
const colors = [
"#ba3763",
"#d34076",
"#dbb0cc",
"#fddafa",
"#fef2fe",
"#eec0db",
"#ca809a",
"#e9d8e8"];
let m = { x: 0, y: 0 };
let previous = { x: 0, y: 0 };
let scale = 1;
let bool = false;
class Flower {
constructor(n, pos, scale, parent) {
this.n = n;
this.scale = scale;
this.pos = pos;
this.width = 40;
this.height = 40;
this.color = colors[~~(Math.random() * colors.length)];
this.parent = parent;
this.markup();
}
markup() {
this.G = document.createElementNS(SVG_NS, "g");
this.G.setAttribute("style", `--scale:${this.scale};`);
let rot = ~~(Math.random() * 180);
this.G.setAttributeNS(
null,
"transform",
`translate(${this.pos.x},${this.pos.y}) rotate(${rot})`);
this.G.setAttributeNS(null, "fill", this.color);
let ga = document.createElementNS(SVG_NS, "g");
ga.setAttribute("class", "a");
for (let i = 0; i < 2; i++) {
// left, right
let g = document.createElementNS(SVG_NS, "g");
for (let j = 0; j < this.n; j++) {
let use = document.createElementNS(SVG_NS, "use");
use.setAttributeNS(SVG_XLINK, "xlink:href", `#petal${this.n}`);
use.setAttributeNS(null, "width", this.width);
use.setAttributeNS(null, "height", this.height);
g.appendChild(use);
}
ga.appendChild(g);
}
this.G.appendChild(ga);
this.parent.appendChild(this.G);
}}
svg.addEventListener("mousedown", e => {
// clear the canvas
while (svg.lastChild) {
svg.removeChild(svg.lastChild);
}
// if bool == true I can draw
bool = true;
});
svg.addEventListener("mouseup", e => {
bool = false;
previous = {};
});
svg.addEventListener("mousemove", e => {
if (bool) {
m = oMousePosSVG(e);
// number of petals
let n = 2 + ~~(Math.random() * 4);
// set the scale
if (previous.x) {
let d = dist(m, previous);
scale = d / 30;
} else {
scale = 1;
}
let flower = new Flower(n, { x: m.x, y: m.y }, scale, svg);
setTimeout(() => {
flower.G.setAttribute("class", `_${flower.n}`);
}, 50);
previous.x = m.x;
previous.y = m.y;
} //if bool
});
function oMousePosSVG(e) {
var p = svg.createSVGPoint();
p.x = e.clientX;
p.y = e.clientY;
var ctm = svg.getScreenCTM().inverse();
var p = p.matrixTransform(ctm);
return p;
}
function dist(p1, p2) {
let dx = p2.x - p1.x;
let dy = p2.y - p1.y;
return Math.sqrt(dx * dx + dy * dy);
}
///////// Initial polygon //////////////
function algorithmPoly(gon, R) {
let points = [];
for (let a = 0; a < 2 * Math.PI; a += 0.1) {
let r =
R *
Math.cos(Math.PI / gon) /
Math.cos(a % (2 * Math.PI / gon) - Math.PI / gon);
let x = 5000 + r * Math.cos(a);
let y = 5000 + r * Math.sin(a);
points.push({ x: x, y: y, r: 5 });
}
return points;
}
let points = algorithmPoly(gon, 2500);
let frames = 0;
function Frame() {
rid = window.requestAnimationFrame(Frame);
if (frames >= points.length) {
window.cancelAnimationFrame(rid);
rid = null;
}
m = points[frames];
let n = 2 + ~~(Math.random() * 4);
scale = ~~(Math.random() * 12) + 3;
let flower = new Flower(n, { x: m.x, y: m.y }, scale, svg);
setTimeout(() => {
flower.G.setAttribute("class", `_${flower.n}`);
}, 50);
frames++;
}
Frame();
//# sourceURL=pen.js
</script>
<script src="https://cpwebassets.codepen.io/assets/editor/iframe/iframeRefreshCSS-4793b73c6332f7f14a9b6bba5d5e62748e9d1bd0b5c52d7af6376f3d1c625d7e.js"></script>
</body>
</html>