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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Myco UI Components โ Modular Gradio layout and custom HTML/Canvas animations.
|
| 3 |
+
This file decouples the messy HTML/CSS/JS injection from your main application script.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
def myco_animation_card_markdown() -> str:
|
| 9 |
+
"""
|
| 10 |
+
Generates a self-contained, micro-scoped HTML/Canvas card component.
|
| 11 |
+
Features a particle mutation matrix engine that morphs shapes, colors,
|
| 12 |
+
and text strings dynamically inside an isolated container.
|
| 13 |
+
"""
|
| 14 |
+
return """
|
| 15 |
+
<div id="myco-card-container" class="myco-anim-card">
|
| 16 |
+
<style>
|
| 17 |
+
.myco-anim-card {
|
| 18 |
+
position: relative;
|
| 19 |
+
width: 100%;
|
| 20 |
+
max-width: 600px;
|
| 21 |
+
height: 320px;
|
| 22 |
+
margin: 20px auto;
|
| 23 |
+
background: #050a08;
|
| 24 |
+
border: 1px solid rgba(82, 255, 107, 0.15);
|
| 25 |
+
border-radius: 12px;
|
| 26 |
+
overflow: hidden;
|
| 27 |
+
font-family: 'Inter', sans-serif;
|
| 28 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
#myco-card-overlay {
|
| 32 |
+
position: absolute;
|
| 33 |
+
top: 0; left: 0; width: 100%; height: 100%;
|
| 34 |
+
pointer-events: none;
|
| 35 |
+
z-index: 1;
|
| 36 |
+
opacity: 0.12;
|
| 37 |
+
transition: opacity 0.4s ease;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.m-grid { background-image: radial-gradient(rgba(255,255,255,0.15) 1px, transparent 1px); background-size: 20px 20px; }
|
| 41 |
+
.m-lines { background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.03) 3px); }
|
| 42 |
+
.m-noise { background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
|
| 43 |
+
|
| 44 |
+
#myco-card-canvas {
|
| 45 |
+
display: block;
|
| 46 |
+
position: absolute;
|
| 47 |
+
top: 0; left: 0;
|
| 48 |
+
width: 100%;
|
| 49 |
+
height: 100%;
|
| 50 |
+
z-index: 2;
|
| 51 |
+
filter: contrast(1.1) brightness(1.1);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
#myco-card-ui {
|
| 55 |
+
position: absolute; top: 12px; left: 0; width: 100%;
|
| 56 |
+
color: rgba(168, 255, 178, 0.5); font-size: 9px; letter-spacing: 3px;
|
| 57 |
+
pointer-events: none; text-transform: uppercase; z-index: 10;
|
| 58 |
+
text-align: center; line-height: 1.6;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
#myco-card-footer {
|
| 62 |
+
position: absolute; bottom: 12px; left: 16px; right: 16px;
|
| 63 |
+
color: rgba(255, 255, 255, 0.25); font-size: 8px;
|
| 64 |
+
letter-spacing: 1px; text-transform: uppercase; z-index: 10;
|
| 65 |
+
display: flex; justify-content: space-between;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.myco-highlight { color: #00f2fe; font-weight: bold; }
|
| 69 |
+
|
| 70 |
+
@keyframes cardShake {
|
| 71 |
+
0% { transform: translate(1px, 1px); }
|
| 72 |
+
20% { transform: translate(-2px, 0px); }
|
| 73 |
+
40% { transform: translate(1px, -1px); }
|
| 74 |
+
100% { transform: translate(1px, 1px); }
|
| 75 |
+
}
|
| 76 |
+
.card-shaking { animation: cardShake 0.15s infinite; }
|
| 77 |
+
</style>
|
| 78 |
+
|
| 79 |
+
<div id="myco-card-overlay" class="m-grid"></div>
|
| 80 |
+
<div id="myco-card-ui">
|
| 81 |
+
BIOME MUTATION: <span id="myco-card-msg">SCANNING NETWORKS...</span><br>
|
| 82 |
+
<small style="font-size: 7px; opacity: 0.6; letter-spacing: 0.5px;">(CLICK CARD TO INTERACT WITH AUDIO RESONANCE)</small>
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<canvas id="myco-card-canvas"></canvas>
|
| 86 |
+
|
| 87 |
+
<div id="myco-card-footer">
|
| 88 |
+
<div>ENGINE: <span class="myco-highlight">MYCO MATRIX</span></div>
|
| 89 |
+
<div id="myco-card-date"></div>
|
| 90 |
+
</div>
|
| 91 |
+
|
| 92 |
+
<script>
|
| 93 |
+
(function() {
|
| 94 |
+
const container = document.getElementById('myco-card-container');
|
| 95 |
+
const canvas = document.getElementById('myco-card-canvas');
|
| 96 |
+
const ctx = canvas.getContext('2d');
|
| 97 |
+
const overlay = document.getElementById('myco-card-overlay');
|
| 98 |
+
const msg = document.getElementById('myco-card-msg');
|
| 99 |
+
|
| 100 |
+
let audioCtx = null;
|
| 101 |
+
function initAudio() {
|
| 102 |
+
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
| 103 |
+
if (audioCtx.state === 'suspended') audioCtx.resume();
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
const textures = ['m-grid', 'm-lines', 'm-noise'];
|
| 107 |
+
const sequence = ["๐", "MYCO", "๐โ๐ซ", "SPORE", "GILLS", "๐", "CAP", "HYPHAE", "ROOTS"];
|
| 108 |
+
|
| 109 |
+
let currentStep = 0;
|
| 110 |
+
let isExposed = false;
|
| 111 |
+
let w, h, dpr, particles = [];
|
| 112 |
+
|
| 113 |
+
const sCanvas = document.createElement('canvas');
|
| 114 |
+
const sCtx = sCanvas.getContext('2d', { willReadFrequently: true });
|
| 115 |
+
|
| 116 |
+
class Particle {
|
| 117 |
+
constructor() {
|
| 118 |
+
this.x = Math.random() * container.clientWidth;
|
| 119 |
+
this.y = Math.random() * container.clientHeight;
|
| 120 |
+
this.tx = this.x; this.ty = this.y;
|
| 121 |
+
this.vx = 0; this.vy = 0;
|
| 122 |
+
this.size = Math.random() * 1.5 + 1;
|
| 123 |
+
this.color = '#fff';
|
| 124 |
+
}
|
| 125 |
+
update() {
|
| 126 |
+
if (isExposed) {
|
| 127 |
+
this.x += this.vx; this.y += this.vy;
|
| 128 |
+
this.vx *= 0.95; this.vy *= 0.95;
|
| 129 |
+
} else {
|
| 130 |
+
this.vx = (this.tx - this.x) * 0.15;
|
| 131 |
+
this.vy = (this.ty - this.y) * 0.15;
|
| 132 |
+
this.x += this.vx; this.y += this.vy;
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
draw() {
|
| 136 |
+
ctx.fillStyle = this.color;
|
| 137 |
+
ctx.fillRect(this.x, this.y, this.size, this.size);
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
function resizeCard() {
|
| 142 |
+
if (!container.clientWidth) return;
|
| 143 |
+
dpr = window.devicePixelRatio || 1;
|
| 144 |
+
w = container.clientWidth;
|
| 145 |
+
h = container.clientHeight;
|
| 146 |
+
canvas.width = w * dpr; canvas.height = h * dpr;
|
| 147 |
+
ctx.scale(dpr, dpr);
|
| 148 |
+
sCanvas.width = w; sCanvas.height = h;
|
| 149 |
+
if(!isExposed && currentStep < sequence.length) morph(sequence[currentStep]);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
function morph(content) {
|
| 153 |
+
sCtx.clearRect(0, 0, w, h);
|
| 154 |
+
sCtx.fillStyle = "white";
|
| 155 |
+
sCtx.textAlign = "center";
|
| 156 |
+
sCtx.textBaseline = "middle";
|
| 157 |
+
|
| 158 |
+
const baseSize = Math.min(w, h) * 0.55;
|
| 159 |
+
const fontSize = content.length > 2 ? baseSize / (content.length * 0.45) : baseSize;
|
| 160 |
+
sCtx.font = `bold ${fontSize}px sans-serif`;
|
| 161 |
+
sCtx.fillText(content, w / 2, h / 2 + 10);
|
| 162 |
+
|
| 163 |
+
overlay.className = textures[currentStep % textures.length];
|
| 164 |
+
overlay.style.opacity = (0.04 + (Math.random() * 0.1)).toString();
|
| 165 |
+
|
| 166 |
+
const imgData = sCtx.getImageData(0, 0, w, h).data;
|
| 167 |
+
const points = [];
|
| 168 |
+
for (let y = 0; y < h; y += 4) {
|
| 169 |
+
for (let x = 0; x < w; x += 4) {
|
| 170 |
+
if (imgData[(y * w + x) * 4 + 3] > 128) points.push({x, y});
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
if (particles.length < points.length) {
|
| 175 |
+
for (let i = particles.length; i < points.length; i++) particles.push(new Particle());
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
particles.forEach((p, i) => {
|
| 179 |
+
const pt = points[i % points.length];
|
| 180 |
+
p.tx = pt.x; p.ty = pt.y;
|
| 181 |
+
if (content === "BLOOM") {
|
| 182 |
+
p.color = "#00f2fe";
|
| 183 |
+
} else {
|
| 184 |
+
p.color = `hsl(${130 + (currentStep * 22)}, 80%, 65%)`;
|
| 185 |
+
}
|
| 186 |
+
});
|
| 187 |
+
|
| 188 |
+
if (content !== "BLOOM") {
|
| 189 |
+
container.classList.add('card-shaking');
|
| 190 |
+
setTimeout(() => container.classList.remove('card-shaking'), 100);
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
function expose() {
|
| 195 |
+
isExposed = true;
|
| 196 |
+
msg.innerText = "SPORE BURST EXTRACTION";
|
| 197 |
+
overlay.className = 'm-noise';
|
| 198 |
+
overlay.style.opacity = "0.35";
|
| 199 |
+
|
| 200 |
+
particles.forEach(p => {
|
| 201 |
+
const angle = Math.random() * Math.PI * 2;
|
| 202 |
+
const vel = Math.random() * 15 + 8;
|
| 203 |
+
p.vx = Math.cos(angle) * vel;
|
| 204 |
+
p.vy = Math.sin(angle) * vel;
|
| 205 |
+
p.color = `hsl(${Math.random() * 40 + 290}, 95%, 65%)`;
|
| 206 |
+
});
|
| 207 |
+
|
| 208 |
+
setTimeout(() => {
|
| 209 |
+
isExposed = false;
|
| 210 |
+
msg.innerText = "BIOME INTEGRATED";
|
| 211 |
+
morph("BLOOM");
|
| 212 |
+
}, 1400);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
function loop() {
|
| 216 |
+
ctx.fillStyle = 'rgba(5, 10, 8, 0.2)';
|
| 217 |
+
ctx.fillRect(0, 0, w, h);
|
| 218 |
+
particles.forEach(p => { p.update(); p.draw(); });
|
| 219 |
+
requestAnimationFrame(loop);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
container.addEventListener('mousedown', initAudio);
|
| 223 |
+
window.addEventListener('resize', resizeCard);
|
| 224 |
+
document.getElementById('myco-card-date').textContent = new Date().toLocaleDateString();
|
| 225 |
+
|
| 226 |
+
setTimeout(() => {
|
| 227 |
+
resizeCard();
|
| 228 |
+
const timer = setInterval(() => {
|
| 229 |
+
if (!isExposed && msg.innerText !== "BIOME INTEGRATED") {
|
| 230 |
+
currentStep++;
|
| 231 |
+
if (currentStep < sequence.length) {
|
| 232 |
+
msg.innerText = `MUTATION // ${sequence[currentStep]}`;
|
| 233 |
+
morph(sequence[currentStep]);
|
| 234 |
+
} else {
|
| 235 |
+
clearInterval(timer);
|
| 236 |
+
expose();
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
}, 1300);
|
| 240 |
+
loop();
|
| 241 |
+
}, 300);
|
| 242 |
+
})();
|
| 243 |
+
</script>
|
| 244 |
+
</div>
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
def render_shroom_tab():
|
| 248 |
+
"""
|
| 249 |
+
Houses layout rendering parameters within a dedicated component ecosystem.
|
| 250 |
+
You can import this directly into your main app layout file via:
|
| 251 |
+
|
| 252 |
+
>>> from interface import render_shroom_tab
|
| 253 |
+
>>> with gr.Tab("Shroom"):
|
| 254 |
+
>>> render_shroom_tab()
|
| 255 |
+
"""
|
| 256 |
+
gr.HTML(value=myco_animation_card_markdown())
|
| 257 |
+
|
| 258 |
+
with gr.Box():
|
| 259 |
+
gr.Markdown("### ๐ฌ Laboratory Environment Controls")
|
| 260 |
+
gr.Markdown("Interact with the mutation matrix card above to sync audio contexts.")
|