-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalpha-sort.html
More file actions
186 lines (173 loc) · 7.55 KB
/
Copy pathalpha-sort.html
File metadata and controls
186 lines (173 loc) · 7.55 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alpha Sort — Marvel Computer Fun, Program 2</title>
<link rel="icon" type="image/svg+xml" href="assets/favicon.svg">
<style>
:root { --phos:#33ff66; --phos-dim:#1f9c3f; --amber:#ffcc00; }
* { box-sizing:border-box; }
html,body { margin:0; padding:0; background:#0a0a0a; min-height:100%;
color:var(--phos); font-family:"Courier New",monospace; }
body { display:flex; flex-direction:column; align-items:center; gap:14px; padding:24px 12px 40px; }
.title { text-align:center; line-height:1.3; }
.title .marvel { color:var(--amber); letter-spacing:3px; font-weight:bold; font-size:13px; }
.title .prog { color:#ff5a3c; font-size:22px; font-weight:bold; letter-spacing:1px;
text-shadow:0 0 6px rgba(255,90,60,.5); }
.crt { position:relative; background:#020602; border:14px solid #2b2b2b; border-radius:18px;
padding:16px; box-shadow:0 0 0 2px #000,0 12px 40px rgba(0,0,0,.8),inset 0 0 60px rgba(0,0,0,.9); }
.crt::after { content:""; position:absolute; inset:16px; border-radius:6px;
background:repeating-linear-gradient(to bottom,rgba(0,0,0,0) 0 2px,rgba(0,0,0,.28) 3px 4px);
pointer-events:none; animation:flicker 5s infinite; }
@keyframes flicker { 0%,100%{opacity:.85} 50%{opacity:1} 92%{opacity:.78} }
.screen { margin:0; font-size:16px; line-height:18px; letter-spacing:1px; white-space:pre;
color:var(--phos); text-shadow:0 0 4px var(--phos),0 0 8px var(--phos-dim);
background:radial-gradient(ellipse at center,#031003 0%,#010401 100%);
padding:12px 14px; border-radius:6px; min-width:41ch; min-height:200px; }
.panel { display:flex; flex-wrap:wrap; gap:12px; align-items:center; justify-content:center;
background:#111; border:1px solid #244; border-radius:8px; padding:12px 16px; max-width:660px; }
.panel label { font-size:12px; color:var(--phos); }
input[type=text] { font-family:inherit; font-size:13px; background:#021002; color:var(--phos);
border:1px solid var(--phos-dim); border-radius:5px; padding:6px 10px; width:340px; }
select,button { font-family:inherit; font-size:14px; background:#021002; color:var(--phos);
border:1px solid var(--phos-dim); border-radius:5px; padding:6px 12px; cursor:pointer; }
button:hover { background:#03220a; box-shadow:0 0 8px var(--phos-dim); }
button:disabled { opacity:.4; cursor:default; box-shadow:none; }
input[type=range]{ accent-color:var(--phos); }
.status { font-size:12px; color:var(--phos-dim); text-align:center; min-height:16px; letter-spacing:1px; }
.decoded { font-size:14px; color:var(--amber); text-align:center; min-height:18px;
text-shadow:0 0 6px rgba(255,204,0,.4); letter-spacing:1px; }
.listing { max-width:560px; width:100%; background:#0d0d0d; border:1px solid #222; border-radius:8px;
padding:12px 16px; color:#8fbf9f; font-size:11px; line-height:1.45; white-space:pre-wrap; }
.listing b { color:var(--amber); }
details summary { cursor:pointer; color:var(--phos); font-size:13px; }
</style>
</head>
<body>
<div class="title">
<div class="marvel">MARVEL SUPER HEROES • COMPUTER FUN</div>
<div class="prog">PROGRAM 2 — ALPHA SORT</div>
</div>
<div class="crt"><pre class="screen" id="screen"></pre></div>
<div class="decoded" id="decoded"></div>
<div class="status" id="status">READY.</div>
<div class="panel">
<label>WORDS (comma-separated — reads to STOP):<br>
<input type="text" id="words" value="NOW,VANISH,GRIPPING,CHAINS,RELEASE,YOUR,HOLD,THAT,BINDS,ALL">
</label>
<label>SPEED:
<input type="range" id="speed" min="40" max="600" value="200" step="20">
</label>
<button id="run">RUN</button>
<button id="stop" disabled>STOP</button>
</div>
<details class="listing">
<summary>show original BASIC listing</summary>
<b>110</b> DIM A$(25)
<b>130</b> N=1
<b>140</b> READ A$(N)
<b>150</b> IF A$(N)="STOP" THEN N=N-1:GOTO 170
<b>160</b> N=N+1:GOTO 140
<b>170</b> FOR I=1 TO N-1
<b>180</b> FOR J=I TO N
<b>190-250</b> .. draw " ==> " arrows at rows I and J ..
<b>260</b> IF A$(I)<A$(J) THEN 300
<b>270-290</b> T$=A$(I):A$(I)=A$(J):A$(J)=T$
<b>310</b> WT=WU:GOSUB 920 (WU=100)
<b>320-360</b> .. redraw word list, arrow at row I ..
<b>370</b> NEXT J,I
<b>390-400</b> VT=N:HT=17 : PRINT "** DONE **"
</details>
<script>
const SW = 40;
const DEFAULT = "NOW,VANISH,GRIPPING,CHAINS,RELEASE,YOUR,HOLD,THAT,BINDS,ALL";
const screenEl = document.getElementById('screen');
const wordsEl = document.getElementById('words');
const speedEl = document.getElementById('speed');
const runBtn = document.getElementById('run');
const stopBtn = document.getElementById('stop');
const statusEl = document.getElementById('status');
const decodedEl = document.getElementById('decoded');
let timer = null;
/* Compose one cursor-addressed screen: N rows, cols 1-5 markers, words at col 6,
optional "** DONE **" at (doneRow, col 17) -- exactly the layout the 910 cursor
moves produce in the listing. */
function compose(A, markers, doneRow) {
const N = A.length;
const rows = [];
for (let r = 1; r <= N; r++) {
const line = new Array(SW).fill(' ');
const m = markers.includes(r) ? ' ==> ' : ' ';
for (let k = 0; k < 5; k++) line[k] = m[k];
const w = A[r - 1];
for (let k = 0; k < w.length && 5 + k < SW; k++) line[5 + k] = w[k];
rows.push(line);
}
if (doneRow) {
const txt = '** DONE **';
for (let k = 0; k < txt.length && 16 + k < SW; k++) rows[doneRow - 1][16 + k] = txt[k];
}
return rows.map(a => a.join('').replace(/\s+$/,'')).join('\n');
}
function buildFrames(A0) {
const A = A0.slice();
const N = A.length;
const frames = [];
frames.push({ s: compose(A, [], null), note: 'READING DATA... ' + N + ' WORDS' });
for (let I = 1; I <= N - 1; I++) { // line 170
for (let J = I; J <= N; J++) { // line 180
frames.push({
s: compose(A, [I, J], null),
note: 'COMPARE "' + A[I-1] + '" vs "' + A[J-1] + '"'
});
let swapped = false;
if (!(A[I-1] < A[J-1])) { // line 260 (inverse => swap)
const t = A[I-1]; A[I-1] = A[J-1]; A[J-1] = t; // lines 270-290
swapped = true;
}
frames.push({
s: compose(A, [I], null),
note: swapped ? 'SWAP -> "' + A[I-1] + '" rises to row ' + I : 'no swap'
});
}
}
frames.push({ s: compose(A, [], N), note: '** DONE **', done: true, sorted: A.slice() });
return frames;
}
function parseWords(str) {
const ws = str.split(',').map(w => w.trim().toUpperCase()).filter(Boolean);
return ws.slice(0, 25); // DIM A$(25)
}
function stop() {
if (timer) { clearInterval(timer); timer = null; }
runBtn.disabled = false;
stopBtn.disabled = true;
}
function run() {
stop();
const words = parseWords(wordsEl.value);
if (words.length < 2) { statusEl.textContent = 'ENTER AT LEAST 2 WORDS.'; return; }
const frames = buildFrames(words);
decodedEl.textContent = '';
runBtn.disabled = true;
stopBtn.disabled = false;
let k = 0;
const speed = parseInt(speedEl.value, 10);
timer = setInterval(() => {
if (k >= frames.length) { stop(); return; }
const f = frames[k++];
screenEl.textContent = f.s;
statusEl.textContent = f.note;
if (f.done) {
decodedEl.textContent = 'DECODED: ' + f.sorted.join(' ');
stop();
}
}, speed);
}
runBtn.addEventListener('click', run);
stopBtn.addEventListener('click', () => { stop(); statusEl.textContent = 'STOPPED.'; });
screenEl.textContent = compose(parseWords(DEFAULT), [], null);
</script>
</body>
</html>