masadonline commited on
Commit
a8aa6e6
·
verified ·
1 Parent(s): d8707ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -31
app.py CHANGED
@@ -62,26 +62,19 @@ if code.strip():
62
 
63
  # A-Frame VR scene with interactivity and export
64
  def generate_aframe(call_graph):
65
- spacing = 3
66
- boxes = []
67
- lines = []
68
- positions = []
 
69
 
70
  function_positions = {}
 
71
  i = 0
72
  for fn in call_graph:
73
  x = i * spacing
74
  function_positions[fn] = (x, 1, -3)
75
- positions.append(fn)
76
- boxes.append(f"""
77
- <a-box id="{fn}" position="{x} 1 -3" depth="0.5" height="0.5" width="2" color="#FFC65D"
78
- class="clickable"
79
- event-set__enter="_event: mouseenter; color: #00CED1"
80
- event-set__leave="_event: mouseleave; color: #FFC65D"
81
- onclick="say('{fn}')">
82
- </a-box>
83
- <a-text value="{fn}" position="{x} 2 -3" align="center" color="#000"></a-text>
84
- """)
85
  i += 1
86
 
87
  for caller, callees in call_graph.items():
@@ -89,30 +82,54 @@ if code.strip():
89
  if callee in function_positions:
90
  x1, y1, z1 = function_positions[caller]
91
  x2, y2, z2 = function_positions[callee]
92
- lines.append(f"""
93
- <a-entity line="start: {x1} {y1} {z1}; end: {x2} {y2} {z2}; color: red"></a-entity>
94
- """)
95
 
96
- # JavaScript for text-to-speech on click + screenshot
97
  js = """
98
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  function say(text) {
100
  const utter = new SpeechSynthesisUtterance(text);
101
  speechSynthesis.speak(utter);
102
  }
103
- function downloadScreenshot() {
104
- const scene = document.querySelector('a-scene');
105
- scene.components.screenshot.capture('perspective');
106
- setTimeout(() => {
107
- const a = document.createElement('a');
108
- a.href = scene.components.screenshot.canvas.toDataURL();
109
- a.download = 'scene.png';
110
- a.click();
111
- }, 500);
112
- }
113
  </script>
114
  """
115
 
 
116
  html = f"""
117
  <!DOCTYPE html>
118
  <html>
@@ -123,15 +140,12 @@ if code.strip():
123
  {js}
124
  </head>
125
  <body>
126
- <button onclick="downloadScreenshot()" style="position: absolute; z-index: 9999; top: 10px; left: 10px; font-size: 16px;">📸 Download Screenshot</button>
127
  <a-scene screenshot>
128
  <a-entity position="0 1.6 3">
129
  <a-camera wasd-controls-enabled="true" look-controls-enabled="true"></a-camera>
130
  </a-entity>
131
  <a-light type="ambient" color="#FFF"></a-light>
132
  <a-plane rotation="-90 0 0" width="40" height="40" color="#7BC8A4"></a-plane>
133
- {''.join(boxes)}
134
- {''.join(lines)}
135
  </a-scene>
136
  </body>
137
  </html>
 
62
 
63
  # A-Frame VR scene with interactivity and export
64
  def generate_aframe(call_graph):
65
+ # Serialize function data to JSON format
66
+ function_data = {
67
+ "functions": [],
68
+ "relationships": []
69
+ }
70
 
71
  function_positions = {}
72
+ spacing = 3
73
  i = 0
74
  for fn in call_graph:
75
  x = i * spacing
76
  function_positions[fn] = (x, 1, -3)
77
+ function_data["functions"].append({"name": fn, "position": [x, 1, -3]})
 
 
 
 
 
 
 
 
 
78
  i += 1
79
 
80
  for caller, callees in call_graph.items():
 
82
  if callee in function_positions:
83
  x1, y1, z1 = function_positions[caller]
84
  x2, y2, z2 = function_positions[callee]
85
+ function_data["relationships"].append({"start": [x1, y1, z1], "end": [x2, y2, z2]})
 
 
86
 
87
+ # JavaScript to render the function data dynamically using JSON
88
  js = """
89
  <script>
90
+ // The JSON data will be passed as a global variable
91
+ const functionData = """ + str(function_data).replace("'", '"') + """;
92
+
93
+ // Render boxes dynamically based on function data
94
+ functionData.functions.forEach(function(fn) {
95
+ const el = document.createElement('a-box');
96
+ el.setAttribute('id', fn.name);
97
+ el.setAttribute('position', fn.position.join(' '));
98
+ el.setAttribute('depth', '0.5');
99
+ el.setAttribute('height', '0.5');
100
+ el.setAttribute('width', '2');
101
+ el.setAttribute('color', '#FFC65D');
102
+ el.setAttribute('class', 'clickable');
103
+ el.setAttribute('event-set__enter', '_event: mouseenter; color: #00CED1');
104
+ el.setAttribute('event-set__leave', '_event: mouseleave; color: #FFC65D');
105
+ el.setAttribute('onclick', `say('${fn.name}')`);
106
+ document.querySelector('a-scene').appendChild(el);
107
+
108
+ // Add text for the function
109
+ const text = document.createElement('a-text');
110
+ text.setAttribute('value', fn.name);
111
+ text.setAttribute('position', `${fn.position[0]} ${fn.position[1] + 1} ${fn.position[2]}`);
112
+ text.setAttribute('align', 'center');
113
+ text.setAttribute('color', '#000');
114
+ document.querySelector('a-scene').appendChild(text);
115
+ });
116
+
117
+ // Render relationship lines dynamically based on function data
118
+ functionData.relationships.forEach(function(rel) {
119
+ const el = document.createElement('a-entity');
120
+ el.setAttribute('line', `start: ${rel.start.join(' ')}; end: ${rel.end.join(' ')}; color: red`);
121
+ document.querySelector('a-scene').appendChild(el);
122
+ });
123
+
124
+ // Text-to-speech function for box click
125
  function say(text) {
126
  const utter = new SpeechSynthesisUtterance(text);
127
  speechSynthesis.speak(utter);
128
  }
 
 
 
 
 
 
 
 
 
 
129
  </script>
130
  """
131
 
132
+ # HTML structure for A-Frame scene
133
  html = f"""
134
  <!DOCTYPE html>
135
  <html>
 
140
  {js}
141
  </head>
142
  <body>
 
143
  <a-scene screenshot>
144
  <a-entity position="0 1.6 3">
145
  <a-camera wasd-controls-enabled="true" look-controls-enabled="true"></a-camera>
146
  </a-entity>
147
  <a-light type="ambient" color="#FFF"></a-light>
148
  <a-plane rotation="-90 0 0" width="40" height="40" color="#7BC8A4"></a-plane>
 
 
149
  </a-scene>
150
  </body>
151
  </html>