Skip to content

Commit

Permalink
Added Human interactions to animation plot
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Ambo committed Oct 15, 2024
1 parent 2b2e1d7 commit 35a4fe3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Binary file modified Polerisation_ABM/__pycache__/model_entities.cpython-311.pyc
Binary file not shown.
23 changes: 17 additions & 6 deletions Polerisation_ABM/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#import sys
#sys.path.append('C:/Users/44771/Documents/Level4Project/Polerisation_ABM/model.py')
from model_entities import Environment, Human
random.seed(0)

#random.seed(123567)
population = 150
Human.opinion_threshold = 0.5

env = Environment(100)
env.create_environment()
Expand All @@ -19,20 +21,29 @@
human = Human(x, y, op)
humans.append(human)


fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_axis_off()
ax.set_xlim(0, 100)
ax.set_ylim(0, 100)


scatter = ax.scatter([human.pos[0] for human in humans], [human.pos[1] for human in humans], c=[human.opinion for human in humans], cmap='bwr')
scatter = ax.scatter([human.pos[0] for human in humans], [human.pos[1] for human in humans], c=[human.opinion for human in humans], cmap='bwr',s=[10*np.exp(human.scepticism*2) for human in humans])

def update_frame(frame):
for human in humans:
human.move(human.pos[0], human.pos[1], env)

random_index = random.randint(0,population)
random_human = humans[random_index - 1]
random_human.interact(random.choice(humans))

scatter.set_offsets([(human.pos[0], human.pos[1]) for human in humans])
scatter.set_array([human.opinion for human in humans])

return scatter
ani = animation.FuncAnimation(fig, update_frame, frames=100, interval=500, repeat=True)
plt.show(block=True)

ani = animation.FuncAnimation(fig, update_frame, frames=1000, interval=100, repeat=True)
plt.show(block=True)

from IPython.display import HTML
HTML(ani.to_jshtml())

0 comments on commit 35a4fe3

Please sign in to comment.