-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
444 lines (435 loc) · 16 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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<html>
<head>
<title>SpriteMeister</title>
<script src="console.js"></script>
<script src="elements.spritecreator.js"></script>
<script src="element.js"></script>
<!-- -------------------------------------------------------- template hamarrow1 -->
<template spritemeister id="hamburger_arrow1" duration="4s">
${ setv1( round({value:40-ease({distance:25})}) , "top and bottom X position" ) ,
setv2( ease({distance:20}) , "top and bottom line to Y=50" )
}
<g stroke="black" stroke-width="8" stroke-linecap="round" transform="${rotate(180-ease({distance:180}))}">
<path d="M${v1} 30L85 ${50 - v2}"></path>
<path d="M15 50L85 50"></path>
<path d="M${v1} 70L85 ${50 + v2}"></path>
</g>
</template>
<!-- -------------------------------------------------------- template hamarrow2 -->
<template spritemeister id="hamarrow2" duration="4s">
<g stroke="lightcoral" stroke-width="8" stroke-linecap="round">
<path d="M15 30L85 30"></path>
<path d="M15 50L85 50"></path>
<path d="M85 70L15 70"></path>
</g>
<g stroke="green" stroke-width="8" stroke-linecap="round">
<path d="M50 70L20 50"></path>
<path d="M75 50L20 50"></path>
<path d="M50 30L20 50"></path>
</g>
${setv1(arcpath({start:[15,30],end:[50,30],control:[40,15],color:3}))}
${setv2(arcpath({start:[85,30],end:[20,50],control:[85,60,20,80],color:4}))}
${setv3(arcpath({start:[15,50],end:[75,50],control:[50,20],color:1}))}
${setv4(arcpath({start:[85,50],end:[20,50],control:[50,70],color:2}))}
${setv5(arcpath({start:[85,70],end:[20,50],control:[30,90],color:5}))}
${setv6(arcpath({start:[15,70],end:[50,70],control:[40,40],color:6}))}
<g stroke="black" stroke-width="8" stroke-linecap="round">
<path d="M${v1.x} ${v1.y}L${v2.x} ${v2.y}"></path>
<path d="M${v3.x} ${v3.y}L${v4.x} ${v4.y}"></path>
<path d="M${v5.x} ${v5.y}L${v6.x} ${v6.y}"></path>
</g>
</template>
<!-- -------------------------------------------------------- template fbthumb -->
<template spritemeister id="fbthumb" duration="1s">
<circle cx="50" cy="50" r="40" fill="royalblue"></circle>
<path
transform="rotate(${ease({distance:-15})} 50 50)"
fill="white"
d="m32 45h-8c-1 0-2 1-2 2v24c0 1 1 2 2 2h8c1 0 2-1 2-2v-23c0-1-1-2-2-3zm-4 25c-1 0-2-1-2-2s1-2 2-2s2 1 2 2s-1 2-2 2zm32-39c0 4-3 7-3 9h10c3 0 6 3 6 6c0 2-1 4-2 5l0 0c1 2 1 6-1 8c1 3 0 6-2 7c0 2 0 3-1 4c-1 4-6 4-10 4l0 0c-5 0-9-2-12-3c-2-1-4-2-5-2c-1 0-1-1-1-1v-21c0 0 0-1 0-1c4-4 6-8 9-11c1-1 2-4 3-6c-1-2 0-6 2-6c2 0 7 1 7 8z"
></path>
</template>
<!-- -------------------------------------------------------- template laugh -->
<template spritemeister id="laugh">
<g transform="translate(0 ${ease({distance:8})})">
<circle cx="50" cy="45" r="45" fill="lightblue"></circle>
<path d="M10 ${50 - ease({distance:2})} a1 ${.5 + ease({distance:.3})} 0 0 0 80 0a3 -.5 0 0 0 -80 0"></path>
<path id="eye${framenr}" d="M15 35 a1 ${1 - ease({distance:.5})} 0 0 1 20 0a3 -1 0 0 0 -20 0"></path>
<use href="#eye${framenr}" x="50"></use>
</g>
</template>
<!-- -------------------------------------------------------- template brokenheart -->
<template spritemeister id="brokenheart" duration="3s">
<g fill="red">
<path
transform="rotate(${pulse({mid:-10})} 47 85)"
d="M47 20c0 0 0 0 0 0c-4-5-11-8-18-8c-12 0-22 10-22 22c0 15 14 27 34 46l6 5l0 0l-1-1l3-4l-4-5l5-7l-7-8l9-9l-8-6l8-9l-11-8l6-8z"
></path>
<path
transform="rotate(${pulse({mid:10})} 47 85)"
d="M47 20c1-1 1-1 2-2l2-1c4-3 9-5 14-5c12 0 22 10 22 22c0 15-14 27-34 46l-6 5l-1-1l3-4l-4-5l5-7l-7-8l9-9l-8-6l8-9l-11-8l6-8z"
></path>
</g>
<circle cx="47" cy="85" r="5" fill="none" stroke="blue"></circle>
<text y="12">n:${framenr}</text>
</template>
<!-- -------------------------------------------------------- template bounce -->
<template spritemeister id="bounce" duration="1s" steps="24">
<ellipse
cx="50"
cy="${70 - ease({distance:36})}"
rx="${ framenr > 11 ? minmax({value:30,min:41 - ease({distance:10})}) : 30}"
ry="${minmax({value:30,min:30 - ease({distance:30})})}"
fill="none"
stroke="black"
stroke-width="5"
></ellipse>
<text y="12">n:${framenr}</text>
</template>
<!-- -------------------------------------------------------- template adjust -->
<template spritemeister id="adjust" duration="3s">
${
v1=10,
v2=90,
v3=20,
v4=20,
v5='black',
v6=60,
v7='grey',
v8='fill=\'green\''
}
<g stroke="${v5}" stroke-width="4" stroke-linecap="round">
<line x1="${v3}" y1="${v1}" x2="${v4}" y2="${v2}"></line>
<line x1="${v3+25}" y1="${v1}" x2="${v4+25}" y2="${v2}"></line>
<line x1="${v3+50}" y1="${v1}" x2="${v4+50}" y2="${v2}"></line>
</g>
<rect
id="knob"
x="10"
y="${15+ease({distance:v6})}"
width="20"
height="10"
stroke-width="2"
stroke="${v7}"
rx="3"
ry="3"
${v8}
></rect>
<use href="#knob" x="25" y="${-ease({distance:v6})}"></use>
<use href="#knob" x="50" y="${framenr > 10 ? -v6 + ease({distance:v6}) : -10}"></use>
</template>
<!-- -------------------------------------------------------- template battery -->
<template spritemeister id="battery">
<path
stroke-width="5"
d="m-6 42c0 0-6 0-6 0c0 0 0-8 0-8c0-4-4-8-8-8c0 0-66 0-66 0c-4 0-8 4-8 8c0 0 0 32 0 32c0 4 4 8 8 8c0 0 66 0 66 0c4 0 8-4 8-8c0 0 0-8 0-8c0 0 6 0 6 0c0 0 0-16 0-16z"
stroke="black"
fill="none"
></path>
${ setv1( 34 ) , setv2( 64 ) }
<g stroke="green" stroke-width="5" stroke-linecap="round">
<line x1="15" y1="${v1}" x2="15" y2="${v2}"></line>
<line x1="25" y1="${v1}" x2="25" y2="${v2}" opacity="${pulse({start:0.75,mid:1})}"></line>
<line x1="35" y1="${v1}" x2="35" y2="${v2}" opacity="${pulse({start:0.50,mid:1})}"></line>
<line x1="45" y1="${v1}" x2="45" y2="${v2}" opacity="${pulse({start:0.25,mid:1})}"></line>
<line x1="55" y1="${v1}" x2="55" y2="${v2}" opacity="${pulse({start:0,mid:1})}"></line>
</g>
</template>
<!-- -------------------------------------------------------- template pacman -->
<template spritemeister id="pacman" duration=".5s" steps="24">
${ setv1( pulse({mid:45}) ,"rotation" ),
setv2( ease({distance:1}) ,"squint eye")
}
<g fill="yellow">
<g transform="rotate(${ -v1 } 50 50)">
<path d="m90 50a1 1 0 0 0 -80 0"></path>
<ellipse cx="60" cy="30" rx="${5 + v2}" ry="${5 - v2}" fill="black"></ellipse>
</g>
<path transform="rotate(${v1} 50 50)" d="m10 50a1 1 0 0 0 80 0"></path>
</g>
<text y="99">n:${framenr}</text>
</template>
<!-- -------------------------------------------------------- template ghost -->
<template spritemeister id="ghost" duration=".5s" steps="24" ghostcolor="hotpink">
${ setv1( ease({distance:1}) ,"squeeze eyes" ),
setv2( ease({distance:1}) ,"bounce eyes" ),
setv3( pulse({mid:1}) ,"bounce ghost" ),
setv4( pulse({start:5,mid:10}) ,"wiggle skirt" ),
setv7( ease({distance:10}) ,"curve cloak" )
}
<g transform="skewY(${v3})">
<path fill="${attr('ghostcolor','red')}"
d="M82 94 c${7 - v7}-13 4-44 1-65s-40-55-63-1 c${-7 - v7} 22-7 53-3 66
l${v4}-11 l7 11l8-13l8 13l8-12l8 12l7-12z"></path>
<g id="eye${framenr}" transform="translate(0 ${v2})">
<ellipse cx="${58 + v1}" cy="${30 + v1}" rx="${5 + v1}" ry="${5 - v1}" fill="white"></ellipse>
<ellipse cx="${60 + v1}" cy="${30 + v1}" rx="${1 + v1}" ry="${2 - v1}" fill="black"></ellipse>
</g>
<use x="0" y="36" href="#eye${framenr}" transform="rotate(180 50 50)"></use>
</g>
<text y="12">n:${framenr} </text>
</template>
<!-- -------------------------------------------------------- template SPRITE-SOURCE -->
<template id="SPRITE-SOURCE">
<style>
:host {
display: inline-block;
}
textarea {
width: var(--editorWidth, 95vw);
height: var(--editorEditHeight, var(--editorHeight, 9em));
font-size: var(--editorFontSize, 1em);
background: var(--editorBackground);
}
</style>
<h3><slot name="title"></slot></h3>
<textarea></textarea>
</template>
<!-- -------------------------------------------------------- template FILM-STRIP -->
<template id="SPRITE-FILMSTRIP">
<style>
:host {
--duration: 2s;
--steps: 9;
--w: 140;
}
.filmstrip {
--size: calc(1px * var(--w));
--hbsize: 2px;
--border: var(--hbsize) solid black;
--coveropacity: 0.9;
border: var(--border);
width: calc(5 * var(--size));
}
.holes {
background: lightgrey;
border-top: calc(5 * var(--hbsize)) dashed black;
}
.cells {
display: grid;
border-top: var(--border);
border-bottom: var(--border);
grid-template-columns: repeat(5, var(--size));
overflow: hidden;
}
.cell {
width: var(--size);
box-sizing: border-box;
border-right: var(--border);
background: grey;
opacity: var(--coveropacity);
z-index: 10;
}
.sprite {
grid-column: 3;
width: var(--size);
height: var(--size);
}
.sprite img {
height: var(--size);
position: relative;
left: 0%;
animation: moveX var(--duration) steps(var(--steps)) infinite;
z-index: 0;
}
@keyframes moveX {
to {
transform: translate(calc(-1px * var(--steps) * var(--w)));
xleft: 100%;
}
}
</style>
<div class="filmstrip">
<div class="holes"></div>
<div class="cells">
<div class="cell"></div>
<div class="cell"></div>
<div class="sprite">
<img src="" />
</div>
<div class="cell"></div>
<div class="cell"></div>
</div>
<div class="holes"></div>
</div>
</template>
<template id="SPRITE-FRAMES">
<style>
:host {
display: block;
}
#spriteframes {
display: grid;
grid-template-columns: repeat(var(--steps, 24) 1fr);
grid-auto-flow: column;
background: lightgrey;
}
.frame {
position: relative;
width: 100%;
vertical-align: top;
position: relative;
display: block;
width: 100%;
height: 0;
padding-bottom: 100%;
}
.frame svg {
xwidth: 100%;
xheight: 35px;
}
</style>
<div id="spriteframes"></div>
</template>
<template id="SPRITE-EDITOR">
<div>
<slot></slot>
</div>
</template>
<style>
body {
font: 14px Arial;
}
h1,
h2,
h3,
h4,
ul,
p {
margin: 0.7em 0;
}
#sprite1[editor] {
--editorHeight: 16em;
--editorWidth: 70vw;
--editorFontSize: 1.2em;
--editorBackground: lightgreen;
}
sprite-editor {
display: block;
background: beige;
padding: 1em;
}
sprite-templates {
cursor: pointer;
}
</style>
</head>
<body>
<section>
<h2>
SpriteMeister - Working Model - 0.42
<p style="color: red; font-weight: bold">
One programmable/editable (template literal) frame generates all frames for the sprite
</p>
</h2>
</section>
<section>
<h3>standard templates:</h3>
<sprite-templates></sprite-templates>
<h3>your localStorage templates:</h3>
Hold ctrl key down to delete your template
<br />
<sprite-templates user></sprite-templates>
</section>
<section>
<h3>SVG Editor - available functions & variables</h3>
<ul>
<li>No self-closing tags</li>
</ul>
<ul>
<li><b>framenr</b> - 0+</li>
<li><b>steps</b> - total frames</li>
<li>v - viewBox width</li>
<li>h - viewBox height</li>
<li><b>pulse( { start=0 , mid=0 , end=start })</b> - pulse from start to mid in one cycle - returns value</li>
<li><b>scale( { start=0 , mid=0 , end=start })</b> - scale (from center) - returns matrix string</li>
<li>
<b>ease({ distance , cycle=steps/2} )</b> - ease from 0 to length in [cycle], and back to 0 again - returns
value
</li>
<li><b>minmax({ value, min , max=value } )</b> - use value between min and max - returns value</li>
<li>
<b>arcpath({ start:[x1,y1 ] , end:[x2,y2] , [control:[sx,sy , ex,ey ]] , [color=false] )</b> - arc between 2
points with c-control points, c2x,c2y == c1x,c1y when not specified value
</li>
<li><b>round({ value , precision=1 })</b> - round, for smaller output</li>
</ul>
<sprite-editor>
<h2><span>Sprite Editor</span> - SVG one frame source: (changes are saved in localStorage)</h2>
<div>
Steps:
<input
id="sprite-editor-steps"
type="number"
value="24"
min="0"
step="0.1"
style="width: 4em"
onchange="this.closest('sprite-editor').set_steps(this.value)"
/>
frames (hardcoded in this online creator)
</div>
<div>
Duration:
<input
id="sprite-editor-duration"
type="number"
value="1"
min="0"
step="0.1"
style="width: 4em"
onchange="this.closest('sprite-editor').set_duration(this.value)"
/>
second for 24 frames
</div>
<div id="viewBoxSetting">
<style>
#viewBoxSetting input {
width: 3em;
text-align: right;
}
</style>
hardcoded 100x100 viewBox! You can set a custom viewBox with <sprite-meister cell="..x..">
</div>
<sprite-source id="sprite1" editor></sprite-source>
<!-- Display full running sprite User is editting -->
<sprite-meister
id="svgspriter"
template="bounce"
steps1="48"
duration="3s"
width="250px"
background-color="lightgreen"
>
</sprite-meister>
<!-- Display 24 still sprites, mouse over to freeze running sprite -->
<h2>24 Sprite frames: (move mouse over frame)</h2>
<sprite-frames></sprite-frames>
<!-- <h2>Filmstrip:</h2>
<sprite-filmstrip duration="svgspriter"></sprite-filmstrip> -->
<hr />
<h2>24 frames expanded to 1 SVG</h2>
<!-- Source code for use in IMG tag -->
<sprite-source id="srcIMG" title="SVG sprites output # escaped for IMG src">
<span slot="title"></span
></sprite-source>
<!-- source code for use in CSS background -->
<sprite-source id="srcCSS" escapedtags title="SVG sprites output # and < > escaped for CSS background"
><span slot="title"></span
></sprite-source>
</sprite-editor>
</section>
<section>
<h1>Inspiration</h1>
<ul>
<li>
<a href="https://css-tricks.com/many-tools-shape-morphing/"
>https://css-tricks.com/many-tools-shape-morphing/</a
>
</li>
<li>
<a href="https://shapeshifter.design/">https://shapeshifter.design/</a>
</li>
</ul>
</section>
</body>
</html>