Spaces:
Sleeping

byte-vortex commited on
Commit
ce9857e
·
verified ·
1 Parent(s): 7232542

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/scene_renderers.py +153 -56
ui/scene_renderers.py CHANGED
@@ -1,4 +1,7 @@
1
- """Markdown & HTML renderers for the Myco Gradio interface — multiple digital art styles."""
 
 
 
2
 
3
  from html import escape
4
  import hashlib
@@ -8,14 +11,69 @@ POISONOUS_MUSHROOM_NAMES = {
8
  "Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
9
  }
10
 
11
- # Expanded sprites mapped to thematic vibes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  MUSHROOM_SPRITES = {
13
- "poison": ["🔴", "💀", "🟥"],
14
- "legendary": ["⭐", "🌟", "✨"],
15
- "rare": ["💜", "🔵", "💎"],
16
- "cyberpunk": ["👾", "⚡", "🔮"],
17
- "pixel": ["👾", "🕹️", "🧱"],
18
- "common": ["🍄", "🍄‍🟫", "🟫"],
19
  }
20
 
21
  SCENE_STYLES = """
@@ -47,50 +105,47 @@ SCENE_STYLES = """
47
  font-family: 'Courier New', monospace;
48
  }
49
  .theme-cyberpunk .scene-hud { background: rgba(255, 0, 127, 0.2) !important; border: 1px solid #00f2fe; color: #00f2fe !important; }
50
- .theme-cyberpunk .shroom-cap { filter: drop-shadow(0 0 15px #00f2fe) drop-shadow(0 0 30px #ff007f) !important; }
51
- .theme-cyberpunk .shroom-stem { background: linear-gradient(180deg, #00f2fe, #ff007f) !important; width: 0.4rem !important; }
52
 
53
  /* ── STYLE 3: 8-BIT PIXEL ART ── */
54
  .theme-pixel {
55
  background: repeating-conic-gradient(#2a2a2a 0% 25%, #1f1f1f 0% 50%) 50% / 20px 20px !important;
56
  border: 4px dashed #ffcc00 !important;
57
- image-rendering: pixelated;
58
  }
59
  .theme-pixel * { font-family: 'Courier New', monospace; font-weight: bold; }
60
- .theme-pixel .shroom-cap { font-size: 3.5rem !important; transform: scale(1.1); filter: drop-shadow(4px 4px 0px #000); }
61
- .theme-pixel .shroom-stem { background: #ffcc00 !important; width: 1.2rem !important; border: 3px solid #000; border-radius: 0px !important; }
 
 
62
 
63
  /* ── STYLE 4: GLITCH ART ── */
64
  .theme-glitch {
65
  background: linear-gradient(45deg, #111, #221a2b, #0a1c1c) !important;
66
  border: 2px solid #00ffcc !important;
67
  }
68
- .theme-glitch .shroom-cap {
69
  animation: glitch-anim 1s linear infinite alternate !important;
70
- text-shadow: 3px 0 0 rgba(255,0,0,.4), -3px 0 0 rgba(0,0,255,.4);
71
  }
72
  @keyframes glitch-anim {
73
- 0% { transform: skew(0deg) scale(1); }
74
- 20% { transform: skew(-4deg) scale(1.05); filter: hue-rotate(90deg); }
75
- 40% { transform: skew(5deg) scale(0.95); }
76
- 60% { transform: skew(-2deg) scale(1); filter: blur(1px); }
77
- 80% { transform: skew(3deg) scale(1.02); }
78
  100% { transform: skew(0deg) scale(1); }
79
  }
80
 
81
- /* ── STYLE 5: SYNTHWAVE / VAPORWAVE ── */
82
  .theme-synthwave {
83
  background:
84
- linear-gradient(0deg, rgba(255, 105, 180, 0.2) 1px, transparent 1px),
85
- linear-gradient(90deg, rgba(255, 105, 180, 0.2) 1px, transparent 1px),
86
  linear-gradient(180deg, #2b003a 0%, #0c0014 100%) !important;
87
  background-size: 20px 20px, 20px 20px, auto;
88
  border: 1px solid #ff69b4 !important;
89
  }
90
- .theme-synthwave .shroom-cap { filter: drop-shadow(0 -5px 10px #ff69b4) !important; animation: float-wave 3s ease-in-out infinite !important; }
91
  @keyframes float-wave {
92
  0%, 100% { transform: translateY(0px) rotate(-3deg); }
93
- 50% { transform: translateY(-10px) rotate(3deg); }
94
  }
95
 
96
  /* ── Core Layout Modules ── */
@@ -114,8 +169,8 @@ SCENE_STYLES = """
114
  }
115
 
116
  /* Decor elements */
117
- .tree-left { left: 4%; bottom: 30%; font-size: 5rem; opacity: 0.6; z-index: 1; }
118
- .tree-right { right: 5%; bottom: 32%; font-size: 4.6rem; opacity: 0.6; z-index: 1; }
119
  .myco-player {
120
  font-size: 4.2rem; z-index: 5; bottom: 28%;
121
  transition: left .38s cubic-bezier(.34,1.56,.64,1), bottom .38s cubic-bezier(.34,1.56,.64,1);
@@ -130,44 +185,70 @@ SCENE_STYLES = """
130
  @keyframes myco-bob { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-.4rem);} }
131
 
132
  /* Mushroom Spot Architecture */
133
- .mushroom-spot { z-index: 4; display: flex; flex-direction: column; align-items: center; gap: 0; right: 30%; bottom: 28%; }
134
- .shroom-stem { width: .7rem; height: 1.2rem; border-radius: 2px; background: linear-gradient(180deg,#d4a96a,#8b5e2a); }
135
- .shroom-cap { font-size: 2.8rem; line-height: 1; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3)); }
136
 
137
  /* State Modifications */
138
  .state-waiting .mushroom-spot { display: none; }
139
- .state-picked .shroom-cap { animation: shroom-fly .6s ease both; }
140
- .state-picked .shroom-stem { display: none; }
141
  @keyframes shroom-fly { 100% { transform: translateY(-10rem) scale(0); opacity: 0; } }
142
 
143
  .state-game-over { filter: grayscale(0.8) contrast(1.2); background: #220000 !important; }
144
  </style>
145
  """
146
 
147
- def get_art_theme(mushroom_name: str) -> tuple[str, str]:
148
- """Deterministically maps a mushroom name to an art style class and style title."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  if not mushroom_name:
150
- return "theme-organic", "Organic"
151
 
152
- # Generate a simple reliable hash index
153
  hash_val = int(hashlib.md5(mushroom_name.encode('utf-8')).hexdigest(), 16)
 
 
154
  themes = [
155
- ("theme-organic", "🌲 Organic Form"),
156
- ("theme-cyberpunk", "⚡ Neon Cyberpunk"),
157
- ("theme-pixel", "🕹️ 8-Bit Pixel"),
158
- ("theme-glitch", "👾 Glitch Art"),
159
- ("theme-synthwave", "🌌 Synthwave Retro")
160
  ]
161
  return themes[hash_val % len(themes)]
162
 
 
163
  def forest_scene(current, collection, position):
164
- """Renders the HTML stage injected with procedural style definitions."""
165
  px, py = position if position else (1, 1)
166
 
167
  state_class = "state-waiting"
168
  theme_class = "theme-organic"
169
  style_title = "Organic"
170
- cap_emoji = "🍄"
 
 
171
 
172
  if current:
173
  name = current.get("name", "")
@@ -176,25 +257,43 @@ def forest_scene(current, collection, position):
176
  is_game_over = current.get("game_over") == "Yes"
177
  rarity = current.get("rarity", "Common").lower()
178
 
179
- # Extract emergent visual theme
180
- theme_class, style_title = get_art_theme(name)
181
 
182
  if is_game_over:
183
  state_class = "state-game-over"
 
184
  elif is_picked:
185
  state_class = "state-picked"
186
  else:
187
  state_class = "state-discovered"
188
 
189
- # Match emoji visuals based on rarity or art style
190
- if theme_class == "theme-cyberpunk":
191
- cap_emoji = MUSHROOM_SPRITES["cyberpunk"][hash(name) % len(MUSHROOM_SPRITES["cyberpunk"])]
 
 
 
 
 
 
192
  elif theme_class == "theme-pixel":
193
- cap_emoji = MUSHROOM_SPRITES["pixel"][hash(name) % len(MUSHROOM_SPRITES["pixel"])]
194
- elif is_poison:
195
- cap_emoji = MUSHROOM_SPRITES["poison"][0]
 
 
 
 
 
 
 
 
 
 
196
  else:
197
- cap_emoji = MUSHROOM_SPRITES.get(rarity, MUSHROOM_SPRITES["common"])[0]
 
198
 
199
  return f"""
200
  {SCENE_STYLES}
@@ -202,7 +301,7 @@ def forest_scene(current, collection, position):
202
  <div class="scene-hud">
203
  <span>📍 Region: X:{px} Y:{py}</span>
204
  <span>Render Engine: {style_title}</span>
205
- <span>{"🍄 Target Loaded" if state_class != "state-waiting" else "🌿 Scanning clearing..."}</span>
206
  </div>
207
  <div class="scene-stage">
208
  <span class="tree-left">🌲</span>
@@ -212,8 +311,7 @@ def forest_scene(current, collection, position):
212
  <div class="myco-player">🍄</div>
213
 
214
  <div class="mushroom-spot">
215
- <div class="shroom-cap">{cap_emoji}</div>
216
- <div class="shroom-stem"></div>
217
  </div>
218
  </div>
219
  </div>
@@ -250,4 +348,3 @@ def game_intro_markdown():
250
 
251
  def play_hook_markdown():
252
  return "What will Myco discover next?"
253
-
 
1
+ """Markdown & HTML renderers for the Myco Gradio interface.
2
+
3
+ Translates mathematical 2D matrix arrays directly into procedural 8-bit pixel art mushrooms.
4
+ """
5
 
6
  from html import escape
7
  import hashlib
 
11
  "Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
12
  }
13
 
14
+ # ── 8-BIT MATRIX BLUEPRINTS ──
15
+ # 0 = Transparent Sky/Void space
16
+ # 1 = Outer structural outlines (Dark Slate/Black)
17
+ # 2 = Primary Cap Color (Dynamic based on theme)
18
+ # 3 = Secondary Spot/Accent Color (Dynamic based on theme)
19
+ # 4 = Stem Body Color (Dynamic based on theme)
20
+
21
+ # Visualizing MATRIX_DOME: Creates a classic rounded toadstool cap
22
+ MATRIX_DOME = [
23
+ [0,0,0,1,1,1,1,0,0,0], # Top Outline
24
+ [0,0,1,2,2,3,2,1,0,0], # Cap Curve with spot
25
+ [0,1,2,2,3,2,2,2,1,0], # Mid Cap
26
+ [1,2,3,2,2,2,3,2,2,1], # Wide Base
27
+ [1,1,1,1,1,4,1,1,1,1], # Cap Rim meeting Stem
28
+ [0,0,0,0,1,4,1,0,0,0], # Stem Trunk
29
+ [0,0,0,0,1,4,1,0,0,0], # Stem Trunk
30
+ [0,0,0,0,1,1,1,0,0,0] # Ground Base Outline
31
+ ]
32
+
33
+ # Visualizing MATRIX_SKULL: Creates an eerie, hollow-eyed toxic mushroom shape
34
+ MATRIX_SKULL = [
35
+ [0,0,1,1,1,1,1,1,0,0],
36
+ [0,1,2,2,2,2,2,2,1,0],
37
+ [1,2,1,2,2,2,1,2,2,1], # Hollow eye slots (1) inside the cap
38
+ [1,2,1,2,2,2,1,2,2,1],
39
+ [0,1,2,2,1,1,2,2,1,0], # Tapering cheek bone shapes
40
+ [0,0,1,2,1,1,2,1,0,0],
41
+ [0,0,1,4,4,4,4,1,0,0], # Thick interlocking root stem
42
+ [0,0,0,1,1,1,1,0,0,0]
43
+ ]
44
+
45
+ # Visualizing MATRIX_FLAT: Creates a wide, umbrella-like shelf fungus profile
46
+ MATRIX_FLAT = [
47
+ [0,0,1,1,1,1,1,1,0,0],
48
+ [0,1,3,2,2,2,3,2,1,0],
49
+ [1,2,2,2,3,2,2,2,2,1], # Wide, stretched horizontal frame
50
+ [1,1,1,1,4,4,1,1,1,1],
51
+ [0,0,0,1,4,4,1,0,0,0],
52
+ [0,0,0,1,4,4,1,0,0,0],
53
+ [0,0,1,4,4,4,4,1,0,0],
54
+ [0,0,1,1,1,1,1,1,0,0]
55
+ ]
56
+
57
+ # Visualizing MATRIX_STAR: Creates a spiky, geometric magical star-cap shape
58
+ MATRIX_STAR = [
59
+ [0,0,0,0,1,1,0,0,0,0], # Star apex point
60
+ [0,1,0,1,2,2,1,0,1,0], # Spire flares
61
+ [1,2,1,2,2,2,2,1,2,1], # Wide lateral points
62
+ [0,1,2,3,2,2,3,2,1,0],
63
+ [0,0,1,1,4,4,1,1,0,0],
64
+ [0,0,0,1,4,4,1,0,0,0],
65
+ [0,0,0,1,4,4,1,0,0,0],
66
+ [0,0,0,1,1,1,1,0,0,0]
67
+ ]
68
+
69
+ # Structural Sprite Mapping Directory
70
  MUSHROOM_SPRITES = {
71
+ "poison": [MATRIX_SKULL, MATRIX_DOME, MATRIX_FLAT],
72
+ "legendary": [MATRIX_STAR, MATRIX_DOME, MATRIX_STAR],
73
+ "rare": [MATRIX_DOME, MATRIX_FLAT, MATRIX_DOME],
74
+ "cyberpunk": [MATRIX_FLAT, MATRIX_SKULL, MATRIX_DOME],
75
+ "pixel": [MATRIX_DOME, MATRIX_FLAT, MATRIX_DOME],
76
+ "common": ["🍄", "🍄‍🟫"] # Kept as clean text emojis as requested
77
  }
78
 
79
  SCENE_STYLES = """
 
105
  font-family: 'Courier New', monospace;
106
  }
107
  .theme-cyberpunk .scene-hud { background: rgba(255, 0, 127, 0.2) !important; border: 1px solid #00f2fe; color: #00f2fe !important; }
108
+ .theme-cyberpunk .shroom-art-wrap { filter: drop-shadow(0 0 15px #00f2fe) drop-shadow(0 0 30px #ff007f) !important; }
 
109
 
110
  /* ── STYLE 3: 8-BIT PIXEL ART ── */
111
  .theme-pixel {
112
  background: repeating-conic-gradient(#2a2a2a 0% 25%, #1f1f1f 0% 50%) 50% / 20px 20px !important;
113
  border: 4px dashed #ffcc00 !important;
 
114
  }
115
  .theme-pixel * { font-family: 'Courier New', monospace; font-weight: bold; }
116
+ .theme-pixel .shroom-art-wrap {
117
+ transform: scale(1.4);
118
+ filter: drop-shadow(5px 5px 0px #000);
119
+ }
120
 
121
  /* ── STYLE 4: GLITCH ART ── */
122
  .theme-glitch {
123
  background: linear-gradient(45deg, #111, #221a2b, #0a1c1c) !important;
124
  border: 2px solid #00ffcc !important;
125
  }
126
+ .theme-glitch .shroom-art-wrap {
127
  animation: glitch-anim 1s linear infinite alternate !important;
 
128
  }
129
  @keyframes glitch-anim {
130
+ 0% { transform: skew(0deg) scale(1); filter: hue-rotate(0deg); }
131
+ 30% { transform: skew(-4deg) scale(1.05); filter: hue-rotate(90deg); }
132
+ 70% { transform: skew(5deg) scale(0.95); filter: contrast(1.5); }
 
 
133
  100% { transform: skew(0deg) scale(1); }
134
  }
135
 
136
+ /* ── STYLE 5: SYNTHWAVE RETRO ── */
137
  .theme-synthwave {
138
  background:
139
+ linear-gradient(0deg, rgba(255, 105, 180, 0.15) 1px, transparent 1px),
140
+ linear-gradient(90deg, rgba(255, 105, 180, 0.15) 1px, transparent 1px),
141
  linear-gradient(180deg, #2b003a 0%, #0c0014 100%) !important;
142
  background-size: 20px 20px, 20px 20px, auto;
143
  border: 1px solid #ff69b4 !important;
144
  }
145
+ .theme-synthwave .shroom-art-wrap { animation: float-wave 3s ease-in-out infinite !important; }
146
  @keyframes float-wave {
147
  0%, 100% { transform: translateY(0px) rotate(-3deg); }
148
+ 50% { transform: translateY(-8px) rotate(3deg); }
149
  }
150
 
151
  /* ── Core Layout Modules ── */
 
169
  }
170
 
171
  /* Decor elements */
172
+ .tree-left { left: 4%; bottom: 30%; font-size: 5rem; opacity: 0.2; z-index: 1; }
173
+ .tree-right { right: 5%; bottom: 32%; font-size: 4.6rem; opacity: 0.2; z-index: 1; }
174
  .myco-player {
175
  font-size: 4.2rem; z-index: 5; bottom: 28%;
176
  transition: left .38s cubic-bezier(.34,1.56,.64,1), bottom .38s cubic-bezier(.34,1.56,.64,1);
 
185
  @keyframes myco-bob { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-.4rem);} }
186
 
187
  /* Mushroom Spot Architecture */
188
+ .mushroom-spot { z-index: 4; display: flex; flex-direction: column; align-items: center; right: 30%; bottom: 34%; }
189
+ .shroom-art-wrap { display: inline-block; image-rendering: pixelated; image-rendering: crisp-edges; }
190
+ .shroom-emoji-fallback { font-size: 2.8rem; line-height: 1; }
191
 
192
  /* State Modifications */
193
  .state-waiting .mushroom-spot { display: none; }
194
+ .state-picked .shroom-art-wrap, .state-picked .shroom-emoji-fallback { animation: shroom-fly .6s ease both; }
 
195
  @keyframes shroom-fly { 100% { transform: translateY(-10rem) scale(0); opacity: 0; } }
196
 
197
  .state-game-over { filter: grayscale(0.8) contrast(1.2); background: #220000 !important; }
198
  </style>
199
  """
200
 
201
+ def render_matrix_to_pixels(matrix: list[list[int]], cap_color: str, spot_color: str, stem_color: str) -> str:
202
+ """Processes numerical 2D array mappings into rendering coordinate data strings."""
203
+ color_map = {
204
+ 1: "#121214", # Outer outline values
205
+ 2: cap_color, # Active surface cap hex color
206
+ 3: spot_color, # Active dot accent hex color
207
+ 4: stem_color # Main foot stem hex color
208
+ }
209
+
210
+ px_scale = 5
211
+ shadow_layers = []
212
+
213
+ for r_idx, row in enumerate(matrix):
214
+ for c_idx, val in enumerate(row):
215
+ if val in color_map:
216
+ # Math Translation: column * width, row * height offsets mapping out shapes
217
+ shadow_layers.append(f"{c_idx * px_scale}px {r_idx * px_scale}px 0 {color_map[val]}")
218
+
219
+ width = len(matrix[0]) * px_scale
220
+ height = len(matrix) * px_scale
221
+ return f'<div style="width:{px_scale}px; height:{px_scale}px; margin-right:{width}px; margin-bottom:{height}px; background:transparent; box-shadow:{", ".join(shadow_layers)};"></div>'
222
+
223
+
224
+ def get_art_theme(mushroom_name: str) -> tuple[str, str, str, str, str]:
225
+ """Resolves background themes and color hex codes based on the unique mushroom name."""
226
  if not mushroom_name:
227
+ return "theme-organic", "Organic Form", "#e63946", "#ffffff", "#f1faee"
228
 
 
229
  hash_val = int(hashlib.md5(mushroom_name.encode('utf-8')).hexdigest(), 16)
230
+
231
+ # Structure definition: (theme_class, style_name, cap_hex, spot_hex, stem_hex)
232
  themes = [
233
+ ("theme-organic", "🌲 Organic Form", "#d62828", "#f77f00", "#fcbf49"),
234
+ ("theme-cyberpunk", "⚡ Neon Cyberpunk", "#00f2fe", "#ff007f", "#25003e"),
235
+ ("theme-pixel", "🕹️ 8-Bit Pixel", "#ffb703", "#ffffff", "#fb8500"),
236
+ ("theme-glitch", "👾 Glitch Art", "#00ffcc", "#ff0055", "#111111"),
237
+ ("theme-synthwave", "🌌 Synthwave Retro", "#ff007f", "#7209b7", "#4cc9f0")
238
  ]
239
  return themes[hash_val % len(themes)]
240
 
241
+
242
  def forest_scene(current, collection, position):
243
+ """Assembles and generates the final viewable HTML interface snippet."""
244
  px, py = position if position else (1, 1)
245
 
246
  state_class = "state-waiting"
247
  theme_class = "theme-organic"
248
  style_title = "Organic"
249
+
250
+ cap_hex, spot_hex, stem_hex = "#d62828", "#fcbf49", "#eae2b7"
251
+ markup_out = ""
252
 
253
  if current:
254
  name = current.get("name", "")
 
257
  is_game_over = current.get("game_over") == "Yes"
258
  rarity = current.get("rarity", "Common").lower()
259
 
260
+ # 1. Resolve theme information
261
+ theme_class, style_title, cap_hex, spot_hex, stem_hex = get_art_theme(name)
262
 
263
  if is_game_over:
264
  state_class = "state-game-over"
265
+ cap_hex, spot_hex, stem_hex = "#2b2b2b", "#1a1a1a", "#444444"
266
  elif is_picked:
267
  state_class = "state-picked"
268
  else:
269
  state_class = "state-discovered"
270
 
271
+ if is_poison:
272
+ cap_hex, spot_hex, stem_hex = "#7a0010", "#ff3333", "#3a0007"
273
+ style_title += " (⚠️ TOXIC DETECTED)"
274
+
275
+ # 2. Select targeted key mapping category
276
+ if is_poison:
277
+ pool_key = "poison"
278
+ elif theme_class == "theme-cyberpunk":
279
+ pool_key = "cyberpunk"
280
  elif theme_class == "theme-pixel":
281
+ pool_key = "pixel"
282
+ else:
283
+ pool_key = rarity if rarity in MUSHROOM_SPRITES else "common"
284
+
285
+ # 3. Translate lookups directly into output markup
286
+ pool_variants = MUSHROOM_SPRITES.get(pool_key, MUSHROOM_SPRITES["common"])
287
+ name_hash = int(hashlib.md5(name.encode('utf-8')).hexdigest(), 16)
288
+ chosen_variant = pool_variants[name_hash % len(pool_variants)]
289
+
290
+ if isinstance(chosen_variant, list):
291
+ # If our sprite registry contains a list matrix, send it to the processing loop
292
+ pixel_data = render_matrix_to_pixels(chosen_variant, cap_hex, spot_hex, stem_hex)
293
+ markup_out = f'<div class="shroom-art-wrap">{pixel_data}</div>'
294
  else:
295
+ # Fallback directly to text strings for basic standard variations
296
+ markup_out = f'<div class="shroom-emoji-fallback">{chosen_variant}</div>'
297
 
298
  return f"""
299
  {SCENE_STYLES}
 
301
  <div class="scene-hud">
302
  <span>📍 Region: X:{px} Y:{py}</span>
303
  <span>Render Engine: {style_title}</span>
304
+ <span>{"🍄 Matrix Assembly Active" if state_class != "state-waiting" else "🌿 Scanning clearing..."}</span>
305
  </div>
306
  <div class="scene-stage">
307
  <span class="tree-left">🌲</span>
 
311
  <div class="myco-player">🍄</div>
312
 
313
  <div class="mushroom-spot">
314
+ {markup_out}
 
315
  </div>
316
  </div>
317
  </div>
 
348
 
349
  def play_hook_markdown():
350
  return "What will Myco discover next?"