Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added first version.
Browse files Browse the repository at this point in the history
Dilawar Singh committed Nov 15, 2021
1 parent 38bfbb3 commit 488481b
Showing 2 changed files with 196 additions and 0 deletions.
138 changes: 138 additions & 0 deletions examples/S99_more/maze/maze.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
-0.5 -0.5 -0.5 9.5
-0.5 9.5 9 9.5
9.5 -0.5 9.5 9.5
0 -0.5 9.5 -0.5
0.49999999999999994 -0.5 0.5 0.5
0.5 1.5 -0.5 1.5
-0.5 1.5 0.5 1.5
0.5 2.5 -0.5 2.5
-0.5 2.5 0.5 2.5
0.5 4.5 -0.5 4.5
-0.5 4.5 0.5 4.5
0.49999999999999994 5.5 0.5 6.5
0.5 7.5 -0.5 7.5
-0.5 7.5 0.5 7.5
0.49999999999999994 7.5 0.5 8.5
1.5 -0.5 1.5 0.5
0.5000000000000001 0.5 0.4999999999999999 -0.5
1.5 1.5 0.5 1.5
0.5 1.5 1.5 1.5
1.5 1.5 1.5 2.5
1.5 5.5 0.5 5.5
1.5 6.5 0.5 6.5
1.5 5.5 1.5 6.5
0.5 5.5 1.5 5.5
0.5000000000000001 6.5 0.4999999999999999 5.5
0.5 6.5 1.5 6.5
0.5000000000000001 8.5 0.4999999999999999 7.5
1.5 7.5 1.5 8.5
1.5 0.5 1.5 -0.5
2.5 2.5 1.5 2.5
1.5 2.5 1.5 1.5
2.5 3.5 1.5 3.5
2.5 2.5 2.5 3.5
1.5 2.5 2.5 2.5
1.5 3.5 2.5 3.5
2.5 3.5 2.5 4.5
1.5 6.5 1.5 5.5
1.5 8.5 1.5 7.5
3.5 0.49999999999999994 2.5 0.5000000000000001
3.5 1.5 2.5 1.5
3.5 0.5 3.5 1.5
2.5 0.5 3.5 0.5
2.5 1.5 3.5 1.5
3.5 2.5 2.5 2.5
2.5 3.5 2.5 2.5
2.5 2.5 3.5 2.5
3.5 2.5 3.5 3.5
3.5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2.5 7.5 2.5
6.5 3.5 7.5 3.5
7.5 6.5 7.5 7.5
7.5 7.5 7.5 8.5
8.5 -0.5 8.5 0.5
7.5 0.5 7.5 -0.5
8.5 0.49999999999999994 7.5 0.5000000000000001
7.5 1.5 7.5 0.5
7.5 0.5 8.5 0.5
8.5 2.5 8.5 3.5
8.5 4.5 7.5 4.5
8.5 3.5 8.5 4.5
7.5 4.5 8.5 4.5
7.5 7.5 7.5 6.5
8.5 8.5 7.5 8.5
7.5 8.5 7.5 7.5
7.5 8.5 8.5 8.5
8.5 8.5 8.5 9.5
8.5 0.5 8.5 -0.5
9.5 1.5 8.5 1.5
8.5 1.5 9.5 1.5
9.5 2.5 8.5 2.5
8.5 3.5 8.5 2.5
8.5 2.5 9.5 2.5
8.5 4.5 8.5 3.5
9.5 5.5 8.5 5.5
8.5 5.5 9.5 5.5
8.5 9.5 8.5 8.5
58 changes: 58 additions & 0 deletions examples/S99_more/maze/maze_solve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# Solve a maze using brute force
#

__author__ = "Dilawar Singh"
__email__ = "dilawar.s.rajput@gmail.com"

import math
import smoldyn
from pathlib import Path


def get_axis(line):
x0, y0, x1, y1 = line
theta = math.atan2(y1 - y0, x1 - x0)
if math.isclose(theta, 0.0) or math.isclose(theta, math.pi):
return "+y"
return "+x"


def add_maze(s, mazefile):
panels = []
offset = 1.5
scale = 10
with open(mazefile, "r") as f:
for i, l in enumerate(f.read().strip().split("\n")):
line = [scale * (offset + float(x)) for x in l.split()]
axis = get_axis(line)
x0, y0, x1, y1 = line
r = s.addRectangle(
corner=[x0, y0],
dimensions=[max((x1 - x0), (y1 - y0))],
axis=axis,
name=f"r{i}",
)
panels.append(r)
# close the entry notch
r = s.addRectangle(
corner=[10, 10],
dimensions=[30],
axis="+y",
name=f"rrr",
)
panels.append(r)
return panels


s = smoldyn.Simulation(low=[0, 0], high=[120, 120])
A = s.addSpecies("A", difc=2, color="blue")
A.addToSolution(1000, pos=[15, 15])

panels = add_maze(s, Path(__file__).parent / "maze.txt")
maze = s.addSurface("maze", panels=panels)
maze.setAction("front", [A], "reflect")
maze.setAction("back", [A], "reflect")
maze.setStyle("both", thickness=1, color='red')
s.addGraphics("opengl", iter=50)
s.run(3000, dt=0.01)

0 comments on commit 488481b

Please sign in to comment.