-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmrwizard.html
More file actions
422 lines (366 loc) · 15.7 KB
/
mrwizard.html
File metadata and controls
422 lines (366 loc) · 15.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mr. Wizard Atari Drawing (HTML5) - Enhanced</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: black;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
font-family: 'Press Start 2P', cursive; /* Optional: for a retro feel */
color: lime; /* For menu text */
flex-direction: column;
user-select: none; /* Prevent text selection */
}
canvas {
border: 2px solid #333;
background-color: #000;
cursor: crosshair;
}
#menu {
position: absolute;
top: 20px;
left: 20px;
background-color: rgba(0, 0, 0, 0.7);
padding: 10px;
border: 1px solid #555;
color: lime;
font-size: 14px;
line-height: 1.6;
z-index: 10; /* Ensure menu is on top */
}
#menu p {
margin: 0;
}
#menu p span {
color: #FFFF00; /* Highlighted text */
}
#controls {
margin-top: 10px;
display: flex;
gap: 10px;
flex-wrap: wrap; /* Allow controls to wrap */
justify-content: center;
align-items: center;
padding: 10px;
background-color: rgba(0, 0, 0, 0.7);
border: 1px solid #555;
}
#controls button, #controls label, #controls input[type="range"], #controls input[type="number"] {
background-color: #333;
color: lime;
border: 1px solid #555;
padding: 8px 15px;
cursor: pointer;
font-family: 'Press Start 2P', cursive;
font-size: 12px;
white-space: nowrap; /* Prevent text wrapping */
}
#controls button:hover {
background-color: #555;
}
#controls label {
background-color: transparent;
border: none;
padding: 0;
margin-right: 5px;
}
#controls input[type="range"] {
width: 120px;
height: 25px; /* Adjust height for better appearance */
-webkit-appearance: none;
background: #555;
outline: none;
border-radius: 5px;
border: 1px solid #777;
}
#controls input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 15px;
height: 15px;
background: lime;
border-radius: 50%;
cursor: pointer;
}
#controls input[type="number"] {
width: 60px;
text-align: center;
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
</head>
<body>
<div id="menu">
<p>MAIN</p>
<p><span id="lineMenuText">LINE</span></p>
<p>POINT</p>
<p>COLOR</p>
<p>DRAWING</p>
<p>QUAD</p>
<p><span id="clearMenuText">CLEAR</span></p>
<p><span id="startMenuText">START</span></p>
<p><span id="eraseMenuText">ERASE</span></p>
<p>PAINTING 1</p>
<p>TYPE A RETURN AFTER</p>
<p>ALL COMMANDS</p>
<p>COPYRIGHT ATARI 1979</p>
</div>
<canvas id="atariCanvas"></canvas>
<div id="controls">
<button id="clearBtn">CLEAR</button>
<button id="toggleAnimationBtn">RESUME ANIMATION</button>
<button id="eraseBtn">ERASE</button>
<button id="lineBtn">LINE</button>
<button id="autoDrawBtn">AUTO DRAW</button>
<label for="colorSpeed">Color Speed:</label>
<input type="range" id="colorSpeed" min="1" max="100" value="100">
<label for="numShapes">Auto Shapes:</label>
<input type="number" id="numShapes" min="1" max="10" value="3">
<label for="numTrails">Auto Trails:</label>
<input type="number" id="numTrails" min="10" max="200" value="50">
</div>
<script>
const canvas = document.getElementById('atariCanvas');
const ctx = canvas.getContext('2d');
canvas.width = 640;
canvas.height = 480;
let drawing = false;
let erasing = false;
let autoDrawing = false;
let lastX, lastY;
let drawnSegments = []; // Stores { startX, startY, endX, endY, baseColorIndex, type: 'line'/'erase' }
let animationActive = false; // Changed: Animation is paused by default
let animationFrameCount = 0;
let animationSpeedFactor = 100; // Changed: Default to max speed (100)
const colorPalette = [
'#FF00FF', // Magenta
'#00FFFF', // Cyan
'#FFFF00', // Yellow
'#00FF00', // Green
'#FF8000', // Orange
'#8000FF', // Purple
'#0080FF', // Sky Blue
'#FF0080' // Hot Pink
];
let colorCycleOffset = 0;
const numSectors = 8; // For kaleidoscope symmetry
// Auto Drawing specific variables
let autoShapesToDraw = 3;
let autoTrailsPerShape = 50;
let currentAutoShape = 0;
let currentAutoTrail = 0;
let autoStartPoint = { x: 0, y: 0 };
let autoEndPoint = { x: 0, y: 0 };
let autoTargetPoint = { x: 0, y: 0 };
let autoColorIndex = 0;
// --- DOM Elements ---
const clearBtn = document.getElementById('clearBtn');
const toggleAnimationBtn = document.getElementById('toggleAnimationBtn');
const eraseBtn = document.getElementById('eraseBtn');
const lineBtn = document.getElementById('lineBtn');
const autoDrawBtn = document.getElementById('autoDrawBtn');
const colorSpeedSlider = document.getElementById('colorSpeed');
const numShapesInput = document.getElementById('numShapes');
const numTrailsInput = document.getElementById('numTrails');
// Menu text elements for highlighting
const lineMenuText = document.getElementById('lineMenuText');
const clearMenuText = document.getElementById('clearMenuText');
const startMenuText = document.getElementById('startMenuText');
const eraseMenuText = document.getElementById('eraseMenuText');
// --- Functions ---
function drawSymmetricLine(x1, y1, x2, y2, colorIdx, isErasing = false) {
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
for (let i = 0; i < numSectors; i++) {
ctx.save();
ctx.translate(centerX, centerY);
ctx.rotate(i * (Math.PI * 2 / numSectors)); // Rotate by sector angle
if (isErasing) {
ctx.strokeStyle = 'black'; // Erase by drawing in background color
ctx.lineWidth = 10; // Thicker for erasing
ctx.lineCap = 'round';
} else {
ctx.strokeStyle = colorPalette[(colorIdx + colorCycleOffset) % colorPalette.length];
ctx.lineWidth = 2;
ctx.lineCap = 'butt';
}
ctx.beginPath();
ctx.moveTo(x1 - centerX, y1 - centerY);
ctx.lineTo(x2 - centerX, y2 - centerY);
ctx.stroke();
// Draw mirrored line across Y-axis within this sector for double symmetry
ctx.beginPath();
ctx.moveTo(-(x1 - centerX), y1 - centerY);
ctx.lineTo(-(x2 - centerX), y2 - centerY);
ctx.stroke();
ctx.restore();
}
}
function setDrawingMode(mode) {
erasing = (mode === 'erase');
autoDrawing = (mode === 'auto');
drawing = false; // Disable manual drawing when changing modes
// Update button styles
lineBtn.style.backgroundColor = (mode === 'line') ? '#555' : '#333';
eraseBtn.style.backgroundColor = (mode === 'erase') ? '#555' : '#333';
autoDrawBtn.style.backgroundColor = (mode === 'auto') ? '#555' : '#333';
// Update cursor
if (erasing) {
canvas.style.cursor = 'url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' width=\'24\' height=\'24\'><rect x=\'0\' y=\'0\' width=\'24\' height=\'24\' fill=\'white\' stroke=\'black\' stroke-width=\'1\'/></svg>") 12 12, default';
} else if (autoDrawing) {
canvas.style.cursor = 'default';
} else { // line mode
canvas.style.cursor = 'crosshair';
}
// Update menu text highlights
lineMenuText.style.color = (mode === 'line') ? '#FFFF00' : 'lime';
eraseMenuText.style.color = (mode === 'erase') ? '#FFFF00' : 'lime';
// No direct menu item for auto draw, so we'll highlight 'START' for it
startMenuText.style.color = (mode === 'auto') ? '#FFFF00' : 'lime';
// Reset auto drawing state if switching away from it
if (!autoDrawing) {
currentAutoShape = 0;
currentAutoTrail = 0;
} else {
// Initialize for auto-draw
resetAutoDrawState();
}
}
function resetAutoDrawState() {
currentAutoShape = 0;
currentAutoTrail = 0;
autoStartPoint = { x: Math.random() * canvas.width, y: Math.random() * canvas.height };
autoTargetPoint = { x: Math.random() * canvas.width, y: Math.random() * canvas.height };
autoColorIndex = Math.floor(Math.random() * colorPalette.length);
}
function handleAutoDrawing() {
if (currentAutoShape >= autoShapesToDraw) {
// All shapes drawn, stop auto drawing
setDrawingMode('line'); // Revert to manual line drawing
return;
}
if (currentAutoTrail >= autoTrailsPerShape) {
// Move to next shape
currentAutoShape++;
currentAutoTrail = 0;
resetAutoDrawState(); // New random start/target for next shape
return;
}
// Interpolate points for the "trail" effect
const ratio = currentAutoTrail / autoTrailsPerShape;
const x = autoStartPoint.x + (autoTargetPoint.x - autoStartPoint.x) * ratio;
const y = autoStartPoint.y + (autoTargetPoint.y - autoStartPoint.y) * ratio;
// Store the segment
if (currentAutoTrail > 0) { // Only draw lines after the first point
drawnSegments.push({
startX: autoEndPoint.x, // Previous end point
startY: autoEndPoint.y,
endX: x,
endY: y,
baseColorIndex: autoColorIndex,
type: 'line'
});
}
autoEndPoint = { x: x, y: y }; // Update current end point
currentAutoTrail++;
}
function animate() {
// Control animation speed by skipping frames
if (animationActive) {
animationFrameCount++;
// Invert the speed logic: 100 means skip 0 frames, 1 means skip 99 frames
const skipFrames = Math.floor(100 - animationSpeedFactor);
if (skipFrames > 0 && animationFrameCount % (skipFrames + 1) !== 0) {
requestAnimationFrame(animate);
return;
}
}
ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear the whole canvas
if (animationActive) { // Only cycle colors if animation is active
colorCycleOffset = (colorCycleOffset + 1) % colorPalette.length; // Cycle colors
}
if (autoDrawing) {
handleAutoDrawing();
}
// Redraw all stored segments with updated colors
drawnSegments.forEach(segment => {
drawSymmetricLine(segment.startX, segment.startY, segment.endX, segment.endY, segment.baseColorIndex, segment.type === 'erase');
});
requestAnimationFrame(animate);
}
// --- Event Listeners ---
canvas.addEventListener('mousedown', (e) => {
if (!autoDrawing) { // Only allow manual drawing if not in auto mode
drawing = true;
lastX = e.offsetX;
lastY = e.offsetY;
}
});
canvas.addEventListener('mousemove', (e) => {
if (!drawing) return;
const currentX = e.offsetX;
const currentY = e.offsetY;
const angle = Math.atan2(currentY - lastY, currentX - lastX);
const baseColorIndex = Math.floor((angle / (Math.PI * 2) + 0.5) * colorPalette.length) % colorPalette.length;
drawnSegments.push({
startX: lastX,
startY: lastY,
endX: currentX,
endY: currentY,
baseColorIndex: baseColorIndex,
type: erasing ? 'erase' : 'line'
});
lastX = currentX;
lastY = currentY;
});
canvas.addEventListener('mouseup', () => {
drawing = false;
});
canvas.addEventListener('mouseleave', () => {
drawing = false;
});
// --- Control Button Event Listeners ---
clearBtn.addEventListener('click', () => {
drawnSegments = []; // Clear all segments
ctx.clearRect(0, 0, canvas.width, canvas.height); // Immediately clear canvas
clearMenuText.style.color = '#FFFF00'; // Highlight
setTimeout(() => clearMenuText.style.color = 'lime', 200); // Unhighlight
});
toggleAnimationBtn.addEventListener('click', () => {
animationActive = !animationActive;
toggleAnimationBtn.textContent = animationActive ? 'PAUSE ANIMATION' : 'RESUME ANIMATION';
});
eraseBtn.addEventListener('click', () => setDrawingMode('erase'));
lineBtn.addEventListener('click', () => setDrawingMode('line'));
autoDrawBtn.addEventListener('click', () => setDrawingMode('auto'));
colorSpeedSlider.addEventListener('input', (e) => {
animationSpeedFactor = parseInt(e.target.value, 10);
});
numShapesInput.addEventListener('change', (e) => {
autoShapesToDraw = parseInt(e.target.value, 10);
if (autoDrawing) { // Restart auto-draw if values change while active
resetAutoDrawState();
}
});
numTrailsInput.addEventListener('change', (e) => {
autoTrailsPerShape = parseInt(e.target.value, 10);
if (autoDrawing) { // Restart auto-draw if values change while active
resetAutoDrawState();
}
});
// Initialize default mode and settings
setDrawingMode('line'); // Start in manual line drawing mode
// Set initial slider value
colorSpeedSlider.value = animationSpeedFactor;
// Start the animation loop
animate();
</script>
</body>
</html>