Commit
·
81a0426
1
Parent(s):
3251628
Adding user-controlled step size
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import io
|
|
| 5 |
import numpy as np
|
| 6 |
|
| 7 |
|
| 8 |
-
def generate_random_walk(iters):
|
| 9 |
iters = int(iters)
|
| 10 |
directions = ['east', 'north', 'west', 'south']
|
| 11 |
start_point = [0, 0]
|
|
@@ -19,13 +19,13 @@ def generate_random_walk(iters):
|
|
| 19 |
def step_determination():
|
| 20 |
direction = random.choice(directions)
|
| 21 |
if direction == 'east':
|
| 22 |
-
return [1, 0]
|
| 23 |
elif direction == 'west':
|
| 24 |
-
return [-1, 0]
|
| 25 |
elif direction == 'north':
|
| 26 |
-
return [0, 1]
|
| 27 |
elif direction == 'south':
|
| 28 |
-
return [0, -1]
|
| 29 |
|
| 30 |
coordinate_list = [start_point]
|
| 31 |
|
|
@@ -65,6 +65,8 @@ def generate_random_walk(iters):
|
|
| 65 |
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
| 66 |
return image_array
|
| 67 |
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
iface = gr.Interface(fn=generate_random_walk, inputs=
|
| 70 |
iface.launch()
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
|
| 7 |
|
| 8 |
+
def generate_random_walk(iters, step_size = 1):
|
| 9 |
iters = int(iters)
|
| 10 |
directions = ['east', 'north', 'west', 'south']
|
| 11 |
start_point = [0, 0]
|
|
|
|
| 19 |
def step_determination():
|
| 20 |
direction = random.choice(directions)
|
| 21 |
if direction == 'east':
|
| 22 |
+
return [1*step_size, 0]
|
| 23 |
elif direction == 'west':
|
| 24 |
+
return [-1*step_size, 0]
|
| 25 |
elif direction == 'north':
|
| 26 |
+
return [0, 1*step_size]
|
| 27 |
elif direction == 'south':
|
| 28 |
+
return [0, -1*step_size]
|
| 29 |
|
| 30 |
coordinate_list = [start_point]
|
| 31 |
|
|
|
|
| 65 |
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
| 66 |
return image_array
|
| 67 |
|
| 68 |
+
iters = gr.inputs.Number(label="How many random steps?")
|
| 69 |
+
step_size = gr.inputs.Number(label="step size, defaults to 1")
|
| 70 |
|
| 71 |
+
iface = gr.Interface(fn=generate_random_walk, inputs=[iters, step_size], outputs="image", title="2-D Random Walk Plot", description="Steps along NEWS directions only")
|
| 72 |
iface.launch()
|