-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime-spirals.html
More file actions
162 lines (149 loc) · 6.91 KB
/
Copy pathtime-spirals.html
File metadata and controls
162 lines (149 loc) · 6.91 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Time Spirals — Marvel Computer Fun, Program 4</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:15px; line-height:15px; letter-spacing:2px; 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; }
.panel { display:flex; flex-wrap:wrap; gap:14px; align-items:center; justify-content:center;
background:#111; border:1px solid #244; border-radius:8px; padding:12px 16px; max-width:600px; }
.panel label { font-size:12px; color:var(--phos); }
button { font-family:inherit; font-size:14px; background:#021002; color:var(--phos);
border:1px solid var(--phos-dim); border-radius:5px; padding:6px 14px; 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; }
.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 4 — TIME SPIRALS</div>
</div>
<div class="crt"><pre class="screen" id="screen"></pre></div>
<div class="status" id="status"> </div>
<div class="panel">
<label>SPEED:
<input type="range" id="speed" min="4" max="60" value="20" step="2">
</label>
<button id="run">RUN</button>
<button id="stop" disabled>STOP</button>
</div>
<details class="listing">
<summary>show original BASIC listing</summary>
<b>120</b> CH$="*"
<b>130</b> PW=1
<b>140</b> XO=SW/2:YO=SH/2
<b>150</b> FOR I=1 TO SH-2
<b>160</b> IF PW=1 THEN PW=-1:GOTO 180
<b>170</b> PW=1
<b>180</b> P2=-PW
<b>190</b> XN=XO-I*PW
<b>200-230</b> FOR PX=XO TO XN STEP P2 : plot(YO,PX) CH$ : NEXT
<b>240</b> XO=XN
<b>250</b> YN=YO-I*PW
<b>260-290</b> FOR PY=YO TO YN STEP P2 : plot(PY,XO) CH$ : NEXT
<b>300</b> YO=YN
<b>310</b> NEXT
<b>320</b> IF CH$ <>" " THEN CH$=" ":GOTO 140
<b>330</b> RX=CS:GOSUB 930
<b>340</b> CH$=CHR$(RD+BC)
<b>350</b> GOTO 140
</details>
<script>
/* 900-Line setup (Commodore 64 profile) + 970: BC=33, CS=95 */
const SW = 40, SH = 24;
const BC = 33, CS = 95;
const screenEl = document.getElementById('screen');
const speedEl = document.getElementById('speed');
const runBtn = document.getElementById('run');
const stopBtn = document.getElementById('stop');
const statusEl = document.getElementById('status');
/* Turtle path: lines 140-310 produce a fixed sequence of (VT,HT) plot cells.
PW ends at 1 each pass (SH-2 is even), so the path is identical every pass
and the space-erase aligns with the draw. */
function buildPath() {
const path = [];
let XO = Math.floor(SW / 2), YO = Math.floor(SH / 2); // line 140
let PW = 1; // line 130
for (let I = 1; I <= SH - 2; I++) { // line 150
PW = (PW === 1) ? -1 : 1; // lines 160-170
const P2 = -PW; // line 180
const XN = XO - I * PW; // line 190
for (let PX = XO; P2 > 0 ? PX <= XN : PX >= XN; PX += P2) path.push([YO, PX]); // 200-230
XO = XN; // line 240
const YN = YO - I * PW; // line 250
for (let PY = YO; P2 > 0 ? PY <= YN : PY >= YN; PY += P2) path.push([PY, XO]); // 260-290
YO = YN; // line 300
}
return path;
}
function glyph(code) { return (code >= 33 && code <= 126) ? String.fromCharCode(code) : '#'; }
function randomChar() { const rd = Math.floor(Math.random() * CS) + 1; return glyph(rd + BC); } // 930/340
/* line 320-340: '*' -> ' ' -> random -> ' ' -> random -> ... */
function nextChar(prev) {
if (prev !== ' ') return ' ';
return randomChar();
}
const PATH = buildPath();
let grid, timer = null, ci = 0, ch = '*';
function clearGrid() { grid = Array.from({ length: SH }, () => new Array(SW).fill(' ')); }
function render() { screenEl.textContent = grid.map(r => r.join('')).join('\n'); }
function stop() {
if (timer) { clearInterval(timer); timer = null; }
runBtn.disabled = false; stopBtn.disabled = true;
statusEl.textContent = 'STOPPED. PRESS RUN TO TRAVEL AGAIN.';
}
function run() {
stop();
clearGrid(); render();
ci = 0; ch = '*';
runBtn.disabled = true; stopBtn.disabled = false;
const perTick = parseInt(speedEl.value, 10);
timer = setInterval(() => {
for (let k = 0; k < perTick; k++) {
if (ci >= PATH.length) { // finished a pass (line 310 done)
ch = nextChar(ch); // lines 320-340
ci = 0;
if (ch !== ' ') clearGrid(); // a fresh draw starts on a clean screen after erase
}
const [vt, ht] = PATH[ci++];
const r = vt - 1, c = ht - 1; // 910 maps VT,HT (1-based) to 0-based cell
if (r >= 0 && r < SH && c >= 0 && c < SW) grid[r][c] = ch;
}
render();
statusEl.textContent = (ch === ' ') ? 'ERASING...' : "DRAWING WITH '" + ch + "'";
}, 30);
}
runBtn.addEventListener('click', run);
stopBtn.addEventListener('click', stop);
clearGrid(); render();
run(); // auto-start the trip
</script>
</body>
</html>