-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.html
More file actions
610 lines (534 loc) · 25.3 KB
/
function.html
File metadata and controls
610 lines (534 loc) · 25.3 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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>C / FUNC — Functions Architecture</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 { color: var(--text-secondary); font-size: 0.95rem; line-height: 1.7; margin-bottom: 1rem; }
/* --- 8. TERMINAL / CODE WINDOW --- */
.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;
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>FUNC</span></a>
<div class="nav-links">
<a href="#intro" data-hover>Concept</a>
<a href="#declaration" data-hover>Syntax</a>
<a href="#call-by-value" data-hover>Value</a>
<a href="#stack" data-hover>Stack</a>
<a href="#calling" data-hover>CPU</a>
<a href="#recursion" data-hover>Recursion</a>
</div>
</nav>
<section class="hero">
<canvas id="heroCanvas"></canvas>
<div class="container">
<h1>
<span>Functions</span>
<span>In C</span>
<span>Lang</span>
</h1>
<p>Master function declaration, definition, call by value semantics, stack frames, calling conventions, and recursion to write efficient, modular C code.</p>
<div class="btn-group">
<a href="#intro" class="btn btn-primary" data-hover>Start Learning</a>
<a href="#stack" class="btn" data-hover>View Stack</a>
</div>
</div>
</section>
<section id="intro">
<div class="container">
<h2 class="section-title">What is a Function?</h2>
<p class="section-desc">A reusable block of code that performs a specific task. Functions organize code into logical units.</p>
<div class="highlight-box scroll-reveal">
<strong>Key Concept:</strong>
Every function has a name, parameters (inputs), a return type, and a body. The simplest function is <code>main()</code>, where execution begins.
</div>
</div>
</section>
<section id="declaration">
<div class="container">
<h2 class="section-title">Declaration vs Definition</h2>
<p class="section-desc">The blueprint versus the implementation.</p>
<div class="grid-2">
<div class="card scroll-reveal" data-hover>
<h3>Declaration (Prototype)</h3>
<p>Tells the compiler about a function before it's used. Includes name, return type, and parameters.</p>
<div class="terminal-window" style="margin-top:1rem; box-shadow:none;">
<div class="code-content" style="padding:1rem;">// Before main()
int add(int a, int b);
void printMsg(char *msg);</div>
</div>
</div>
<div class="card scroll-reveal" data-hover>
<h3>Definition (Body)</h3>
<p>The actual implementation containing the code to execute.</p>
<div class="terminal-window" style="margin-top:1rem; box-shadow:none;">
<div class="code-content" style="padding:1rem;">// Implementation
int add(int a, int b) {
return a + b;
}</div>
</div>
</div>
</div>
<div class="terminal-window scroll-reveal">
<div class="terminal-header">
<span style="margin-left: 10px; color: #666; font-family: var(--font-code); font-size: 0.8rem;">functions.c</span>
</div>
<div class="code-content"><span class="kw">#include</span> <span class="str"><stdio.h></span>
<span class="cmt">// 1. Declaration</span>
<span class="kw">int</span> <span class="fn">multiply</span>(<span class="kw">int</span> x, <span class="kw">int</span> y);
<span class="kw">int</span> <span class="fn">main</span>() {
<span class="kw">int</span> result = <span class="fn">multiply</span>(<span class="num">5</span>, <span class="num">3</span>);
<span class="fn">printf</span>(<span class="str">"Result: %d\n"</span>, result);
<span class="kw">return</span> <span class="num">0</span>;
}
<span class="cmt">// 2. Definition</span>
<span class="kw">int</span> <span class="fn">multiply</span>(<span class="kw">int</span> x, <span class="kw">int</span> y) {
<span class="kw">return</span> x * y;
}</div>
</div>
</div>
</section>
<section id="call-by-value">
<div class="container">
<h2 class="section-title">Call by Value</h2>
<p class="section-desc">C passes copies of arguments, not originals. Changes inside functions don't affect the caller.</p>
<div class="terminal-window scroll-reveal">
<div class="terminal-header"><span style="color:#666;">value.c</span></div>
<div class="code-content"><span class="kw">void</span> <span class="fn">increment</span>(<span class="kw">int</span> x) {
x = x + <span class="num">1</span>; <span class="cmt">// Modifies COPY of x</span>
}
<span class="kw">int</span> <span class="fn">main</span>() {
<span class="kw">int</span> num = <span class="num">10</span>;
<span class="fn">increment</span>(num);
<span class="cmt">// num is STILL 10 here!</span>
}</div>
</div>
<div class="diagram scroll-reveal">
main() Memory: increment() Memory:
┌─────────────┐ ┌─────────────┐
│ num = 10 │ ──COPY─>│ x = 10 │
└─────────────┘ └─────────────┘
↓
┌─────────────┐
│ x = 11 │ (Modified only here)
└─────────────┘
</div>
</div>
</section>
<section id="return">
<div class="container">
<h2 class="section-title">Return Values</h2>
<p class="section-desc">Exiting a function and sending data back to the caller.</p>
<div class="grid-2">
<div class="card scroll-reveal" data-hover>
<h3>Return Value</h3>
<p>Returns a result to the caller.</p>
<div class="code-content" style="padding:1rem; background:transparent;">int square(int n) {
return n * n;
}</div>
</div>
<div class="card scroll-reveal" data-hover>
<h3>Return Void</h3>
<p>Returns nothing.</p>
<div class="code-content" style="padding:1rem; background:transparent;">void sayHello() {
printf("Hi");
return; // Optional
}</div>
</div>
</div>
</div>
</section>
<section id="stack">
<div class="container">
<h2 class="section-title">Stack Architecture</h2>
<p class="section-desc">How memory manages function calls. Every call creates a "Stack Frame".</p>
<div class="diagram scroll-reveal">
Step 1: main() called
┌─────────────────────┐
│ [STACK FRAME: main] │
│ main_var = 5 │
└─────────────────────┘
Step 2: func1(5) called
┌─────────────────────┐
│ [STACK FRAME: func1]│
│ x = 5 │
├─────────────────────┤
│ [STACK FRAME: main] │
└─────────────────────┘
Step 3: func2(15) called
┌─────────────────────┐
│ [STACK FRAME: func2]│ <--- Top of Stack
│ y = 15 │
├─────────────────────┤
│ [STACK FRAME: func1]│
├─────────────────────┤
│ [STACK FRAME: main] │
└─────────────────────┘
</div>
<div class="highlight-box scroll-reveal">
<strong>Memory Rules:</strong>
<br>• LIFO (Last In, First Out) structure.
<br>• Local variables exist only in their frame.
<br>• Returning destroys the frame.
<br>• Deep recursion can cause Stack Overflow.
</div>
</div>
</section>
<section id="calling">
<div class="container">
<h2 class="section-title">Calling Conventions (x86-64)</h2>
<p class="section-desc">How the CPU passes data between functions at the machine level.</p>
<div class="grid-2">
<div class="card scroll-reveal" data-hover>
<h3>Parameters (Input)</h3>
<p>First 6 integer args go into registers:</p>
<ul>
<li>1: RDI</li>
<li>2: RSI</li>
<li>3: RDX</li>
<li>4: RCX</li>
<li>5: R8</li>
<li>6: R9</li>
</ul>
</div>
<div class="card scroll-reveal" data-hover>
<h3>Return (Output)</h3>
<p>Where the result goes:</p>
<ul>
<li>Integer: RAX Register</li>
<li>Float: XMM0 Register</li>
</ul>
</div>
</div>
<div class="terminal-window scroll-reveal">
<div class="terminal-header"><span style="color:#666;">assembly_concept.c</span></div>
<div class="code-content"><span class="cmt">// C Code:</span>
<span class="kw">int</span> result = <span class="fn">add</span>(10, 20);
<span class="cmt">// Assembly (Concept):</span>
MOV RDI, 10 <span class="cmt">// Arg 1</span>
MOV RSI, 20 <span class="cmt">// Arg 2</span>
CALL add
MOV result, RAX <span class="cmt">// Return value</span></div>
</div>
</div>
</section>
<section id="recursion">
<div class="container">
<h2 class="section-title">Recursion</h2>
<p class="section-desc">A function calling itself. Requires a Base Case to stop.</p>
<div class="terminal-window scroll-reveal">
<div class="terminal-header"><span style="color:#666;">factorial.c</span></div>
<div class="code-content"><span class="kw">int</span> <span class="fn">factorial</span>(<span class="kw">int</span> n) {
<span class="cmt">// Base Case</span>
<span class="kw">if</span> (n <= 1) <span class="kw">return</span> 1;
<span class="cmt">// Recursive Case</span>
<span class="kw">return</span> n * <span class="fn">factorial</span>(n - 1);
}
<span class="cmt">// Execution: 5 * 4 * 3 * 2 * 1 = 120</span></div>
</div>
</div>
</section>
<footer>
<a href="#" class="footer-logo">C / <span>FUNC</span></a>
<div class="nav-links" style="justify-content: center; margin-bottom: 2rem;">
<a href="#intro" data-hover>Concept</a>
<a href="#stack" data-hover>Stack</a>
<a href="#calling" data-hover>CPU</a>
</div>
<p class="footer-credit">
© 2026 FUNCTION 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>