byte-vortex commited on
Commit
61cd9b6
·
verified ·
1 Parent(s): 4b5c4ea

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/interface.py +32 -25
ui/interface.py CHANGED
@@ -1,30 +1,36 @@
1
  import gradio as gr
2
- import html
3
  from game.engine import get_myco_narrative
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def render_shroom_tab():
6
- with gr.Blocks(css="""
7
- #garden-canvas { width: 100%; height: 400px; background: linear-gradient(180deg, #1a2b4c 0%, #2a4c5e 50%, #4a7c59 100%); border-radius: 12px; }
8
- #narrative-box {
9
- font-family: 'Courier New', monospace;
10
- font-size: 15px;
11
- color: #52ff6b;
12
- background: #090e0b;
13
- padding: 15px;
14
- border-radius: 8px;
15
- border: 1px solid rgba(82, 255, 107, 0.3);
16
- text-align: center;
17
- margin-top: 10px;
18
- }
19
- """) as demo:
20
-
21
  # 1. The Canvas
22
  gr.HTML("<canvas id='garden-canvas'></canvas>")
23
 
24
  # 2. The Narrative
25
  narrative = gr.Markdown(value="Waiting for the forest to wake...", elem_id="narrative-box")
26
 
27
- # 3. Refresh Timer
28
  gr.Timer(20).tick(fn=get_myco_narrative, outputs=narrative)
29
 
30
  # 4. Injected Animation Logic
@@ -35,8 +41,8 @@ def render_shroom_tab():
35
  const ctx = canvas.getContext('2d');
36
 
37
  function resize() {
38
- canvas.width = canvas.clientWidth;
39
- canvas.height = canvas.clientHeight;
40
  }
41
  window.addEventListener('resize', resize);
42
  resize();
@@ -57,15 +63,18 @@ def render_shroom_tab():
57
 
58
  ctx.fillStyle = '#4a3b32';
59
  const isBlinking = (time % m.blinkInterval) < 150;
60
- if (isBlinking) { ctx.fillRect(-7, 12, 4, 2); ctx.fillRect(3, 12, 4, 2); }
61
- else { ctx.beginPath(); ctx.arc(-5, 12, 2.5, 0, Math.PI*2); ctx.fill(); ctx.beginPath(); ctx.arc(5, 12, 2.5, 0, Math.PI*2); ctx.fill(); }
62
-
 
 
 
 
63
  ctx.restore();
64
  }
65
 
66
  function animate(time) {
67
  ctx.clearRect(0, 0, canvas.width, canvas.height);
68
-
69
  if (Math.random() < 0.02 && mushrooms.length < 20) {
70
  mushrooms.push({
71
  x: Math.random() * canvas.width,
@@ -77,7 +86,6 @@ def render_shroom_tab():
77
  life: 500
78
  });
79
  }
80
-
81
  mushrooms.forEach((m, i) => {
82
  m.life--;
83
  m.currentSize += (m.targetSize - m.currentSize) * 0.05;
@@ -85,7 +93,6 @@ def render_shroom_tab():
85
  if (m.life < 0) m.targetSize = 0;
86
  if (m.life < 0 && m.currentSize < 0.05) mushrooms.splice(i, 1);
87
  });
88
-
89
  requestAnimationFrame(animate);
90
  }
91
  animate(0);
 
1
  import gradio as gr
 
2
  from game.engine import get_myco_narrative
3
 
4
+ # Exported CSS for use in your app.launch(css=MYCO_CSS)
5
+ MYCO_CSS = """
6
+ #garden-canvas {
7
+ width: 100%;
8
+ height: 400px;
9
+ background: linear-gradient(180deg, #1a2b4c 0%, #2a4c5e 50%, #4a7c59 100%);
10
+ border-radius: 12px;
11
+ }
12
+ #narrative-box {
13
+ font-family: 'Courier New', monospace;
14
+ font-size: 15px;
15
+ color: #52ff6b;
16
+ background: #090e0b;
17
+ padding: 15px;
18
+ border-radius: 8px;
19
+ border: 1px solid rgba(82, 255, 107, 0.3);
20
+ text-align: center;
21
+ margin-top: 10px;
22
+ }
23
+ """
24
+
25
  def render_shroom_tab():
26
+ with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  # 1. The Canvas
28
  gr.HTML("<canvas id='garden-canvas'></canvas>")
29
 
30
  # 2. The Narrative
31
  narrative = gr.Markdown(value="Waiting for the forest to wake...", elem_id="narrative-box")
32
 
33
+ # 3. Timer (Updates every 20s via game engine)
34
  gr.Timer(20).tick(fn=get_myco_narrative, outputs=narrative)
35
 
36
  # 4. Injected Animation Logic
 
41
  const ctx = canvas.getContext('2d');
42
 
43
  function resize() {
44
+ canvas.width = canvas.parentElement.clientWidth;
45
+ canvas.height = 400;
46
  }
47
  window.addEventListener('resize', resize);
48
  resize();
 
63
 
64
  ctx.fillStyle = '#4a3b32';
65
  const isBlinking = (time % m.blinkInterval) < 150;
66
+ if (isBlinking) {
67
+ ctx.fillRect(-7, 12, 4, 2);
68
+ ctx.fillRect(3, 12, 4, 2);
69
+ } else {
70
+ ctx.beginPath(); ctx.arc(-5, 12, 2.5, 0, Math.PI*2); ctx.fill();
71
+ ctx.beginPath(); ctx.arc(5, 12, 2.5, 0, Math.PI*2); ctx.fill();
72
+ }
73
  ctx.restore();
74
  }
75
 
76
  function animate(time) {
77
  ctx.clearRect(0, 0, canvas.width, canvas.height);
 
78
  if (Math.random() < 0.02 && mushrooms.length < 20) {
79
  mushrooms.push({
80
  x: Math.random() * canvas.width,
 
86
  life: 500
87
  });
88
  }
 
89
  mushrooms.forEach((m, i) => {
90
  m.life--;
91
  m.currentSize += (m.targetSize - m.currentSize) * 0.05;
 
93
  if (m.life < 0) m.targetSize = 0;
94
  if (m.life < 0 && m.currentSize < 0.05) mushrooms.splice(i, 1);
95
  });
 
96
  requestAnimationFrame(animate);
97
  }
98
  animate(0);