-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.html
More file actions
841 lines (699 loc) · 29.7 KB
/
image.html
File metadata and controls
841 lines (699 loc) · 29.7 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
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Art Generator</title>
<style>
/* Reset and base styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: monospace, 'Courier New', Courier;
}
body {
background-color: #f8f8f8;
color: #111;
padding: 20px;
max-width: 1000px;
margin: 0 auto;
transition: background-color 0.3s, color 0.3s;
}
body.dark {
background-color: #111;
color: #f8f8f8;
}
/* Main container */
.app-container {
margin: 2rem auto;
padding: 2rem;
background-color: #fff;
box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.1);
border: 1px solid #111;
position: relative;
transition: background-color 0.3s;
}
body.dark .app-container {
background-color: #222;
border-color: #f8f8f8;
}
/* Typography */
h1 {
text-align: center;
margin-bottom: 2rem;
font-size: 1.8rem;
letter-spacing: 1px;
}
h2 {
margin: 1.5rem 0 1rem 0;
font-size: 1.2rem;
}
/* Upload area */
.upload-area {
border: 2px dashed #111;
padding: 2rem;
text-align: center;
margin-bottom: 1.5rem;
transition: border-color 0.3s;
}
body.dark .upload-area {
border-color: #f8f8f8;
}
/* Buttons */
button {
background-color: #111;
color: #fff;
border: none;
padding: 0.75rem 1.5rem;
cursor: pointer;
font-size: 1rem;
transition: background-color 0.3s, color 0.3s;
}
body.dark button {
background-color: #f8f8f8;
color: #111;
}
button:hover {
opacity: 0.9;
}
/* Toggle dark mode button */
.dark-mode-toggle {
position: absolute;
top: 1rem;
right: 1rem;
padding: 0.5rem;
font-size: 0.8rem;
font-weight: bold;
}
/* Controls section */
.controls {
margin-bottom: 1.5rem;
}
.control-group {
margin-bottom: 1rem;
}
label {
display: block;
margin-bottom: 0.5rem;
}
.slider-container {
display: flex;
align-items: center;
gap: 1rem;
}
input[type="range"] {
flex: 1;
height: 2px;
-webkit-appearance: none;
background: #111;
}
body.dark input[type="range"] {
background: #f8f8f8;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 10px;
height: 10px;
background: #111;
cursor: pointer;
}
body.dark input[type="range"]::-webkit-slider-thumb {
background: #f8f8f8;
}
input[type="color"] {
-webkit-appearance: none;
width: 100%;
height: 30px;
padding: 0;
border: 1px solid #111;
}
body.dark input[type="color"] {
border-color: #f8f8f8;
}
/* Canvas grid */
.canvas-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1.5rem;
margin-bottom: 1.5rem;
}
@media (max-width: 768px) {
.canvas-grid {
grid-template-columns: 1fr;
}
}
.canvas-container {
text-align: center;
}
canvas {
max-width: 100%;
border: 1px solid #111;
background-color: #fff;
transition: border-color 0.3s, background-color 0.3s;
}
body.dark canvas {
border-color: #f8f8f8;
background-color: #222;
}
/* Progress indicators */
.progress-container {
height: 4px;
background-color: #eee;
margin: 1rem 0;
display: none;
transition: background-color 0.3s;
}
body.dark .progress-container {
background-color: #333;
}
.progress-bar {
height: 100%;
width: 0%;
background-color: #111;
transition: width 0.3s, background-color 0.3s;
}
body.dark .progress-bar {
background-color: #f8f8f8;
}
.status-message {
text-align: center;
margin: 1rem 0;
display: none;
}
/* Instructions section */
.instructions {
margin-top: 2rem;
border-top: 1px solid #111;
padding-top: 1.5rem;
transition: border-color 0.3s;
}
body.dark .instructions {
border-color: #f8f8f8;
}
.pin-visualization {
text-align: center;
margin: 1.5rem 0;
}
ol, ul {
padding-left: 1.5rem;
margin-bottom: 1rem;
}
li {
margin-bottom: 0.5rem;
}
/* Action buttons */
.action-button {
display: block;
margin: 1.5rem auto;
min-width: 200px;
}
/* Success message */
.success-message {
text-align: center;
margin: 1rem 0;
}
</style>
</head>
<body>
<div class="app-container">
<button class="dark-mode-toggle" id="darkModeToggle">DARK</button>
<h1>IMAGE ↔ STRING ART CONVERTER</h1>
<div class="upload-area" id="dropArea">
Drag & drop image files here
<br>or
<br><br>
<button id="browseButton">Browse Files</button>
<input type="file" id="imageUpload" accept="image/*" style="display: none;">
</div>
<div class="controls">
<div class="control-group">
<label>PINS: <span id="numPinsValue">100</span></label>
<div class="slider-container">
<input type="range" id="numPins" min="20" max="200" value="100">
</div>
</div>
<div class="control-group">
<label>STRINGS: <span id="numStringsValue">1000</span></label>
<div class="slider-container">
<input type="range" id="numStrings" min="100" max="2000" value="1000">
</div>
</div>
<div class="control-group">
<label>STRING COLOR</label>
<input type="color" id="stringColor" value="#000000">
</div>
<div class="control-group">
<label>BACKGROUND COLOR</label>
<input type="color" id="backgroundColor" value="#ffffff">
</div>
</div>
<button id="generateBtn" class="action-button">Convert & Generate</button>
<div id="statusMessage" class="status-message">Processing image...</div>
<div class="progress-container" id="progressContainer">
<div class="progress-bar" id="progressBar"></div>
</div>
<div id="successMessage" class="success-message"></div>
<div class="canvas-grid">
<div class="canvas-container">
<h2>Original Image</h2>
<canvas id="originalCanvas"></canvas>
</div>
<div class="canvas-container">
<h2>String Art</h2>
<canvas id="stringArtCanvas"></canvas>
</div>
</div>
<div class="instructions">
<h2>How it works</h2>
<ul>
<li>Upload an image to convert it into string art</li>
<li>Adjust pins and strings to control complexity</li>
<li>The algorithm finds optimal string paths</li>
<li>Follow the generated instructions to create it in real life</li>
</ul>
<div id="pinVisualization" class="pin-visualization">
<h2>Pin Layout</h2>
<canvas id="pinLayoutCanvas" width="400" height="400"></canvas>
</div>
<h2>Implementation Guide</h2>
<ol id="instructions">
<li>Upload an image and click "Convert & Generate" to see instructions.</li>
</ol>
<button id="downloadBtn" class="action-button" style="display:none;">Download Instructions</button>
</div>
</div>
<script>
// DOM Elements
const darkModeToggle = document.getElementById('darkModeToggle');
const imageUpload = document.getElementById('imageUpload');
const browseButton = document.getElementById('browseButton');
const dropArea = document.getElementById('dropArea');
const originalCanvas = document.getElementById('originalCanvas');
const stringArtCanvas = document.getElementById('stringArtCanvas');
const pinLayoutCanvas = document.getElementById('pinLayoutCanvas');
const numPinsSlider = document.getElementById('numPins');
const numPinsValue = document.getElementById('numPinsValue');
const numStringsSlider = document.getElementById('numStrings');
const numStringsValue = document.getElementById('numStringsValue');
const stringColorPicker = document.getElementById('stringColor');
const backgroundColorPicker = document.getElementById('backgroundColor');
const generateBtn = document.getElementById('generateBtn');
const statusMessage = document.getElementById('statusMessage');
const successMessage = document.getElementById('successMessage');
const progressContainer = document.getElementById('progressContainer');
const progressBar = document.getElementById('progressBar');
const instructions = document.getElementById('instructions');
const downloadBtn = document.getElementById('downloadBtn');
// Dark mode toggle
darkModeToggle.addEventListener('click', function() {
document.body.classList.toggle('dark');
darkModeToggle.textContent = document.body.classList.contains('dark') ? 'LIGHT' : 'DARK';
});
// Global variables
let originalImage = null;
let pins = [];
let stringSequence = [];
// Handle file browse button
browseButton.addEventListener('click', function() {
imageUpload.click();
});
// Update slider value displays
numPinsSlider.addEventListener('input', () => {
numPinsValue.textContent = numPinsSlider.value;
});
numStringsSlider.addEventListener('input', () => {
numStringsValue.textContent = numStringsSlider.value;
});
// Handle image upload
imageUpload.addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
handleFile(file);
});
// Handle drag and drop
dropArea.addEventListener('dragover', function(e) {
e.preventDefault();
dropArea.style.borderColor = '#000';
});
dropArea.addEventListener('dragleave', function() {
dropArea.style.borderColor = '';
});
dropArea.addEventListener('drop', function(e) {
e.preventDefault();
dropArea.style.borderColor = '';
if (e.dataTransfer.files.length) {
const file = e.dataTransfer.files[0];
if (file.type.match('image.*')) {
handleFile(file);
}
}
});
// Process the uploaded file
function handleFile(file) {
const reader = new FileReader();
reader.onload = function(event) {
const img = new Image();
img.onload = function() {
originalImage = img;
displayOriginalImage();
successMessage.textContent = "Image uploaded successfully";
successMessage.style.display = "block";
setTimeout(() => {
successMessage.style.display = "none";
}, 3000);
};
img.src = event.target.result;
};
reader.readAsDataURL(file);
}
// Display original image on canvas
function displayOriginalImage() {
if (!originalImage) return;
const ctx = originalCanvas.getContext('2d');
// Set canvas size with max dimensions of 400px
const maxDim = 400;
let width = originalImage.width;
let height = originalImage.height;
if (width > height) {
if (width > maxDim) {
height = height * (maxDim / width);
width = maxDim;
}
} else {
if (height > maxDim) {
width = width * (maxDim / height);
height = maxDim;
}
}
originalCanvas.width = width;
originalCanvas.height = height;
// Draw image
ctx.clearRect(0, 0, width, height);
ctx.drawImage(originalImage, 0, 0, width, height);
}
// Generate button click handler
generateBtn.addEventListener('click', function() {
if (!originalImage) {
alert('Please upload an image first');
return;
}
// Show status message and progress bar
statusMessage.style.display = 'block';
progressContainer.style.display = 'block';
progressBar.style.width = '0%';
generateBtn.disabled = true;
// Get parameters
const numPins = parseInt(numPinsSlider.value);
const numStrings = parseInt(numStringsSlider.value);
const stringColor = stringColorPicker.value;
const backgroundColor = backgroundColorPicker.value;
// Use setTimeout to allow UI to update before processing
setTimeout(() => {
// Generate string art
generateStringArt(numPins, numStrings, stringColor, backgroundColor);
// Create pin layout visualization
createPinLayout(numPins, backgroundColor);
// Generate instructions
createInstructions(numPins, numStrings, stringColor);
// Show download button
downloadBtn.style.display = 'block';
// Hide status message and show success
statusMessage.style.display = 'none';
progressContainer.style.display = 'none';
successMessage.textContent = "String art generated successfully";
successMessage.style.display = "block";
setTimeout(() => {
successMessage.style.display = "none";
}, 3000);
generateBtn.disabled = false;
}, 100);
});
// Generate string art
function generateStringArt(numPins, numStrings, stringColor, backgroundColor) {
// Setup canvas
const canvas = stringArtCanvas;
const ctx = canvas.getContext('2d');
// Match dimensions with original canvas
canvas.width = originalCanvas.width;
canvas.height = originalCanvas.height;
const width = canvas.width;
const height = canvas.height;
// Fill background
ctx.fillStyle = backgroundColor;
ctx.fillRect(0, 0, width, height);
// Get original image data
const originalCtx = originalCanvas.getContext('2d');
const imgData = originalCtx.getImageData(0, 0, width, height);
const data = imgData.data;
// Create grayscale intensity map (inverted)
const intensityMap = new Uint8Array(width * height);
for (let i = 0; i < data.length; i += 4) {
const x = (i / 4) % width;
const y = Math.floor((i / 4) / width);
const idx = y * width + x;
// Convert to grayscale and invert
const gray = 255 - Math.round(0.299 * data[i] + 0.587 * data[i+1] + 0.114 * data[i+2]);
intensityMap[idx] = gray;
}
// Create pins in circular arrangement
pins = [];
const radius = Math.min(width, height) * 0.45;
const centerX = width / 2;
const centerY = height / 2;
for (let i = 0; i < numPins; i++) {
const angle = (i / numPins) * Math.PI * 2;
const x = centerX + radius * Math.cos(angle);
const y = centerY + radius * Math.sin(angle);
pins.push({ x, y, index: i });
}
// Draw pins
ctx.fillStyle = document.body.classList.contains('dark') ? '#fff' : '#000';
pins.forEach(pin => {
ctx.beginPath();
ctx.arc(pin.x, pin.y, 2, 0, Math.PI * 2);
ctx.fill();
});
// Creates an array representing pixels on a line
function createLineMap(from, to) {
const lineMap = new Uint8Array(width * height);
const dx = to.x - from.x;
const dy = to.y - from.y;
const steps = Math.max(Math.abs(dx), Math.abs(dy)) * 2;
for (let i = 0; i <= steps; i++) {
const t = i / steps;
const x = Math.floor(from.x + t * dx);
const y = Math.floor(from.y + t * dy);
if (x >= 0 && x < width && y >= 0 && y < height) {
lineMap[y * width + x] = 1;
}
}
return lineMap;
}
// Initialize the string art algorithm
stringSequence = [];
let currentPin = 0;
let workingIntensityMap = new Uint8Array(intensityMap);
for (let s = 0; s < numStrings; s++) {
let bestScore = -1;
let bestPin = -1;
let bestLineMap = null;
// Find the best pin to connect to
for (let i = 0; i < numPins; i++) {
if (i === currentPin) continue;
const from = pins[currentPin];
const to = pins[i];
const lineMap = createLineMap(from, to);
// Calculate how well this line matches dark areas
let score = 0;
for (let j = 0; j < lineMap.length; j++) {
if (lineMap[j]) {
score += workingIntensityMap[j];
}
}
if (score > bestScore) {
bestScore = score;
bestPin = i;
bestLineMap = lineMap;
}
}
if (bestPin === -1) break;
// Draw the best line
const from = pins[currentPin];
const to = pins[bestPin];
ctx.beginPath();
ctx.moveTo(from.x, from.y);
ctx.lineTo(to.x, to.y);
ctx.strokeStyle = stringColor;
ctx.lineWidth = 0.7;
ctx.stroke();
// Add to string sequence
stringSequence.push({ from: currentPin, to: bestPin });
// Update intensity map - reduce values where we drew a line
for (let j = 0; j < bestLineMap.length; j++) {
if (bestLineMap[j]) {
workingIntensityMap[j] = Math.max(0, workingIntensityMap[j] - 35);
}
}
// Move to next pin
currentPin = bestPin;
// Update progress bar every 10 strings
if (s % 10 === 0) {
const progress = s / numStrings * 100;
progressBar.style.width = progress + '%';
}
}
// Final progress update
progressBar.style.width = '100%';
}
// Create pin layout visualization
function createPinLayout(numPins, backgroundColor) {
const canvas = pinLayoutCanvas;
const ctx = canvas.getContext('2d');
// Clear canvas with background color
ctx.fillStyle = backgroundColor;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Add a board outline
const outlineColor = document.body.classList.contains('dark') ? '#fff' : '#111';
ctx.strokeStyle = outlineColor;
ctx.lineWidth = 2;
ctx.strokeRect(10, 10, canvas.width-20, canvas.height-20);
// Draw circle guide
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const radius = Math.min(canvas.width, canvas.height) * 0.4;
ctx.beginPath();
ctx.arc(centerX, centerY, radius, 0, Math.PI * 2);
ctx.strokeStyle = outlineColor;
ctx.lineWidth = 1;
ctx.stroke();
// Determine text color based on background
const isBackgroundDark = isColorDark(backgroundColor);
const textColor = isBackgroundDark ? '#fff' : '#111';
// Draw pins and numbers
for (let i = 0; i < numPins; i++) {
const angle = (i / numPins) * Math.PI * 2;
const x = centerX + radius * Math.cos(angle);
const y = centerY + radius * Math.sin(angle);
// Draw pin
ctx.beginPath();
ctx.arc(x, y, 3, 0, Math.PI * 2);
ctx.fillStyle = textColor;
ctx.fill();
// Only show labels for every 5th pin to avoid crowding
if (i % 5 === 0) {
const labelRadius = radius + 15;
const labelX = centerX + labelRadius * Math.cos(angle);
const labelY = centerY + labelRadius * Math.sin(angle);
ctx.fillStyle = textColor;
ctx.font = '10px monospace';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText((i + 1).toString(), labelX, labelY);
}
}
// Add center marker
ctx.beginPath();
ctx.arc(centerX, centerY, 3, 0, Math.PI * 2);
ctx.fillStyle = stringColorPicker.value;
ctx.fill();
// Add pin count text
ctx.fillStyle = textColor;
ctx.font = '12px monospace';
ctx.textAlign = 'center';
ctx.fillText(`${numPins} PINS ARRANGED IN A CIRCLE`, centerX, canvas.height - 20);
}
// Helper function to check if a color is dark
function isColorDark(hexColor) {
const r = parseInt(hexColor.substr(1, 2), 16);
const g = parseInt(hexColor.substr(3, 2), 16);
const b = parseInt(hexColor.substr(5, 2), 16);
const brightness = (r * 299 + g * 587 + b * 114) / 1000;
return brightness < 128;
}
// Create instructions for real-life implementation
function createInstructions(numPins, numStrings, stringColor) {
instructions.innerHTML = '';
// Materials needed
const materialsLi = document.createElement('li');
materialsLi.innerHTML = '<strong>MATERIALS:</strong><ul>' +
'<li>Wooden board (recommended size: 12" x 12")</li>' +
`<li>${numPins} pins or small nails</li>` +
`<li>String in color code: ${stringColor} (approx. ${Math.ceil(numStrings * 1.5)} feet)</li>` +
'<li>Hammer, ruler, compass</li>' +
'</ul>';
instructions.appendChild(materialsLi);
// Preparation
const prepLi = document.createElement('li');
prepLi.innerHTML = '<strong>PREPARATION:</strong><ul>' +
'<li>Mark center point of board</li>' +
'<li>Draw circle around center point</li>' +
`<li>Place ${numPins} pins evenly around circle</li>` +
'<li>Number pins 1 to ' + numPins + ' clockwise</li>' +
'</ul>';
instructions.appendChild(prepLi);
// String sequence
if (stringSequence.length > 0) {
const sequenceLi = document.createElement('li');
sequenceLi.innerHTML = '<strong>STRING SEQUENCE:</strong>';
// If many strings, show first 15 and then notify about download
if (stringSequence.length > 30) {
sequenceLi.innerHTML += '<p>First 15 connections:</p>';
const sequenceDiv = document.createElement('div');
for (let i = 0; i < 15; i++) {
const line = document.createElement('div');
line.textContent = `${i+1}: Connect pin ${stringSequence[i].from+1} to pin ${stringSequence[i].to+1}`;
sequenceDiv.appendChild(line);
}
sequenceLi.appendChild(sequenceDiv);
sequenceLi.innerHTML += '<p>Download complete instructions using button below</p>';
} else {
// Show all strings if less than 30
const sequenceDiv = document.createElement('div');
for (let i = 0; i < stringSequence.length; i++) {
const line = document.createElement('div');
line.textContent = `${i+1}: Connect pin ${stringSequence[i].from+1} to pin ${stringSequence[i].to+1}`;
sequenceDiv.appendChild(line);
}
sequenceLi.appendChild(sequenceDiv);
}
instructions.appendChild(sequenceLi);
}
}
// Download instructions as text file
downloadBtn.addEventListener('click', function() {
const numPins = parseInt(numPinsSlider.value);
const numStrings = parseInt(numStringsSlider.value);
const stringColor = stringColorPicker.value;
let text = "STRING ART INSTRUCTIONS\n";
text += "======================\n\n";
text += "MATERIALS NEEDED:\n";
text += "- Wooden board (12\" x 12\" or larger)\n";
text += `- ${numPins} pins or small nails\n`;
text += `- String in color ${stringColor}\n`;
text += "- Hammer, ruler, compass\n\n";
text += "SETUP INSTRUCTIONS:\n";
text += "1. Mark center of board\n";
text += "2. Draw circle around center\n";
text += `3. Place ${numPins} pins evenly around circle\n`;
text += "4. Number pins 1 to " + numPins + " clockwise\n\n";
text += "STRING SEQUENCE:\n";
for (let i = 0; i < stringSequence.length; i++) {
text += `${i+1}. Connect pin ${stringSequence[i].from+1} to pin ${stringSequence[i].to+1}\n`;
}
const blob = new Blob([text], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'string_art_instructions.txt';
a.click();
URL.revokeObjectURL(url);
successMessage.textContent = "Instructions downloaded successfully";
successMessage.style.display = "block";
setTimeout(() => {
successMessage.style.display = "none";
}, 3000);
});
</script>
</body>
</html>