arirajuns commited on
Commit
ea68f14
·
verified ·
1 Parent(s): 9fdbede

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +178 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Fibonacci 1
3
- emoji: 🏆
4
- colorFrom: pink
5
  colorTo: blue
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: fibonacci-1
3
+ emoji: 🐳
4
+ colorFrom: yellow
5
  colorTo: blue
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,178 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Fibonacci Squares Visualization</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <style>
9
+ .fib-container {
10
+ position: relative;
11
+ width: 100%;
12
+ height: 500px;
13
+ overflow: hidden;
14
+ }
15
+
16
+ .fib-square {
17
+ position: absolute;
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ font-weight: bold;
22
+ border: 2px solid rgba(59, 130, 246, 0.7);
23
+ background-color: rgba(219, 234, 254, 0.7);
24
+ }
25
+ </style>
26
+ </head>
27
+ <body class="bg-gray-100 min-h-screen">
28
+ <div class="container mx-auto px-4 py-8">
29
+ <header class="text-center mb-12">
30
+ <h1 class="text-4xl font-bold text-indigo-800 mb-2">Fibonacci Squares</h1>
31
+ <p class="text-lg text-gray-600 max-w-2xl mx-auto">
32
+ Visual representation of the Fibonacci sequence through proportional squares
33
+ </p>
34
+ </header>
35
+
36
+ <div class="flex flex-col lg:flex-row gap-8 items-center">
37
+ <div class="fib-container bg-white rounded-xl shadow-lg p-4 lg:w-2/3" id="fibContainer">
38
+ <!-- Squares will be generated here -->
39
+ </div>
40
+
41
+ <div class="lg:w-1/3 bg-white rounded-xl shadow-lg p-6">
42
+ <h2 class="text-2xl font-semibold text-indigo-700 mb-4">Controls</h2>
43
+
44
+ <div class="mb-6">
45
+ <label for="fibCount" class="block text-sm font-medium text-gray-700 mb-2">Number of terms:</label>
46
+ <div class="flex items-center gap-2">
47
+ <input type="range" id="fibCount" min="5" max="15" value="8" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
48
+ <span id="countValue" class="text-lg font-medium text-indigo-600">8</span>
49
+ </div>
50
+ </div>
51
+
52
+ <button id="generateBtn" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-4 rounded-lg transition duration-300">
53
+ Generate Squares
54
+ </button>
55
+
56
+ <div class="mt-6 p-4 bg-indigo-50 rounded-lg">
57
+ <h3 class="font-medium text-indigo-800 mb-2">Fibonacci Sequence</h3>
58
+ <p class="text-sm text-gray-700">
59
+ Each number is the sum of the two preceding ones, starting from 1 and 1.
60
+ The ratio between consecutive numbers approaches the golden ratio (≈1.618).
61
+ </p>
62
+ </div>
63
+ </div>
64
+ </div>
65
+
66
+ <div class="mt-12 bg-white rounded-xl shadow-lg p-6">
67
+ <h2 class="text-2xl font-semibold text-indigo-700 mb-4">Sequence Values</h2>
68
+ <div id="sequenceList" class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-4">
69
+ <!-- Sequence numbers will appear here -->
70
+ </div>
71
+ </div>
72
+ </div>
73
+
74
+ <script>
75
+ document.addEventListener('DOMContentLoaded', function() {
76
+ const fibContainer = document.getElementById('fibContainer');
77
+ const fibCount = document.getElementById('fibCount');
78
+ const countValue = document.getElementById('countValue');
79
+ const generateBtn = document.getElementById('generateBtn');
80
+ const sequenceList = document.getElementById('sequenceList');
81
+
82
+ // Update displayed count value
83
+ fibCount.addEventListener('input', function() {
84
+ countValue.textContent = this.value;
85
+ });
86
+
87
+ // Generate Fibonacci sequence
88
+ function generateFibonacci(n) {
89
+ const sequence = [1, 1];
90
+ for (let i = 2; i < n; i++) {
91
+ sequence.push(sequence[i-1] + sequence[i-2]);
92
+ }
93
+ return sequence;
94
+ }
95
+
96
+ // Create the square visualization
97
+ function createSquares(sequence) {
98
+ fibContainer.innerHTML = '';
99
+ sequenceList.innerHTML = '';
100
+
101
+ const containerWidth = fibContainer.clientWidth;
102
+ const containerHeight = fibContainer.clientHeight;
103
+ const centerX = containerWidth / 2;
104
+ const centerY = containerHeight / 2;
105
+
106
+ let x = centerX;
107
+ let y = centerY;
108
+ let direction = 0; // 0: right, 1: down, 2: left, 3: up
109
+
110
+ // Scale factor to fit the squares in the container
111
+ const maxSize = Math.max(...sequence);
112
+ const scale = Math.min(containerWidth, containerHeight) * 0.8 / (maxSize * 2);
113
+
114
+ sequence.forEach((num, index) => {
115
+ // Create sequence list item
116
+ const seqItem = document.createElement('div');
117
+ seqItem.className = 'bg-indigo-100 rounded-lg p-3 text-center';
118
+ seqItem.innerHTML = `
119
+ <div class="text-xs text-indigo-500">Term ${index + 1}</div>
120
+ <div class="text-xl font-bold text-indigo-800">${num}</div>
121
+ `;
122
+ sequenceList.appendChild(seqItem);
123
+
124
+ // Calculate scaled size
125
+ const scaledSize = num * scale;
126
+
127
+ // Create square
128
+ const square = document.createElement('div');
129
+ square.className = 'fib-square';
130
+ square.style.width = `${scaledSize}px`;
131
+ square.style.height = `${scaledSize}px`;
132
+ square.textContent = num;
133
+ square.style.fontSize = `${Math.min(20, scaledSize / 3)}px`;
134
+
135
+ // Position square based on direction
136
+ switch (direction) {
137
+ case 0: // right
138
+ square.style.left = `${x}px`;
139
+ square.style.top = `${y}px`;
140
+ x += scaledSize;
141
+ break;
142
+ case 1: // down
143
+ square.style.left = `${x - scaledSize}px`;
144
+ square.style.top = `${y}px`;
145
+ y += scaledSize;
146
+ break;
147
+ case 2: // left
148
+ square.style.left = `${x - scaledSize}px`;
149
+ square.style.top = `${y - scaledSize}px`;
150
+ x -= scaledSize;
151
+ break;
152
+ case 3: // up
153
+ square.style.left = `${x}px`;
154
+ square.style.top = `${y - scaledSize}px`;
155
+ y -= scaledSize;
156
+ break;
157
+ }
158
+
159
+ fibContainer.appendChild(square);
160
+
161
+ // Update direction for next square
162
+ direction = (direction + 1) % 4;
163
+ });
164
+ }
165
+
166
+ // Initial generation
167
+ const initialSequence = generateFibonacci(parseInt(fibCount.value));
168
+ createSquares(initialSequence);
169
+
170
+ // Regenerate on button click
171
+ generateBtn.addEventListener('click', function() {
172
+ const newSequence = generateFibonacci(parseInt(fibCount.value));
173
+ createSquares(newSequence);
174
+ });
175
+ });
176
+ </script>
177
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=arirajuns/fibonacci-1" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
178
+ </html>