(click on the green button to run the code)
initialState()
w_hat
(colored) and w
(grayscale)',
},
},
'SMC2D-tab': {
'scripts': {
'main': 'smc_2d.py',
'user': 'smc_2d_example.py',
'ui': 'ui.py',
'common': 'common.py',
},
'texts': {
'help': 'If you need context about how this code is used, see this script and this one',
'legend': 'w_hat
w
',
},
'has_histogram': True,
},
'HEDAC-tab': {
'scripts': {
'main': 'hedac.py',
'user': 'hedac_example.py',
'ui': 'ui.py',
'common': 'common.py',
},
'texts': {
'help': 'If you need context about how this code is used, see this script and this one',
'legend': '',
},
}
}
# UI-related variables
canvas = document.getElementById('canvas')
canvas_histogram = document.getElementById('canvas_histogram')
ctx = canvas.getContext('2d')
ctx_histogram = canvas_histogram.getContext('2d')
output = document.getElementById('output')
help = document.getElementById('help')
legend = document.getElementById('legend')
def onTabClicked(event):
unregister_listeners()
switch_to_tab(event.target.id)
register_listeners()
# Initialise all the tabs
for tab, entry in config.items():
scripts = entry['scripts']
for id, filename in scripts.items():
with open(filename, 'r') as f:
code = f.read()
scripts[id] = {
'filename': filename,
'code': code,
}
editor = document.getElementById(tab + '-repl')
editor.textContent = scripts['user']['code']
button = document.getElementById(tab)
button.onclick = onTabClicked
def switch_to_tab(id):
output.innerText = ''
entry = config[id]
if ('has_histogram' in entry) and entry['has_histogram']:
canvas_histogram.style.display = 'inline';
else:
canvas_histogram.style.display = 'none';
texts = entry['texts']
help.innerHTML = texts['help']
legend.innerHTML = texts['legend']
scripts = entry['scripts']
exec(scripts['main']['code'], globals())
exec(scripts['ui']['code'], globals())
if 'common' in scripts:
exec(scripts['common']['code'], globals())
editor = document.getElementById(id + '-repl')
try:
user_code = editor.getPySrc()
except AttributeError:
user_code = editor.textContent
exec(user_code, globals())
reset()
terminal = document.getElementsByClassName('py-terminal-docked')
if terminal.length == 1:
terminal[0].remove()
switch_to_tab('SMC1D-tab')
async def main():
run_buttons = document.getElementsByClassName("py-repl-run-button")
for button in run_buttons:
button.addEventListener('click', create_proxy(lambda evt: reset()))
while True:
# Call the appropriate update function
update()
# Update the rendering
draw_scene(param)
await asyncio.sleep(1E-6)
pyscript.run_until_complete(main())