-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
508 lines (449 loc) · 19 KB
/
index.html
File metadata and controls
508 lines (449 loc) · 19 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OceanLabAI</title>
<!-- Load the p5.js library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.min.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: #333;
}
body {
display: flex;
justify-content: center;
align-items: center;
padding-top: 48px; /* 預留導覽列高度 */
}
canvas {
display: block !important;
margin: 0 auto;
}
#error-message {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(255, 255, 255, 0.9);
padding: 20px;
border-radius: 10px;
text-align: center;
max-width: 80%;
z-index: 100;
}
.instructions {
position: absolute;
bottom: 10px;
left: 10px;
color: white;
font-family: monospace;
background-color: rgba(0, 0, 0, 0.5);
padding: 5px 10px;
border-radius: 5px;
z-index: 10;
}
@media (max-width: 896px) and (orientation: landscape) {
body {
overflow-y: auto;
}
.iframeContainer {
position: relative;
height: auto;
min-height: 100vh;
}
iframe {
height: 100%;
position: relative;
}
}
/* Add styles for bar overlay */
#bar-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 2001; /* Above iframe */
}
#bar-overlay canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: auto;
}
/* 右上角黑色橫條樣式 */
#right-top-bar {
position: absolute;
top: 140px;
right: 0;
height: 120px; /* 高度可根據需要調整 */
width: 0; /* 初始寬度為 0,將通過動畫改變 */
background-color: rgba(0, 0, 0, 1);
z-index: 2002;
overflow: hidden;
transition: width 0.8s ease-out;
}
#right-top-bar-text {
position: absolute;
right: 20px;
top: 50%;
transform: translateY(-50%);
color: white; /* 初始顏色,將由JavaScript動態設置 */
font-family: 'Century Gothic', Arial, sans-serif;
font-size: calc(0.9 * var(--bar-height, 80px));
opacity: 0;
transition: opacity 0.5s ease-in, color 0.5s ease;
text-align: right;
padding-right: calc(40% - 20px); /* 根據橫條長度,從右邊推一個比例距離 */
}
/* 響應式調整 */
@media (max-width: 768px) {
#right-top-bar {
top: 30px;
height: 30px;
}
#right-top-bar-text {
font-size: 18px;
}
}
@media (max-width: 480px) {
#right-top-bar {
top: 20px;
height: 25px;
}
#right-top-bar-text {
font-size: 14px;
right: 10px;
}
}
/* 上方固定導覽列 */
#top-nav {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 48px;
background: #f5f5f7;
box-shadow: 0 2px 12px rgba(0,0,0,0.07);
z-index: 4000;
display: flex;
align-items: center;
padding: 0 24px;
}
#top-nav .nav-link {
color: #222;
text-decoration: none;
font-size: calc(0.9 * var(--bar-height, 48px));
margin-right: 32px;
padding: 0 6px;
line-height: 48px;
border-bottom: 2px solid transparent;
transition: color 0.2s, border-bottom 0.2s;
}
#top-nav .nav-link:last-child {
margin-right: 0;
}
#top-nav .nav-link:hover {
color: #0070f3;
border-bottom: 2px solid #0070f3;
background: #ececec;
border-radius: 4px;
}
</style>
<!-- Add a small script to fix the color error -->
<script>
// Fix color handling before loading sketch.js
window.addEventListener('DOMContentLoaded', () => {
// Create a safer version of p5.js color functions
const originalColor = p5.prototype.color;
p5.prototype.color = function() {
try {
// Make sure we're passing valid color arguments
if (arguments.length === 0) return originalColor.call(this, 0);
if (arguments.length === 1 &&
(arguments[0] === undefined || arguments[0] === null)) {
return originalColor.call(this, 0);
}
// Try to convert Arguments object to array if needed
if (arguments.length === 1 && typeof arguments[0] === 'object' &&
!(arguments[0] instanceof Array) && arguments[0].toString() === '[object Arguments]') {
const args = Array.from(arguments[0]);
return originalColor.apply(this, args);
}
return originalColor.apply(this, arguments);
} catch (e) {
console.warn('Error creating color, using fallback', e);
return originalColor.call(this, 0); // Return black as fallback
}
};
// Also patch red, green, blue functions to handle errors
['red', 'green', 'blue'].forEach(colorFunc => {
const original = p5.prototype[colorFunc];
p5.prototype[colorFunc] = function(c) {
try {
if (!c || typeof c !== 'object') {
return 0; // Return 0 for invalid color
}
return original.call(this, c);
} catch (e) {
console.warn(`Error extracting ${colorFunc} value, using 0`, e);
return 0;
}
};
});
console.log('Color handling patches applied');
});
// 顏色對比生成工具,在HSL色彩空間中操作
class ColorGenerator {
constructor() {
this.currentHue = Math.random() * 360; // 隨機初始色相
this.p5Instance = null;
}
// 初始化P5實例
initP5() {
if (this.p5Instance) return;
this.p5Instance = new p5((p) => {
p.setup = () => {
// 創建一個1x1像素的隱藏canvas
const canvas = p.createCanvas(1, 1);
canvas.style('display', 'none');
p.colorMode(p.HSB, 360, 100, 100);
};
});
}
// 生成新的隨機顏色
generateNewColor() {
this.currentHue = Math.random() * 360;
return this.getCurrentColor();
}
// 獲取當前顏色的HSL表示
getCurrentColor() {
return `hsl(${this.currentHue}, 80%, 65%)`;
}
// 獲取當前顏色的對比色(色相差180度)
getContrastColor() {
let contrastHue = (this.currentHue + 180) % 360;
return `hsl(${contrastHue}, 100%, 70%)`;
}
// 使用P5.js的方式生成顏色
getP5ContrastColor() {
this.initP5();
if (!this.p5Instance) return this.getContrastColor();
const p = this.p5Instance;
const baseColor = p.color(this.currentHue, 80, 90);
const contrastHue = (this.currentHue + 180) % 360;
return p.color(contrastHue, 95, 95);
}
}
// 全局顏色生成器實例
const colorGen = new ColorGenerator();
</script>
</head>
<body>
<div class="instructions">
Press 'R' to change colors | Press 'N' to reset cells
</div>
<div id="error-message">
<h3>Error loading resources</h3>
<p>There was a problem loading the sketch resources.</p>
<p>Please try refreshing the page or check the console for details.</p>
<button onclick="location.reload()">Refresh Page</button>
</div>
<!-- 右上角黑色橫條(自動產生,這裡不再寫死多個div) -->
<div id="right-top-bars"></div>
<!-- 上方固定導覽列 -->
<nav id="top-nav">
<a class="nav-link" href="https://oceanlabdesign.github.io/about.html">About us</a>
<a class="nav-link" href="https://oceanlabdesign.github.io/privacy.html">Privacy Policy</a>
<a class="nav-link" href="https://oceanlabdesign.github.io/service.html">Service Policy</a>
</nav>
<script>
// Error handling
window.addEventListener('error', function(e) {
if (e.message && (e.message.includes('CORS') || e.message.includes('Failed to fetch') || e.message.includes('load'))) {
document.getElementById('error-message').style.display = 'block';
console.error('Resource loading error:', e.message);
}
});
// 更新文字顏色函數
function updateTextColor() {
const textElement = document.getElementById('right-top-bar-text');
if (textElement) {
textElement.style.color = colorGen.getContrastColor();
}
}
// 監聽按鍵事件,當按下'R'鍵時重新生成顏色
document.addEventListener('keydown', function(event) {
if (event.key.toLowerCase() === 'r') {
colorGen.generateNewColor();
updateTextColor();
}
});
// Replace local script with embedded p5.js editor version
window.addEventListener('load', function() {
try {
// 防止重複建立 iframe(只建立一次)
if (document.getElementById('main-iframe')) return;
// 先移除任何已存在的 canvas 或 iframe
const existingCanvas = document.querySelector('canvas');
if (existingCanvas) {
existingCanvas.remove();
}
// 建立 iframe 容器,用於控制顯示區域
const iframeContainer = document.createElement('div');
iframeContainer.style.position = 'absolute';
iframeContainer.style.top = '0';
iframeContainer.style.left = '0';
iframeContainer.style.width = '100%';
iframeContainer.style.height = '100vh';
iframeContainer.style.overflow = 'auto';
// 建立 iframe,設定負邊距將頂部隱藏
const iframe = document.createElement('iframe');
iframe.id = 'main-iframe'; // 加入唯一 id
iframe.src = 'https://editor.p5js.org/ks.architect01/full/QU_im7pMR';
iframe.style.width = '100%';
iframe.style.height = 'calc(100vh + 40px)'; // 增加高度
iframe.style.marginTop = '-43px'; // 負邊距隱藏頂部
iframe.style.border = 'none';
iframe.style.position = 'absolute';
// 完整啟用 iframe 所有互動功能
iframe.style.pointerEvents = 'auto';
iframe.setAttribute('allowfullscreen', 'true');
iframe.setAttribute('allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture');
// 確保不使用 sandbox 限制
iframe.removeAttribute('sandbox');
// 確保連結在同一頁面內打開
iframe.name = "mainFrame";
// 確保 iframe 在最頂層
iframe.style.zIndex = '2000';
// 添加 iframe 到容器
iframeContainer.appendChild(iframe);
document.body.appendChild(iframeContainer);
// 添加事件監聽,攔截點擊事件處理連結目標
window.addEventListener('message', function(event) {
// 檢查訊息是否來自我們的 iframe
if (event.source === iframe.contentWindow) {
// 如果是連結點擊訊息,在當前頁面打開
if (event.data && event.data.type === 'link' && event.data.href) {
window.location.href = event.data.href;
event.preventDefault();
return false;
}
}
});
// 監聽 iframe 加載完成事件
iframe.onload = function() {
console.log('Iframe loaded, modifying link behavior');
try {
// 嘗試注入代碼來修改所有連結目標
iframe.contentWindow.postMessage({
action: 'modifyLinks',
target: '_self' // 使連結在同一頁面打開
}, '*');
// 定期檢查
setInterval(() => {
iframe.contentWindow.postMessage({
action: 'modifyLinks',
target: '_self'
}, '*');
}, 2000);
} catch(e) {
console.log('PostMessage failed:', e);
}
};
// 啟動右上角黑色橫條動畫
// 移除舊的單一 bar 點擊事件設定,改由 renderRightTopBars 動態處理
} catch (error) {
console.error('Error initializing iframe:', error);
}
});
// 服務項目陣列
const serviceBars = [
{ label: "Web_Design", link: "https://oceanlabdesign.github.io/web_design.html" },
{ label: "Digital_Art_Design", link: "#" },
{ label: "UI_UX_Design", link: "#" }
// 你可以在這裡增減服務項目
];
// 動態產生黑色橫條
function renderRightTopBars() {
const container = document.getElementById('right-top-bars');
container.innerHTML = '';
const barHeight = 60;
const barGap = 400;
const barStartTop = 140;
const minBarWidth = 180; // 最小寬度
const maxBarWidth = Math.floor(window.innerWidth * 0.8); // 最大寬度
// 建立一個隱藏的span用於測量文字寬度
const measureSpan = document.createElement('span');
measureSpan.style.visibility = 'hidden';
measureSpan.style.position = 'absolute';
measureSpan.style.fontFamily = "'Century Gothic', Arial, sans-serif";
measureSpan.style.fontSize = 'calc(0.9 * 80px)';
measureSpan.style.whiteSpace = 'nowrap';
document.body.appendChild(measureSpan);
serviceBars.forEach((service, idx) => {
// 測量文字寬度
measureSpan.textContent = service.label;
const textWidth = measureSpan.offsetWidth;
// 計算橫條寬度(加上一些padding,並限制最大最小)
const barWidth = Math.max(minBarWidth, Math.min(textWidth *1.618, maxBarWidth));
const bar = document.createElement('div');
bar.className = 'right-top-bar';
bar.style.position = 'absolute';
bar.style.top = (barStartTop + idx * (barHeight + barGap)) + 'px';
bar.style.right = '0';
bar.style.height = barHeight + 'px';
bar.style.width = '0';
bar.style.backgroundColor = 'rgba(0,0,0,1)';
bar.style.zIndex = 2002;
bar.style.overflow = 'hidden';
bar.style.transition = 'width 0.8s cubic-bezier(.4,0,.2,1)';
const barText = document.createElement('div');
barText.className = 'right-top-bar-text';
barText.textContent = service.label;
barText.style.position = 'absolute';
barText.style.right = '20px';
barText.style.top = '50%';
barText.style.transform = 'translateY(-50%)';
barText.style.color = 'white';
barText.style.fontFamily = "'Century Gothic', Arial, sans-serif";
barText.style.fontSize = 'calc(0.9 * 80px)';
barText.style.opacity = '0';
barText.style.transition = 'opacity 0.5s ease-in, color 0.5s ease';
barText.style.textAlign = 'right';
barText.style.paddingRight = '0';
bar.appendChild(barText);
container.appendChild(bar);
// 動畫與點擊事件
setTimeout(() => {
bar.style.width = barWidth + 'px';
setTimeout(() => {
barText.style.opacity = '1';
}, 560);
}, 800 + idx * 200);
// 這裡已經根據 service.link 動態處理連結
bar.addEventListener('click', function() {
if (service.link && service.link !== "#") {
window.location.href = service.link;
}
});
bar.style.cursor = 'pointer';
});
// 移除測量用span
document.body.removeChild(measureSpan);
}
// 呼叫渲染函數
renderRightTopBars();
</script>
</body>
</html>