-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.html
More file actions
544 lines (475 loc) · 22.6 KB
/
Copy patharray.html
File metadata and controls
544 lines (475 loc) · 22.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>C / ARRAYS — Memory Blocks</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=Syncopate:wght@400;700&family=JetBrains+Mono:wght@300;400;700&display=swap" rel="stylesheet">
<style>
/* --- 1. CORE VARIABLES --- */
:root {
--bg-color: #050505;
--surface-color: #0b0b0b;
--card-bg: #111111;
--text-primary: #ffffff;
--text-secondary: #999999;
--accent-color: #ff3c00; /* International Orange */
--accent-glow: rgba(255, 60, 0, 0.15);
--border-color: rgba(255, 255, 255, 0.12);
--grid-line: rgba(255, 255, 255, 0.04);
/* Typography */
--font-display: 'Syncopate', sans-serif;
--font-body: 'Space Grotesk', sans-serif;
--font-code: 'JetBrains Mono', monospace;
--easing: cubic-bezier(0.16, 1, 0.3, 1);
}
/* --- 2. RESET & BASE --- */
* { margin: 0; padding: 0; box-sizing: border-box; cursor: none; }
html { scroll-behavior: smooth; }
body {
background-color: var(--bg-color);
color: var(--text-primary);
font-family: var(--font-body);
overflow-x: hidden;
-webkit-font-smoothing: antialiased;
line-height: 1.7;
}
a { text-decoration: none; color: inherit; cursor: none; }
ul { list-style: none; }
/* --- 3. UTILITIES --- */
/* Film Grain Noise */
.noise {
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
pointer-events: none; z-index: 900; opacity: 0.035;
background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='1'/%3E%3C/svg%3E");
}
/* Custom Magnetic Cursor */
.cursor-dot, .cursor-circle {
position: fixed; top: 0; left: 0; transform: translate(-50%, -50%);
border-radius: 50%; pointer-events: none; z-index: 9999;
}
.cursor-dot { width: 6px; height: 6px; background: var(--accent-color); }
.cursor-circle {
width: 40px; height: 40px; border: 1px solid rgba(255, 255, 255, 0.3);
transition: width 0.3s, height 0.3s, background-color 0.3s;
}
body.hovering .cursor-circle {
width: 80px; height: 80px; background: var(--accent-glow); border-color: var(--accent-color);
}
/* --- 4. LAYOUT --- */
.container {
max-width: 1400px; margin: 0 auto; padding: 0 5vw;
}
section {
padding: 8rem 0;
position: relative;
border-bottom: 1px solid var(--grid-line);
}
/* --- 5. NAVIGATION --- */
nav {
position: fixed; top: 0; left: 0; width: 100%; padding: 1.5rem 5vw;
display: flex; justify-content: space-between; align-items: center;
z-index: 1000; background: rgba(5,5,5,0.85); backdrop-filter: blur(12px);
border-bottom: 1px solid var(--border-color);
}
.logo {
font-family: var(--font-display); font-weight: 700;
text-transform: uppercase; font-size: 1.1rem; letter-spacing: 2px;
color: white; transition: color 0.3s;
}
.logo span { color: var(--accent-color); }
.nav-links { display: flex; gap: 2rem; }
.nav-links a {
font-family: var(--font-code); font-size: 0.75rem; text-transform: uppercase;
position: relative; color: var(--text-secondary); letter-spacing: 1px;
transition: color 0.3s;
}
.nav-links a:hover { color: white; }
.nav-links a::after {
content: ''; position: absolute; bottom: -5px; left: 0; width: 0; height: 1px;
background: var(--accent-color); transition: width 0.3s var(--easing);
}
.nav-links a:hover::after { width: 100%; }
/* --- 6. HERO SECTION --- */
.hero {
min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
position: relative; overflow: hidden; border-bottom: none; padding-top: 10rem;
}
#heroCanvas {
position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: -1;
opacity: 0.3;
}
.hero h1 {
font-family: var(--font-display); font-size: clamp(3rem, 10vw, 7rem);
line-height: 0.95; text-transform: uppercase; font-weight: 700;
margin-bottom: 2rem; color: white;
}
.hero h1 span {
display: block; opacity: 0; transform: translateY(50px);
animation: textReveal 1s var(--easing) forwards;
}
.hero h1 span:nth-child(1) { animation-delay: 0.1s; }
.hero h1 span:nth-child(2) { animation-delay: 0.2s; color: transparent; -webkit-text-stroke: 1px white; }
.hero h1 span:nth-child(3) { animation-delay: 0.3s; color: var(--accent-color); -webkit-text-stroke: 0; }
.hero p {
font-family: var(--font-body); max-width: 600px; color: var(--text-secondary);
font-size: 1.1rem; line-height: 1.7; margin-bottom: 3rem;
opacity: 0; animation: fadeIn 1s 0.6s forwards;
}
.btn-group { display: flex; gap: 1.5rem; opacity: 0; animation: fadeIn 1s 0.8s forwards; }
.btn {
background: transparent; color: white; padding: 1rem 2.5rem;
font-family: var(--font-code); font-weight: 700; text-transform: uppercase;
border: 1px solid var(--border-color); transition: all 0.3s;
display: inline-flex; align-items: center; justify-content: center;
letter-spacing: 1px;
}
.btn-primary { background: var(--accent-color); border-color: var(--accent-color); color: #000; }
.btn:hover { transform: translateY(-4px); box-shadow: 0 10px 30px rgba(255, 60, 0, 0.15); }
/* --- 7. COMPONENTS & GRID --- */
.section-title {
font-family: var(--font-display); font-size: clamp(2rem, 5vw, 3.5rem);
margin-bottom: 1.5rem; color: white; text-transform: uppercase;
}
.section-desc {
color: var(--text-secondary); margin-bottom: 4rem; max-width: 800px;
font-size: 1.1rem; line-height: 1.8;
}
.grid-2 {
display: grid; grid-template-columns: repeat(auto-fill, minmax(450px, 1fr));
gap: 2rem;
}
.card {
background: var(--card-bg); border: 1px solid var(--border-color);
padding: 2.5rem; position: relative; transition: all 0.4s var(--easing);
overflow: hidden;
}
.card:hover { transform: translateY(-10px); border-color: var(--accent-color); }
.card h3 {
font-family: var(--font-display); font-size: 1.25rem; margin-bottom: 1rem;
color: white; text-transform: uppercase;
}
.card p, .card ul { color: var(--text-secondary); font-size: 0.95rem; line-height: 1.7; margin-bottom: 1rem; }
.card ul { padding-left: 1.2rem; list-style: square; }
.card ul li { margin-bottom: 0.5rem; }
/* --- 8. TERMINAL / CODE WINDOW (FIXED) --- */
.terminal-window {
background: #080808; border: 1px solid var(--border-color);
border-radius: 8px; overflow: hidden; margin-top: 1.5rem; margin-bottom: 1.5rem;
box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.terminal-header {
background: #151515; padding: 0.8rem 1.2rem; border-bottom: 1px solid #222;
display: flex; gap: 0.6rem; align-items: center;
}
.dot { width: 12px; height: 12px; border-radius: 50%; }
.code-content {
padding: 2rem;
font-family: var(--font-code);
font-size: 0.9rem;
line-height: 1.6;
color: #d4d4d4;
overflow-x: auto;
/* CRITICAL FIX: Preserves line breaks and spacing */
white-space: pre;
}
/* Syntax Highlighting */
.kw { color: #ff3c00; font-weight: bold; } /* Keyword */
.str { color: #a5d6ff; } /* String */
.num { color: #b5cea8; } /* Number */
.cmt { color: #6a9955; font-style: italic; } /* Comment */
.fn { color: #dcdcaa; } /* Function */
.type { color: #4ec9b0; } /* Type */
/* --- 9. SPECIAL BOXES --- */
.highlight-box {
border-left: 3px solid var(--accent-color); background: rgba(255, 60, 0, 0.05);
padding: 2rem; margin-top: 2rem; color: var(--text-secondary);
}
.highlight-box strong { color: white; display: block; margin-bottom: 0.5rem; }
.diagram {
background: var(--surface-color); padding: 2rem; border: 1px solid var(--border-color);
margin: 2rem 0; font-family: var(--font-code); color: #ccc; overflow-x: auto; white-space: pre;
}
/* --- 10. ANIMATIONS --- */
@keyframes textReveal { to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { to { opacity: 1; } }
.scroll-reveal { opacity: 0; transform: translateY(40px); transition: all 0.8s var(--easing); }
.scroll-reveal.in-view { opacity: 1; transform: translateY(0); }
/* --- 11. FOOTER --- */
footer {
padding: 6rem 5vw; border-top: 1px solid var(--grid-line); background: var(--card-bg);
text-align: center;
}
.footer-logo { font-family: var(--font-display); font-size: 2rem; margin-bottom: 2rem; display: block; color: white; }
.footer-credit { font-family: var(--font-code); color: var(--text-secondary); font-size: 0.8rem; }
/* Responsive */
@media (max-width: 900px) {
.nav-links { display: none; }
.hero h1 { font-size: 3.5rem; }
.grid-2 { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="noise"></div>
<div class="cursor-dot"></div>
<div class="cursor-circle"></div>
<nav>
<a href="#" class="logo">C / <span>ARR</span></a>
<div class="nav-links">
<a href="#intro" data-hover>1D</a>
<a href="#2d-arrays" data-hover>2D</a>
<a href="#memory" data-hover>Memory</a>
<a href="#decay" data-hover>Decay</a>
<a href="#functions" data-hover>Funcs</a>
<a href="#strings" data-hover>Strings</a>
</div>
</nav>
<section class="hero">
<canvas id="heroCanvas"></canvas>
<div class="container">
<h1>
<span>Arrays</span>
<span>&</span>
<span>Strings</span>
</h1>
<p>Master contiguous memory blocks, 2D matrices, array decay to pointers, string handling, and avoid buffer overflows.</p>
<div class="btn-group">
<a href="#intro" class="btn btn-primary" data-hover>Start Learning</a>
<a href="#memory" class="btn" data-hover>View Memory</a>
</div>
</div>
</section>
<section id="intro">
<div class="container">
<h2 class="section-title">1D Arrays</h2>
<p class="section-desc">A collection of elements of the same data type stored in contiguous memory.</p>
<div class="terminal-window scroll-reveal">
<div class="terminal-header"><span style="color:#666;">array1d.c</span></div>
<div class="code-content"><span class="kw">#include</span> <span class="str"><stdio.h></span>
<span class="kw">int</span> <span class="fn">main</span>() {
<span class="cmt">// Declare array of 5 integers</span>
<span class="kw">int</span> scores[<span class="num">5</span>];
<span class="cmt">// Initialize elements</span>
scores[0] = <span class="num">85</span>;
scores[1] = <span class="num">92</span>;
scores[4] = <span class="num">95</span>;
<span class="cmt">// Loop through array</span>
<span class="kw">for</span> (<span class="kw">int</span> i = <span class="num">0</span>; i < <span class="num">5</span>; i++) {
<span class="fn">printf</span>(<span class="str">"Index %d: %d\n"</span>, i, scores[i]);
}
<span class="kw">return</span> <span class="num">0</span>;
}</div>
</div>
<div class="diagram scroll-reveal">
Memory Layout (4 bytes per int):
Index Value Address
───────────────────────────
0 85 1000 ┐
1 92 1004 │ Contiguous
2 ?? 1008 │ Memory Block
3 ?? 1012 │
4 95 1016 ┘
</div>
<div class="grid-2">
<div class="card scroll-reveal" data-hover>
<h3>Declaration Styles</h3>
<div class="code-content" style="padding:1rem; background:transparent;">int arr1[10]; // Uninitialized
int arr2[] = {1, 2, 3}; // Size 3
int arr3[5] = {1, 2}; // [1, 2, 0, 0, 0]</div>
</div>
<div class="card scroll-reveal" data-hover>
<h3>Key Rules</h3>
<ul>
<li>Size is constant at compile time</li>
<li>Indices: 0 to (size-1)</li>
<li>No bounds checking!</li>
<li>Name is pointer to first element</li>
</ul>
</div>
</div>
</div>
</section>
<section id="2d-arrays">
<div class="container">
<h2 class="section-title">2D Arrays</h2>
<p class="section-desc">Matrices and tables. Arrays of arrays.</p>
<div class="terminal-window scroll-reveal">
<div class="terminal-header"><span style="color:#666;">matrix.c</span></div>
<div class="code-content"><span class="kw">int</span> matrix[<span class="num">2</span>][<span class="num">3</span>] = {
{<span class="num">1</span>, <span class="num">2</span>, <span class="num">3</span>}, <span class="cmt">// Row 0</span>
{<span class="num">4</span>, <span class="num">5</span>, <span class="num">6</span>} <span class="cmt">// Row 1</span>
};
<span class="cmt">// Access: matrix[row][col]</span>
<span class="fn">printf</span>(<span class="str">"%d"</span>, matrix[<span class="num">1</span>][<span class="num">2</span>]); <span class="cmt">// Output: 6</span></div>
</div>
</div>
</section>
<section id="memory">
<div class="container">
<h2 class="section-title">Memory Layout</h2>
<p class="section-desc">How multi-dimensional arrays are flattened in RAM.</p>
<div class="diagram scroll-reveal">
2D Array: int mat[2][2] = {{1,2}, {3,4}};
Logical View: Physical RAM (Row-Major Order):
┌───┬───┐ ┌───┬───┬───┬───┐
│ 1 │ 2 │ │ 1 │ 2 │ 3 │ 4 │
├───┼───┤ └───┴───┴───┴───┘
│ 3 │ 4 │ [0][0] [0][1] [1][0] [1][1]
└───┴───┘ Address increases linearly ----->
</div>
<div class="highlight-box scroll-reveal">
<strong>Row-Major Order:</strong> C stores arrays row by row. This is crucial for cache performance. Always loop through rows first, then columns.
</div>
</div>
</section>
<section id="decay">
<div class="container">
<h2 class="section-title">Array Decay</h2>
<p class="section-desc">The concept of arrays "decaying" into pointers when passed to functions.</p>
<div class="terminal-window scroll-reveal">
<div class="terminal-header"><span style="color:#666;">decay.c</span></div>
<div class="code-content"><span class="kw">void</span> <span class="fn">printSize</span>(<span class="kw">int</span> arr[]) {
<span class="cmt">// Decays to (int *), size is 8 bytes (pointer)</span>
<span class="fn">printf</span>(<span class="str">"%lu"</span>, <span class="kw">sizeof</span>(arr));
}
<span class="kw">int</span> <span class="fn">main</span>() {
<span class="kw">int</span> nums[<span class="num">10</span>];
<span class="cmt">// True size: 10 * 4 = 40 bytes</span>
<span class="fn">printf</span>(<span class="str">"%lu"</span>, <span class="kw">sizeof</span>(nums));
<span class="fn">printSize</span>(nums);
}</div>
</div>
</div>
</section>
<section id="strings">
<div class="container">
<h2 class="section-title">Strings</h2>
<p class="section-desc">Character arrays terminated by a null character <code>'\0'</code>.</p>
<div class="grid-2">
<div class="card scroll-reveal" data-hover>
<h3>Declaration</h3>
<div class="code-content" style="padding:1rem; background:transparent;">char s1[] = "Hello";
// Size is 6 ('H','e','l','l','o','\0')
char s2[10] = "Hi";
// s2[2] through s2[9] are 0</div>
</div>
<div class="card scroll-reveal" data-hover>
<h3>String Functions</h3>
<ul>
<li><code>strlen()</code>: Length excluding \0</li>
<li><code>strcpy()</code>: Copy string (Unsafe)</li>
<li><code>strcat()</code>: Concatenate</li>
<li><code>strcmp()</code>: Compare</li>
</ul>
</div>
</div>
<div class="diagram scroll-reveal">
String: "C"
Index: 0 1
Char: 'C' '\0'
ASCII: 67 0
</div>
</div>
</section>
<footer>
<a href="#" class="footer-logo">C / <span>ARR</span></a>
<div class="nav-links" style="justify-content: center; margin-bottom: 2rem;">
<a href="#intro" data-hover>Concept</a>
<a href="#memory" data-hover>Memory</a>
<a href="#strings" data-hover>Strings</a>
</div>
<p class="footer-credit">
© 2026 ARRAYS & STRINGS ARCHITECTURE.
</p>
</footer>
<script>
// --- 1. CUSTOM CURSOR LOGIC ---
const cursorDot = document.querySelector('.cursor-dot');
const cursorCircle = document.querySelector('.cursor-circle');
window.addEventListener('mousemove', (e) => {
const x = e.clientX;
const y = e.clientY;
cursorDot.style.left = `${x}px`;
cursorDot.style.top = `${y}px`;
cursorCircle.animate({
left: `${x}px`,
top: `${y}px`
}, { duration: 500, fill: "forwards" });
});
document.querySelectorAll('[data-hover], a').forEach(el => {
el.addEventListener('mouseenter', () => document.body.classList.add('hovering'));
el.addEventListener('mouseleave', () => document.body.classList.remove('hovering'));
});
// --- 2. CANVAS ANIMATION ---
const canvas = document.getElementById('heroCanvas');
const ctx = canvas.getContext('2d');
let width, height;
function resize() {
width = canvas.width = window.innerWidth;
height = canvas.height = window.innerHeight;
}
window.addEventListener('resize', resize);
resize();
const particles = [];
const particleCount = 60;
class Particle {
constructor() {
this.x = Math.random() * width;
this.y = Math.random() * height;
this.vx = (Math.random() - 0.5) * 0.5;
this.vy = (Math.random() - 0.5) * 0.5;
this.size = Math.random() * 2;
}
update() {
this.x += this.vx;
this.y += this.vy;
if(this.x < 0 || this.x > width) this.vx *= -1;
if(this.y < 0 || this.y > height) this.vy *= -1;
}
draw() {
ctx.fillStyle = '#ff3c00';
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
for(let i=0; i<particleCount; i++) particles.push(new Particle());
function animateCanvas() {
ctx.clearRect(0, 0, width, height);
ctx.strokeStyle = 'rgba(255, 60, 0, 0.1)';
ctx.lineWidth = 1;
for(let i=0; i<particles.length; i++) {
particles[i].update();
particles[i].draw();
for(let j=i; j<particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const dist = Math.sqrt(dx*dx + dy*dy);
if(dist < 150) {
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.stroke();
}
}
}
requestAnimationFrame(animateCanvas);
}
animateCanvas();
// --- 3. SCROLL REVEAL ---
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('in-view');
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.scroll-reveal').forEach((el) => {
observer.observe(el);
});
</script>
</body>
</html>