-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHalfTone_gcode_makerWebApp.html
More file actions
179 lines (156 loc) · 8.14 KB
/
HalfTone_gcode_makerWebApp.html
File metadata and controls
179 lines (156 loc) · 8.14 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
<!DOCTYPE html>
<html lang="sl">
<head>
<meta charset="UTF-8">
<title>Halftone Master V6.2 - Skaliranje</title>
<style>
:root { --bg: #121212; --accent: #00adb5; --text: #e0e0e0; --panel: #1e1e1e; --border: #333; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); margin: 0; display: flex; height: 100vh; }
#sidebar { width: 360px; background: var(--panel); padding: 20px; border-right: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
h2 { color: var(--accent); font-size: 0.8rem; text-transform: uppercase; border-bottom: 1px solid var(--border); padding-bottom: 5px; margin: 10px 0 5px; }
.group { display: flex; flex-direction: column; gap: 3px; }
label { font-size: 0.7rem; color: #888; }
input { background: #2b2b2b; border: 1px solid var(--border); color: white; padding: 8px; border-radius: 4px; font-size: 0.85rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
button { background: var(--accent); color: white; border: none; padding: 12px; border-radius: 4px; cursor: pointer; font-weight: bold; margin-top: 10px; }
button:hover { filter: brightness(1.2); }
#main { flex-grow: 1; padding: 20px; display: flex; flex-direction: column; gap: 15px; }
#terminal { flex-grow: 1; background: #000; color: var(--accent); font-family: monospace; padding: 15px; border-radius: 8px; overflow-y: auto; font-size: 0.75rem; border: 1px solid #222; white-space: pre; }
</style>
</head>
<body>
<div id="sidebar">
<h2 style="margin-top:0">📁 Datoteka & Velikost</h2>
<input type="file" id="fileInput" accept=".svg">
<div class="group">
<label>Ciljna širina slike (mm)</label>
<input type="number" id="targetWidth" value="200">
</div>
<h2>🎨 Parametri čopiča</h2>
<div class="grid-2">
<div class="group"><label>Čopič (mm)</label><input type="number" id="brushW" value="2.0" step="0.1"></div>
<div class="group"><label>Prekrivanje</label><input type="number" id="overlap" value="0.8" step="0.05"></div>
</div>
<h2>🛢️ Namakanje (Wipe)</h2>
<div class="grid-2">
<div class="group"><label>Dip X</label><input type="number" id="dipX" value="91.0"></div>
<div class="group"><label>Dip Y</label><input type="number" id="dipY" value="25.0"></div>
</div>
<div class="grid-2">
<div class="group"><label>Dip Z (Dno)</label><input type="number" id="dipZ" value="1.5"></div>
<div class="group"><label>Wipe Radius (mm)</label><input type="number" id="wipeR" value="29.0"></div>
</div>
<div class="group"><label>Max pot barvanja (mm)</label><input type="number" id="maxDist" value="1000"></div>
<h2>🚀 Višine & Hitrost</h2>
<div class="grid-2">
<div class="group"><label>Z Safe (Paint)</label><input type="number" id="zSafe" value="5.0"></div>
<div class="group"><label>Z Safe Dip (Rob)</label><input type="number" id="zSafeDip" value="18.0"></div>
</div>
<div class="grid-2">
<div class="group"><label>Hitrost (F)</label><input type="number" id="feedRate" value="1500"></div>
<div class="group"><label>Wipe Hitrost</label><input type="number" id="feedWipe" value="300"></div>
</div>
<div class="grid-2">
<div class="group"><label>X Offset</label><input type="number" id="xOff" value="33"></div>
<div class="group"><label>Y Offset</label><input type="number" id="yOff" value="110"></div>
</div>
<button id="generateBtn">USTVARI G-KODO</button>
<button id="downloadBtn" style="background:#444">PRENESI .GCODE</button>
</div>
<div id="main">
<div id="terminal">Naloži SVG in nastavi širino...</div>
</div>
<script>
let rawCircles = [];
let generatedGCode = "";
document.getElementById('fileInput').addEventListener('change', (e) => {
const reader = new FileReader();
reader.onload = (event) => {
const parser = new DOMParser();
const doc = parser.parseFromString(event.target.result, "image/svg+xml");
rawCircles = Array.from(doc.querySelectorAll('circle')).map(c => ({
cx: parseFloat(c.getAttribute('cx') || 0),
cy: parseFloat(c.getAttribute('cy') || 0),
r: parseFloat(c.getAttribute('r') || 0)
}));
document.getElementById('terminal').innerText = `SVG naložen: najdenih ${rawCircles.length} krogov.`;
};
reader.readAsText(e.target.files[0]);
});
document.getElementById('generateBtn').addEventListener('click', () => {
if (!rawCircles.length) return alert("Naloži SVG!");
const cfg = {
targetW: parseFloat(document.getElementById('targetWidth').value),
brush: parseFloat(document.getElementById('brushW').value),
overlap: parseFloat(document.getElementById('overlap').value),
dipX: parseFloat(document.getElementById('dipX').value),
dipY: parseFloat(document.getElementById('dipY').value),
dipZ: parseFloat(document.getElementById('dipZ').value),
wipeR: parseFloat(document.getElementById('wipeR').value),
zHigh: parseFloat(document.getElementById('zSafeDip').value),
zLow: parseFloat(document.getElementById('zSafe').value),
f: document.getElementById('feedRate').value,
fw: document.getElementById('feedWipe').value,
maxD: parseFloat(document.getElementById('maxDist').value),
xOff: parseFloat(document.getElementById('xOff').value),
yOff: parseFloat(document.getElementById('yOff').value)
};
// Skaliranje logike
const minX = Math.min(...rawCircles.map(c => c.cx - c.r));
const maxX = Math.max(...rawCircles.map(c => c.cx + c.r));
const currentSVGWidth = maxX - minX;
const scale = cfg.targetW / currentSVGWidth;
const maxY = Math.max(...rawCircles.map(c => c.cy + c.r));
let g = ["G90", "G21", "; Halftone Master V6.2"];
g.push(`G0 Z${cfg.zHigh.toFixed(3)} ; Zacetni dvig`);
let dSinceDip = 0;
let curPos = { x: cfg.dipX, y: cfg.dipY };
const performDip = () => {
g.push(`; --- Namakanje & Wipe ---`);
g.push(`G0 Z${cfg.zHigh} F${cfg.f}`);
g.push(`G0 X${cfg.dipX} Y${cfg.dipY}`);
g.push(`G1 Z${cfg.dipZ} F800`);
g.push(`G4 P200`);
g.push(`G1 X${(cfg.dipX + cfg.wipeR).toFixed(3)} Y${cfg.dipY} F${cfg.f} ; Na rob`);
g.push(`G1 Z${cfg.zHigh} F${cfg.fw} ; Pocasen Wipe dvig`);
};
performDip();
rawCircles.forEach(c => {
const x = (c.cx - minX) * scale + cfg.xOff;
const y = (maxY - c.cy) * scale + cfg.yOff;
const r = c.r * scale;
const step = cfg.brush * (1 - cfg.overlap);
const approxPathLen = (Math.PI * r * r) / step;
if (dSinceDip + approxPathLen > cfg.maxD) {
g.push(`G0 Z${cfg.zHigh}`);
performDip();
dSinceDip = 0;
}
g.push(`G0 X${x.toFixed(3)} Y${y.toFixed(3)} F${cfg.f}`);
g.push(`G0 Z${cfg.zLow} ; Paint Height`);
g.push(`G1 Z0 F600 ; Dotik papirja`);
// Spirala
let t = 0;
while (true) {
let currR = (step * t) / (2 * Math.PI);
if (currR > r) break;
g.push(`G1 X${(x + currR * Math.cos(t)).toFixed(3)} Y${(y + currR * Math.sin(t)).toFixed(3)}`);
t += 0.5;
}
g.push(`G0 Z${cfg.zLow}`);
dSinceDip += approxPathLen;
});
g.push(`G0 Z${cfg.zHigh}`, "M2");
generatedGCode = g.join("\n");
document.getElementById('terminal').innerText = generatedGCode;
});
document.getElementById('downloadBtn').onclick = () => {
const blob = new Blob([generatedGCode], { type: 'text/plain' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = "halftone_scaled.gcode";
link.click();
};
</script>
</body>
</html>