-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
782 lines (726 loc) · 41 KB
/
index.html
File metadata and controls
782 lines (726 loc) · 41 KB
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SVG Shape Studio!</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
/* Custom styles */
body {
font-family: 'Inter', sans-serif;
/* Apply the requested background color */
background-color: #FFFCEB;
}
/* Main container styling - Adopted */
.main-container {
background-color: #ffffff;
border: 3px solid #2D3748; /* Dark border */
border-radius: 16px; /* More pronounced rounding */
box-shadow: 8px 8px 0px #2D3748; /* Stronger offset shadow */
width: 100%;
max-width: 64rem; /* max-w-5xl */
margin-left: auto;
margin-right: auto;
}
/* Section Container Styling (Controls, Preview/Code) */
.section-container {
background-color: #FFF7ED; /* orange-50 */
border: 2px solid #FDBA74; /* orange-300 */
border-radius: 12px; /* Match inputs */
box-shadow: 4px 4px 0px #FDBA74; /* Offset shadow using border color */
}
.section-container-alt { /* For Preview/Code Side */
background-color: #FEF3C7; /* amber-100 */
border: 2px solid #FDE68A; /* amber-200 */
border-radius: 12px; /* Match inputs */
box-shadow: 4px 4px 0px #FDE68A; /* Offset shadow using border color */
}
/* Playful Select Styling - Adopted */
select {
width: 100%;
padding: 0.75rem 1rem;
background-color: #ffffff;
border: 3px solid #4A5568;
border-radius: 12px;
color: #2D3748;
font-weight: 500;
transition: transform 0.15s ease-out, box-shadow 0.15s ease-out, border-color 0.15s ease-out;
box-shadow: 4px 4px 0px #4A5568;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%234A5568' stroke-linecap='round' stroke-linejoin='round' stroke-width='2.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
background-position: right 0.75rem center;
background-repeat: no-repeat;
background-size: 1.25em 1.25em;
padding-right: 3rem;
}
select:focus {
outline: none;
border-color: #FF7F50;
box-shadow: 4px 4px 0px #FF7F50, 0 0 0 3px #FFFCEB;
transform: translateY(-1px) translateX(-1px);
}
/* Playful Range Slider Styling - Adopted */
input[type="range"] {
flex-grow: 1; /* Ensure slider takes available space */
cursor: pointer;
accent-color: #FF7F50; /* Vibrant Orange */
height: 10px; /* Slightly thicker */
border-radius: 5px;
background-color: #FED7AA; /* Tailwind orange-200 */
transition: background-color 0.15s ease-in-out;
appearance: none;
-webkit-appearance: none;
border: 2px solid #FDBA74; /* orange-300 border */
box-shadow: inset 1px 1px 3px rgba(0,0,0,0.1);
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
-webkit-appearance: none;
width: 22px; /* Larger thumb */
height: 22px;
background: #FF7F50; /* Coral */
border-radius: 50%;
border: 3px solid #FFFCEB; /* Background color border */
box-shadow: 2px 2px 0px #E9754A, 0px 1px 3px rgba(0,0,0,0.3); /* Offset shadow + subtle shadow */
cursor: grab;
}
input[type="range"]::-moz-range-thumb {
width: 18px; /* Adjust for consistency */
height: 18px;
background: #FF7F50;
border-radius: 50%;
border: 3px solid #FFFCEB;
box-shadow: 2px 2px 0px #E9754A, 0px 1px 3px rgba(0,0,0,0.3);
cursor: grab;
}
input[type="range"]:hover {
background-color: #FDBA74; /* Tailwind orange-300 */
}
input[type="range"]:active::-webkit-slider-thumb { cursor: grabbing; }
input[type="range"]:active::-moz-range-thumb { cursor: grabbing; }
/* Playful Color Input Styling */
input[type="color"] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
width: 44px; /* Slightly larger */
height: 44px;
padding: 0;
border: 3px solid #4A5568; /* Dark border */
border-radius: 10px; /* Rounded */
cursor: pointer;
background-color: transparent;
box-shadow: 3px 3px 0px #4A5568; /* Offset shadow */
transition: transform 0.1s ease-out, box-shadow 0.1s ease-out;
}
input[type="color"]:hover {
transform: translateY(-1px);
box-shadow: 4px 4px 0px #4A5568;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; } /* Add padding */
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; } /* Inner swatch */
input[type="color"]::-moz-color-swatch { border: none; border-radius: 4px; padding: 3px;}
/* SVG Preview Area */
#svgPreview {
min-height: 350px; /* Increased height */
border: 3px dashed #FDE68A; /* amber-200 dashed border */
display: flex;
align-items: center;
justify-content: center;
background-color: #FFFBEB; /* amber-50 */
overflow: hidden;
position: relative;
border-radius: 10px; /* Rounded */
}
#svgPreview svg {
max-width: 100%;
max-height: 100%;
display: block;
/* Add a subtle animation */
transition: transform 0.2s ease-out;
}
#svgPreview:hover svg {
transform: scale(1.02); /* Slight zoom on hover */
}
/* SVG Code Output */
#svgCodeOutput {
font-family: monospace;
background-color: #FEF3C7; /* amber-100 */
border: 2px solid #FDE68A; /* amber-200 */
border-radius: 10px;
padding: 1rem 1.25rem; /* Increased padding */
word-wrap: break-word;
white-space: pre-wrap;
min-height: 150px;
max-height: 300px;
overflow-y: auto;
color: #9A3412; /* amber-800 */
box-shadow: inset 2px 2px 4px rgba(0,0,0,0.05);
}
/* Playful Copy Button Style - Adopted */
#copyBtn {
background-color: #FF7F50; /* Coral */
color: white;
font-weight: 700; /* bold */
padding-top: 0.75rem; /* py-3 */
padding-bottom: 0.75rem;
padding-left: 1rem; /* px-4 */
padding-right: 1rem;
border-radius: 0.75rem; /* rounded-xl */
border: 3px solid #2D3748; /* Darker border */
box-shadow: 5px 5px 0px #2D3748; /* Bigger shadow */
transition: all 0.15s ease-out;
width: 100%;
margin-top: 0.75rem; /* mt-3 */
display: flex;
align-items: center;
justify-content: center;
space-x: 0.5rem; /* space-x-2 */
text-transform: uppercase;
letter-spacing: 0.05em;
}
#copyBtn:hover {
background-color: #FF6347; /* Tomato */
box-shadow: 6px 6px 0px #2D3748;
transform: translateY(-2px) translateX(-1px); /* More lift */
}
#copyBtn:active {
background-color: #CD5C5C; /* IndianRed */
box-shadow: 2px 2px 0px #2D3748;
transform: translateY(2px) translateX(2px); /* Push down effect */
}
#copyBtn:focus {
outline: none;
box-shadow: 5px 5px 0px #2D3748, 0 0 0 3px #FFFCEB, 0 0 0 5px #FF7F50; /* Ring effect */
}
/* Message box styling - Adopted */
#message-box {
position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
padding: 12px 24px; border-radius: 12px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15), 3px 3px 0px #4A5568;
z-index: 1000; opacity: 0;
transition: opacity 0.5s ease-in-out, transform 0.3s ease-out;
pointer-events: none; font-weight: 600; border: 3px solid;
transform: translateX(-50%) translateY(10px); /* Start lower */
}
#message-box.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
#message-box.success { background-color: #D1FAE5; color: #047857; border-color: #6EE7B7; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15), 3px 3px 0px #065F46; }
#message-box.error { background-color: #FFE4E6; color: #DC2626; border-color: #FDA4AF; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15), 3px 3px 0px #991B1B; }
/* Control Group Transitions */
.control-group {
transition: opacity 0.3s ease-in-out, max-height 0.4s ease-out, transform 0.3s ease-out, margin-top 0.3s ease-out, padding-top 0.3s ease-out, border-top-width 0.3s ease-out;
transform: translateY(5px); max-height: 0; overflow: hidden; opacity: 0;
margin-top: 0 !important; padding-top: 0 !important;
border-top-width: 0 !important;
}
.control-group:not(.hidden) { /* Apply styles when NOT hidden */
opacity: 1; transform: translateY(0); max-height: 500px; /* Allow enough height */
margin-top: 1rem !important; /* pt-4 equivalent */
padding-top: 1rem !important;
border-top-width: 2px !important; /* Add border */
border-top-style: dashed;
border-top-color: #FDBA74; /* orange-300 */
}
.control-group.hidden { /* Ensure hidden styles override */
opacity: 0 !important; max-height: 0 !important; padding-top: 0 !important;
margin-top: 0 !important; overflow: hidden !important; border-top-width: 0 !important;
transform: translateY(5px) !important;
}
/* Label and Value Styling */
label {
color: #9A3412; /* amber-800 */
font-weight: 600; /* Semibold */
font-size: 0.875rem; /* text-sm */
}
.value-display { /* Class for spans displaying slider values */
color: #EA580C; /* orange-600 */
background-color: #FFFBEB; /* amber-50 */
padding: 2px 6px;
border-radius: 4px;
border: 1px solid #FDE68A; /* amber-200 */
font-family: monospace;
font-size: 0.8rem;
min-width: 35px; /* Ensure minimum width */
text-align: right;
}
.color-value-display { /* Class for spans displaying color values */
color: #EA580C; /* orange-600 */
font-family: monospace;
font-size: 0.875rem;
margin-left: 0.5rem;
font-weight: 500;
}
/* Headings */
.section-heading {
color: #C2410C; /* orange-700 */
font-weight: 700; /* bold */
text-align: center;
border-bottom: 2px dashed #FDBA74; /* orange-300 */
padding-bottom: 0.5rem; /* pb-2 */
margin-bottom: 0.75rem; /* mb-3 */
font-size: 1.125rem; /* text-lg */
}
.subsection-heading {
color: #DD6B20; /* orange-600 */
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
font-size: 0.75rem; /* text-xs */
margin-bottom: 0.5rem; /* Add space below subsection headings */
}
</style>
</head>
<body class="p-4 md:p-8">
<div class="main-container p-6 sm:p-8">
<h1 class="text-3xl sm:text-4xl font-bold text-center text-slate-800 mb-10 tracking-tight flex items-center justify-center gap-3">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-9 h-9 text-orange-500">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.59 14.37a6 6 0 01-5.84 7.38v-4.8m5.84-2.58a14.98 14.98 0 006.16-12.12A14.98 14.98 0 009.63 2.25A14.98 14.98 0 003.47 14.37m12.12 0a14.98 14.98 0 01-8.24 2.58m8.24-2.58a14.98 14.98 0 00-2.58-8.24m-8.24 5.66a14.98 14.98 0 016.16-12.12m0 0A14.98 14.98 0 019.63 2.25m12.12 0A14.98 14.98 0 009.63 2.25M3.47 14.37a14.98 14.98 0 006.16 12.12m0 0a14.98 14.98 0 006.16-12.12m-12.12 0l-5.66-8.24m5.66 8.24l8.24 5.66" />
</svg>
SVG Shape Studio!
</h1>
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
<div class="section-container p-5 space-y-5">
<h2 class="section-heading">Controls</h2>
<div>
<label for="shapeType">Shape Type:</label>
<select id="shapeType">
<option value="polygon">Polygon</option>
<option value="star">Star</option>
<option value="circle">Circle</option>
<option value="ellipse">Ellipse</option>
<option value="rectangle">Rectangle</option>
<option value="rounded_rectangle">Rounded Rectangle</option>
<option value="line">Line</option>
</select>
</div>
<div id="groupPolyStar" class="control-group space-y-4">
<h3 class="subsection-heading">Polygon / Star</h3>
<div class="flex items-center space-x-3">
<label for="points" class="w-28 shrink-0">Points / Sides:</label>
<input type="range" id="points" min="3" max="20" value="5">
<span id="pointsValue" class="value-display">5</span>
</div>
<div class="flex items-center space-x-3">
<label for="outerRadius" class="w-28 shrink-0">Outer Radius:</label>
<input type="range" id="outerRadius" min="20" max="145" value="100">
<span id="outerRadiusValue" class="value-display">100</span>
</div>
<div id="innerRadiusControl" class="control-group flex items-center space-x-3">
<label for="innerRadius" class="w-28 shrink-0">Inner Radius:</label>
<input type="range" id="innerRadius" min="5" max="140" value="50">
<span id="innerRadiusValue" class="value-display">50</span>
</div>
</div>
<div id="groupCircle" class="control-group space-y-4 hidden">
<h3 class="subsection-heading">Circle</h3>
<div class="flex items-center space-x-3">
<label for="circleR" class="w-28 shrink-0">Radius (r):</label>
<input type="range" id="circleR" min="10" max="145" value="80">
<span id="circleRValue" class="value-display">80</span>
</div>
<div class="flex items-center space-x-3">
<label for="circleCX" class="w-28 shrink-0">Center X (cx):</label>
<input type="range" id="circleCX" min="10" max="290" value="150">
<span id="circleCXValue" class="value-display">150</span>
</div>
<div class="flex items-center space-x-3">
<label for="circleCY" class="w-28 shrink-0">Center Y (cy):</label>
<input type="range" id="circleCY" min="10" max="290" value="150">
<span id="circleCYValue" class="value-display">150</span>
</div>
</div>
<div id="groupEllipse" class="control-group space-y-4 hidden">
<h3 class="subsection-heading">Ellipse</h3>
<div class="flex items-center space-x-3">
<label for="ellipseRX" class="w-28 shrink-0">Radius X (rx):</label>
<input type="range" id="ellipseRX" min="10" max="145" value="100">
<span id="ellipseRXValue" class="value-display">100</span>
</div>
<div class="flex items-center space-x-3">
<label for="ellipseRY" class="w-28 shrink-0">Radius Y (ry):</label>
<input type="range" id="ellipseRY" min="10" max="145" value="60">
<span id="ellipseRYValue" class="value-display">60</span>
</div>
<div class="flex items-center space-x-3">
<label for="ellipseCX" class="w-28 shrink-0">Center X (cx):</label>
<input type="range" id="ellipseCX" min="10" max="290" value="150">
<span id="ellipseCXValue" class="value-display">150</span>
</div>
<div class="flex items-center space-x-3">
<label for="ellipseCY" class="w-28 shrink-0">Center Y (cy):</label>
<input type="range" id="ellipseCY" min="10" max="290" value="150">
<span id="ellipseCYValue" class="value-display">150</span>
</div>
</div>
<div id="groupRectangle" class="control-group space-y-4 hidden">
<h3 class="subsection-heading">Rectangle</h3>
<div class="flex items-center space-x-3">
<label for="rectWidth" class="w-28 shrink-0">Width:</label>
<input type="range" id="rectWidth" min="10" max="280" value="150">
<span id="rectWidthValue" class="value-display">150</span>
</div>
<div class="flex items-center space-x-3">
<label for="rectHeight" class="w-28 shrink-0">Height:</label>
<input type="range" id="rectHeight" min="10" max="280" value="100">
<span id="rectHeightValue" class="value-display">100</span>
</div>
<div class="flex items-center space-x-3">
<label for="rectX" class="w-28 shrink-0">Top-Left X:</label>
<input type="range" id="rectX" min="0" max="290" value="75">
<span id="rectXValue" class="value-display">75</span>
</div>
<div class="flex items-center space-x-3">
<label for="rectY" class="w-28 shrink-0">Top-Left Y:</label>
<input type="range" id="rectY" min="0" max="290" value="100">
<span id="rectYValue" class="value-display">100</span>
</div>
<div id="rectRXControl" class="control-group flex items-center space-x-3">
<label for="rectRX" class="w-28 shrink-0">Corner RX:</label>
<input type="range" id="rectRX" min="0" max="140" value="10">
<span id="rectRXValue" class="value-display">10</span>
</div>
<div id="rectRYControl" class="control-group flex items-center space-x-3">
<label for="rectRY" class="w-28 shrink-0">Corner RY:</label>
<input type="range" id="rectRY" min="0" max="140" value="10">
<span id="rectRYValue" class="value-display">10</span>
</div>
</div>
<div id="groupLine" class="control-group space-y-4 hidden">
<h3 class="subsection-heading">Line</h3>
<div class="flex items-center space-x-3">
<label for="lineX1" class="w-28 shrink-0">Start X (x1):</label>
<input type="range" id="lineX1" min="0" max="300" value="50">
<span id="lineX1Value" class="value-display">50</span>
</div>
<div class="flex items-center space-x-3">
<label for="lineY1" class="w-28 shrink-0">Start Y (y1):</label>
<input type="range" id="lineY1" min="0" max="300" value="50">
<span id="lineY1Value" class="value-display">50</span>
</div>
<div class="flex items-center space-x-3">
<label for="lineX2" class="w-28 shrink-0">End X (x2):</label>
<input type="range" id="lineX2" min="0" max="300" value="250">
<span id="lineX2Value" class="value-display">250</span>
</div>
<div class="flex items-center space-x-3">
<label for="lineY2" class="w-28 shrink-0">End Y (y2):</label>
<input type="range" id="lineY2" min="0" max="300" value="250">
<span id="lineY2Value" class="value-display">250</span>
</div>
</div>
<div class="space-y-4 border-t-2 border-dashed border-orange-300 pt-4">
<h3 class="subsection-heading">Appearance</h3>
<div id="fillControl" class="flex items-center space-x-3">
<label for="fillColor" class="w-28 shrink-0">Fill Color:</label>
<input type="color" id="fillColor" value="#FF7F50"> <span id="fillColorValue" class="color-value-display">#FF7F50</span>
</div>
<div class="flex items-center space-x-3">
<label for="strokeColor" class="w-28 shrink-0">Stroke Color:</label>
<input type="color" id="strokeColor" value="#4A5568"> <span id="strokeColorValue" class="color-value-display">#4A5568</span>
</div>
<div class="flex items-center space-x-3">
<label for="strokeWidth" class="w-28 shrink-0">Stroke Width:</label>
<input type="range" id="strokeWidth" min="0" max="20" value="3" step="0.5"> <span id="strokeWidthValue" class="value-display">3</span>
</div>
</div>
</div>
<div class="section-container-alt p-5 space-y-5">
<div>
<h2 class="section-heading">Preview</h2>
<div id="svgPreview">
<p class="text-amber-700 text-sm font-medium">Adjust controls to see your shape!</p>
</div>
</div>
<div>
<h2 class="section-heading">Generated SVG Code</h2>
<div id="svgCodeOutput" class="text-xs sm:text-sm">
</div>
<button id="copyBtn">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.378h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876V5.25a.75.75 0 00-.75-.75h-1.5a.75.75 0 00-.75.75v.443A9.003 9.003 0 006 8.625a9.003 9.003 0 00-1.5-.781V5.25a.75.75 0 00-.75-.75h-1.5a.75.75 0 00-.75.75v1.69" />
</svg>
<span>Copy Code</span>
</button>
</div>
</div>
</div>
<div id="message-box"></div>
</div>
<script>
// --- DOM Elements ---
const shapeTypeSelect = document.getElementById('shapeType');
// Poly/Star
const groupPolyStar = document.getElementById('groupPolyStar');
const pointsSlider = document.getElementById('points');
const pointsValue = document.getElementById('pointsValue');
const outerRadiusSlider = document.getElementById('outerRadius');
const outerRadiusValue = document.getElementById('outerRadiusValue');
const innerRadiusControl = document.getElementById('innerRadiusControl');
const innerRadiusSlider = document.getElementById('innerRadius');
const innerRadiusValue = document.getElementById('innerRadiusValue');
// Circle
const groupCircle = document.getElementById('groupCircle');
const circleRSlider = document.getElementById('circleR');
const circleRValue = document.getElementById('circleRValue');
const circleCXSlider = document.getElementById('circleCX');
const circleCXValue = document.getElementById('circleCXValue');
const circleCYSlider = document.getElementById('circleCY');
const circleCYValue = document.getElementById('circleCYValue');
// Ellipse
const groupEllipse = document.getElementById('groupEllipse');
const ellipseRXSlider = document.getElementById('ellipseRX');
const ellipseRXValue = document.getElementById('ellipseRXValue');
const ellipseRYSlider = document.getElementById('ellipseRY');
const ellipseRYValue = document.getElementById('ellipseRYValue');
const ellipseCXSlider = document.getElementById('ellipseCX');
const ellipseCXValue = document.getElementById('ellipseCXValue');
const ellipseCYSlider = document.getElementById('ellipseCY');
const ellipseCYValue = document.getElementById('ellipseCYValue');
// Rectangle / Rounded Rectangle
const groupRectangle = document.getElementById('groupRectangle');
const rectWidthSlider = document.getElementById('rectWidth');
const rectWidthValue = document.getElementById('rectWidthValue');
const rectHeightSlider = document.getElementById('rectHeight');
const rectHeightValue = document.getElementById('rectHeightValue');
const rectXSlider = document.getElementById('rectX');
const rectXValue = document.getElementById('rectXValue');
const rectYSlider = document.getElementById('rectY');
const rectYValue = document.getElementById('rectYValue');
const rectRXControl = document.getElementById('rectRXControl');
const rectRXSlider = document.getElementById('rectRX');
const rectRXValue = document.getElementById('rectRXValue');
const rectRYControl = document.getElementById('rectRYControl');
const rectRYSlider = document.getElementById('rectRY');
const rectRYValue = document.getElementById('rectRYValue');
// Line
const groupLine = document.getElementById('groupLine');
const lineX1Slider = document.getElementById('lineX1');
const lineX1Value = document.getElementById('lineX1Value');
const lineY1Slider = document.getElementById('lineY1');
const lineY1Value = document.getElementById('lineY1Value');
const lineX2Slider = document.getElementById('lineX2');
const lineX2Value = document.getElementById('lineX2Value');
const lineY2Slider = document.getElementById('lineY2');
const lineY2Value = document.getElementById('lineY2Value');
// Common Appearance
const fillControl = document.getElementById('fillControl');
const fillColorInput = document.getElementById('fillColor');
const fillColorValue = document.getElementById('fillColorValue');
const strokeColorInput = document.getElementById('strokeColor');
const strokeColorValue = document.getElementById('strokeColorValue');
const strokeWidthSlider = document.getElementById('strokeWidth');
const strokeWidthValue = document.getElementById('strokeWidthValue');
// Output
const svgPreview = document.getElementById('svgPreview');
const svgCodeOutput = document.getElementById('svgCodeOutput');
const copyBtn = document.getElementById('copyBtn');
const messageBox = document.getElementById('message-box');
let messageTimeout; // Timer for message box visibility
// --- Utility Functions ---
// Shows a temporary message box at the bottom of the screen.
function showMessage(text, type = 'success') {
if (messageTimeout) clearTimeout(messageTimeout); // Clear previous timer
messageBox.textContent = text;
// Apply type class first, then trigger show animation
messageBox.className = ` ${type}`; // Reset classes except type
setTimeout(() => { messageBox.classList.add('show'); }, 10); // Add 'show' after a tick
// Set timeout to hide the message
messageTimeout = setTimeout(() => {
messageBox.classList.remove('show');
messageTimeout = null;
}, 3000); // Hide after 3 seconds
}
// Calculates the points attribute string for a polygon or star.
// Points are calculated relative to a center of (0,0).
function calculatePolyStarPoints(shapeType, numPoints, outerR, innerR) {
const points = [];
const angleStep = (Math.PI * 2) / numPoints; // Angle between points
for (let i = 0; i < numPoints; i++) {
const angle = i * angleStep - Math.PI / 2; // Start from the top (-90 degrees)
// Calculate outer point coordinates
const x1 = outerR * Math.cos(angle);
const y1 = outerR * Math.sin(angle);
points.push(`${x1.toFixed(2)},${y1.toFixed(2)}`);
// If it's a star, calculate and add the inner point
if (shapeType === 'star') {
// Ensure inner radius is valid (0 <= innerR < outerR)
const safeInnerR = Math.max(0, Math.min(innerR, outerR - 1));
const angleInner = angle + angleStep / 2; // Angle for the inner point (halfway between outer points)
// Calculate inner point coordinates
const x2 = safeInnerR * Math.cos(angleInner);
const y2 = safeInnerR * Math.sin(angleInner);
points.push(`${x2.toFixed(2)},${y2.toFixed(2)}`);
}
}
return points.join(' '); // Join points into a string for the 'points' attribute
}
// --- Update Controls Visibility ---
// Shows/hides control groups based on the selected shape type.
function updateControlsVisibility() {
const shapeType = shapeTypeSelect.value;
// Hide all shape-specific control groups initially
groupPolyStar.classList.add('hidden');
groupCircle.classList.add('hidden');
groupEllipse.classList.add('hidden');
groupRectangle.classList.add('hidden');
groupLine.classList.add('hidden');
// Show fill control by default (will be hidden for line later)
fillControl.classList.remove('hidden');
// Show the relevant control group based on shapeType
if (shapeType === 'polygon' || shapeType === 'star') {
groupPolyStar.classList.remove('hidden');
// Show/hide inner radius only for star
innerRadiusControl.classList.toggle('hidden', shapeType !== 'star');
} else if (shapeType === 'circle') {
groupCircle.classList.remove('hidden');
} else if (shapeType === 'ellipse') {
groupEllipse.classList.remove('hidden');
} else if (shapeType === 'rectangle' || shapeType === 'rounded_rectangle') {
groupRectangle.classList.remove('hidden');
// Show/hide corner radius controls only for rounded rectangle
rectRXControl.classList.toggle('hidden', shapeType !== 'rounded_rectangle');
rectRYControl.classList.toggle('hidden', shapeType !== 'rounded_rectangle');
} else if (shapeType === 'line') {
groupLine.classList.remove('hidden');
// Line doesn't have a fill, so hide the fill control
fillControl.classList.add('hidden');
}
}
// --- Main Generation Function ---
// Reads control values, generates the SVG element string, and updates the preview and code output.
function generateAndUpdateSVG() {
const shapeType = shapeTypeSelect.value;
const fill = fillColorInput.value;
const stroke = strokeColorInput.value;
const strokeWidth = parseFloat(strokeWidthSlider.value);
// Update displayed values for common controls
fillColorValue.textContent = fill.toUpperCase();
strokeColorValue.textContent = stroke.toUpperCase();
strokeWidthValue.textContent = strokeWidth;
let svgElementString = ''; // String to hold the generated SVG element (<polygon>, <circle>, etc.)
const viewBox = "0 0 300 300"; // Define the SVG coordinate system
// Generate the specific SVG element based on the selected shape type
switch (shapeType) {
case 'polygon':
case 'star': {
const numPoints = parseInt(pointsSlider.value, 10);
const outerR = parseInt(outerRadiusSlider.value, 10);
let innerR = parseInt(innerRadiusSlider.value, 10);
// Update displayed values
pointsValue.textContent = numPoints;
outerRadiusValue.textContent = outerR;
innerRadiusValue.textContent = innerR;
// Prevent star inner radius from being >= outer radius
if (shapeType === 'star' && innerR >= outerR) {
innerR = Math.max(0, outerR - 5); // Set slightly smaller than outer
innerRadiusSlider.value = innerR; // Update slider value
innerRadiusValue.textContent = innerR; // Update displayed value
}
const pointsString = calculatePolyStarPoints(shapeType, numPoints, outerR, innerR);
// Use transform to center the polygon/star in the 300x300 viewBox
svgElementString = `<polygon points="${pointsString}" transform="translate(150 150)" fill="${fill}" stroke="${stroke}" stroke-width="${strokeWidth}" />`;
break;
}
case 'circle': {
const r = parseInt(circleRSlider.value, 10);
const cx = parseInt(circleCXSlider.value, 10);
const cy = parseInt(circleCYSlider.value, 10);
// Update displayed values
circleRValue.textContent = r;
circleCXValue.textContent = cx;
circleCYValue.textContent = cy;
svgElementString = `<circle cx="${cx}" cy="${cy}" r="${r}" fill="${fill}" stroke="${stroke}" stroke-width="${strokeWidth}" />`;
break;
}
case 'ellipse': {
const rx = parseInt(ellipseRXSlider.value, 10);
const ry = parseInt(ellipseRYSlider.value, 10);
const cx = parseInt(ellipseCXSlider.value, 10);
const cy = parseInt(ellipseCYSlider.value, 10);
// Update displayed values
ellipseRXValue.textContent = rx;
ellipseRYValue.textContent = ry;
ellipseCXValue.textContent = cx;
ellipseCYValue.textContent = cy;
svgElementString = `<ellipse cx="${cx}" cy="${cy}" rx="${rx}" ry="${ry}" fill="${fill}" stroke="${stroke}" stroke-width="${strokeWidth}" />`;
break;
}
case 'rectangle':
case 'rounded_rectangle': {
const width = parseInt(rectWidthSlider.value, 10);
const height = parseInt(rectHeightSlider.value, 10);
const x = parseInt(rectXSlider.value, 10);
const y = parseInt(rectYSlider.value, 10);
// Get corner radius only if it's a rounded rectangle
const rx = (shapeType === 'rounded_rectangle') ? parseInt(rectRXSlider.value, 10) : 0;
const ry = (shapeType === 'rounded_rectangle') ? parseInt(rectRYSlider.value, 10) : 0;
// Update displayed values
rectWidthValue.textContent = width;
rectHeightValue.textContent = height;
rectXValue.textContent = x;
rectYValue.textContent = y;
rectRXValue.textContent = rx;
rectRYValue.textContent = ry;
svgElementString = `<rect x="${x}" y="${y}" width="${width}" height="${height}" rx="${rx}" ry="${ry}" fill="${fill}" stroke="${stroke}" stroke-width="${strokeWidth}" />`;
break;
}
case 'line': {
const x1 = parseInt(lineX1Slider.value, 10);
const y1 = parseInt(lineY1Slider.value, 10);
const x2 = parseInt(lineX2Slider.value, 10);
const y2 = parseInt(lineY2Slider.value, 10);
// Update displayed values
lineX1Value.textContent = x1;
lineY1Value.textContent = y1;
lineX2Value.textContent = x2;
lineY2Value.textContent = y2;
// Line doesn't use fill attribute
svgElementString = `<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${stroke}" stroke-width="${strokeWidth}" />`;
break;
}
}
// Construct the final SVG string with the generated element
const svgString = `<svg viewBox="${viewBox}" width="300" height="300" xmlns="http://www.w3.org/2000/svg">\n ${svgElementString}\n</svg>`;
// Update the preview area with the generated SVG
svgPreview.innerHTML = svgString;
// Update the code output area
svgCodeOutput.textContent = svgString;
// Update visibility of control groups AFTER generating the SVG
updateControlsVisibility();
}
// --- Event Listeners ---
// Regenerate SVG when shape type changes
shapeTypeSelect.addEventListener('change', generateAndUpdateSVG);
// Regenerate SVG when any slider or color input changes
const controls = document.querySelectorAll('input[type="range"], input[type="color"]');
controls.forEach(control => {
control.addEventListener('input', generateAndUpdateSVG);
});
// Copy Button Functionality
copyBtn.addEventListener('click', () => {
const codeToCopy = svgCodeOutput.textContent;
// Check if there's code to copy
if (!codeToCopy || codeToCopy.trim() === '' || codeToCopy.includes('<p>')) { // Added check for placeholder
showMessage("No SVG code generated yet!", "error");
return;
}
// Use Clipboard API to copy text
navigator.clipboard.writeText(codeToCopy)
.then(() => showMessage("SVG code copied! 👍", "success")) // Success message
.catch(err => { // Error handling
console.error("Failed to copy SVG code: ", err);
showMessage("Failed to copy. Try manually!", "error");
});
});
// --- Initial Load ---
// Generate the default shape (Polygon) and set initial control visibility on page load
generateAndUpdateSVG();
</script>
</body>
</html>