Created
November 20, 2018 14:01
-
-
Save oeway/81f4f019512680cf43eee28f0573cf07 to your computer and use it in GitHub Desktop.
This plugin demonstrate the web python mode in ImJoy which allows run python plugin with the browser.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<docs lang="markdown"> | |
Describe your plugin here. | |
</docs> | |
<config lang="json"> | |
{ | |
"name": "WebPython Demo", | |
"mode": "webpython", | |
"version": "0.1.0", | |
"api_version": "0.1.1", | |
"description": "Estimating PI with numpy", | |
"tags": [], | |
"ui": "Estimating PI with numpy", | |
"inputs": null, | |
"outputs": null, | |
"flags": [], | |
"icon": null, | |
"env": null, | |
"requirements": [], | |
"dependencies": [] | |
} | |
</config> | |
<script lang="python"> | |
import numpy as np | |
class ImJoyPlugin(): | |
def setup(self): | |
print('setup in python') | |
def run(self, my): | |
print('estimating pi using numpy...') | |
points = (np.random.rand(1000, 2) * 2.0) - 1.0 | |
x = points[:, 0] | |
y = points[:, 1] | |
inside_circle = (x*x + y*y) < 1.0 | |
pi = (float(np.sum(inside_circle)) / float(len(points))) * 4.0 | |
api.alert(f'pi={pi}') | |
api.export(ImJoyPlugin()) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment