Guest User

Untitled

a guest
Aug 5th, 2025
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. sample .branch:
  2. {
  3. "meta": { "cw_version": "0.4", "title": "Jacked Beavers" },
  4. "body": [
  5. { "type": "header", "level": 1, "text": "Jacked Beavers" },
  6. { "type": "timer", "interval_ms": 2500, "invokes": "/cycle_art.ww", "repeat": true },
  7. {
  8. "type": "canvas",
  9. "id": "main_art_canvas",
  10. "width": 300,
  11. "height": 200,
  12. "elements": [
  13. { "shape": "rectangle", "coords": [0, 100, 300, 200], "fill": "#6495ED", "outline": "" },
  14. { "shape": "rectangle", "coords": [75, 80, 225, 150], "fill": "#8B4513", "outline": "black" },
  15. { "shape": "polygon", "points": [60, 80, 240, 80, 150, 40], "fill": "#A0522D", "outline": "black" },
  16. { "shape": "rectangle", "coords": [135, 110, 165, 150], "fill": "#F5DEB3", "outline": "black" },
  17. { "shape": "oval", "coords": [240, 20, 280, 60], "fill": "#FFD700", "outline": "yellow" }
  18. ]
  19. },
  20. { "type": "button", "text": "Skip to next image", "invokes": "/cycle_art.ww" },
  21. { "type": "link", "text": "Exodus", "url": "cryptic://{{HOST}}:{{PORT}}/" }
  22. ]
  23. }
  24.  
  25.  
  26.  
  27. sample .ww:
  28. import json
  29.  
  30. BEAVER_ART = [
  31. # Image 1: Beaver lodge
  32. {
  33. "type": "canvas", "id": "main_art_canvas", "width": 300, "height": 200,
  34. "elements": [
  35. { "shape": "rectangle", "coords": [0, 100, 300, 200], "fill": "#6495ED", "outline": ""},
  36. { "shape": "rectangle", "coords": [75, 80, 225, 150], "fill": "#8B4513", "outline": "black"},
  37. { "shape": "polygon", "points": [60, 80, 240, 80, 150, 40], "fill": "#A0522D", "outline": "black"},
  38. { "shape": "rectangle", "coords": [135, 110, 165, 150], "fill": "#F5DEB3", "outline": "black"},
  39. { "shape": "oval", "coords": [240, 20, 280, 60], "fill": "#FFD700", "outline": "yellow"}
  40. ]
  41. },
  42. # Image 2: Beaver face
  43. {
  44. "type": "canvas", "id": "main_art_canvas", "width": 300, "height": 200,
  45. "elements": [
  46. { "shape": "rectangle", "coords": [0, 100, 300, 200], "fill": "#6495ED", "outline": "" },
  47. { "shape": "rectangle", "coords": [75, 80, 225, 150], "fill": "#8B4513", "outline": "black" },
  48. { "shape": "polygon", "points": [60, 80, 240, 80, 150, 40], "fill": "#A0522D", "outline": "black" },
  49. { "shape": "rectangle", "coords": [135, 110, 165, 150], "fill": "#F5DEB3", "outline": "black" },
  50. { "shape": "oval", "coords": [240, 20, 280, 60], "fill": "#FFD700", "outline": "yellow" }
  51. ]
  52. }
  53. ]
  54.  
  55. def run(context):
  56. if not BEAVER_ART:
  57. # return blank if nothing to cycle through; else server crash until better guards
  58. return {"actions": []}
  59.  
  60. client_state = json.loads(context.get("body", "{}"))
  61. current_index = client_state.get("current_image_index", 0)
  62.  
  63. next_index = (current_index + 1) % len(BEAVER_ART)
  64.  
  65. new_canvas_component = BEAVER_ART[next_index]
  66.  
  67. patch = {
  68. "actions": [
  69. {
  70. "action": "replace",
  71. "target_id": "main_art_canvas",
  72. "component": new_canvas_component
  73. },
  74. {
  75. "action": "update_state",
  76. "state": {"current_image_index": next_index}
  77. }
  78. ]
  79. }
  80.  
  81. return patch
Advertisement
Add Comment
Please, Sign In to add comment