# Pedestrian behavior simulation

**URL:** <https://discourse.processing.org/t/pedestrian-behavior-simulation/25588>\
**Category:** Processing.py\
**Created:** [November 21, 2020, 12:28pm UTC](https://discourse.processing.org/t/pedestrian-behavior-simulation/25588 "2020-11-21T12:28:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![emyou](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@emyou](https://discourse.processing.org/u/emyou)\
**Post date:** [November 21, 2020, 12:28pm UTC](https://discourse.processing.org/t/pedestrian-behavior-simulation/25588/1 "2020-11-21T12:28:54Z")

</div>

Hi, I have a project to simulate the pedestrian behavior based on the social force model. I have started with creating the pedestrian class. the pedestrian behavior is controlled by certain forces, accelerate toward target, respect others space, avoid obstacle, and attraction forces.  
I started with creating the pedestrian class. this is my first time to use processing platform and I am a little bit lost! I need some guidance.  
any hints or guidance will be highly appreciated.  
when I use the python mode, it’s a little bit challenging because the libraries like numpy and pandas are not available, is there a way to overcome this challenge?

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [November 21, 2020, 5:48pm UTC](https://discourse.processing.org/t/pedestrian-behavior-simulation/25588/2 "2020-11-21T17:48:46Z")

</div>

I cannot help in regards to numpy or pandas for the Python mode. I would suggest you review the Processing documentation for Python mode and become aware of the limitations before you engage in this project using Processing in python mode.

If Pandas/numpy is essential for your project, I suggest you use Python visual libraries like vpython. I am not sure what is the current state of that project ad you will need to check with the Python community.

If you want to use Processing in Java mode, I suggest you post a minimum amount of code showing your current issue. In Processing, I have used OOP for simulating distal force interactions, similar to what you have done here. I suggest you explore the examples [here](https://processing.org/examples/) to explore core concepts, specially [this](https://processing.org/examples/bouncybubbles.html) one with class definitions and inter-particle interaction.

Kf

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [November 21, 2020, 8:14pm UTC](https://discourse.processing.org/t/pedestrian-behavior-simulation/25588/3 "2020-11-21T20:14:18Z")

</div>

Welcome @emyou

Here are a couple of (Python) options you might explore:

- you can look at using some Java alternative (in Python mode) for the libraries you need, like [ND4J](https://deeplearning4j.konduit.ai/nd4j/overview)
- or some _pure_ Python libraries (with no C bindings), like [tinynumpy](https://github.com/wadetb/tinynumpy)

Alternatively, you could use another Python variant of Processing, like [p5py](https://p5.readthedocs.io/en/latest/) (that will work with any Python library).

Of course, there’s [PVector](https://py.processing.org/reference/PVector.html) for working with vectors (if you aren’t using it already).

---

<div class="post-metadata">

**Author:** ![emyou](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@emyou](https://discourse.processing.org/u/emyou)\
**Post date:** [November 22, 2020, 10:51pm UTC](https://discourse.processing.org/t/pedestrian-behavior-simulation/25588/4 "2020-11-22T22:51:30Z")

</div>

Thank you for your response.  
I am trying to cut the project into smaller pieces.  
1-I just want to see a particle on my screen.  
2-create an array of particles  
3-create a path that these particles can follow.

I started with creating a mover class. using this code:

class Mover(object):

```
def __init__ (self, m, x, y):
    # Mass is tied to size.
    self.mass = m
    self.location = PVector(x, y)
    self.velocity = PVector(0, 0)
    self.acceleration = PVector(0, 0)

# Newton's 2nd law: F = M * A
# or A = F / M
def applyForce(self, force):
    # Divide by mass.
    f = PVector.div(force, self.mass)
    # Accumulate all forces in acceleration.
    self.acceleration.add(f)

def update(self):
    # Velocity changes according to acceleration.
    self.velocity.add(self.acceleration)
    # Location changes by velocity.
    self.location.add(self.velocity)
    # We must clear acceleration each frame.
    self.acceleration.mult(0)

# Draw Mover.
def display(self):
    stroke(255)
    strokeWeight(2)
    fill(255, 200)
    ellipse(self.location.x, self.location.y,
            self.mass * 16, self.mass * 16)

```

from mover import Mover

movers = [None] \* 10

def setup():  
size(640, 360)

def draw():  
background(0)  
# Draw water.

```
mover.update()
mover.display()
mover.checkEdges()
fill(255)

```

I got this error:  
global name mover is not defined

what’s wrong with this code?

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [November 22, 2020, 11:21pm UTC](https://discourse.processing.org/t/pedestrian-behavior-simulation/25588/5 "2020-11-22T23:21:13Z")

</div>

There are a few things wrong here. This revised and commented code should help clarify what’s wrong:

```auto
from mover import Mover

# you must populate the list/array somehow, for example:
movers = [
  Mover(10, 50, 200),
  Mover(5, 100, 150),
  Mover(1, 200, 150)
]

# this force is applied to the movers
wind = PVector(0.1, -0.05)

def setup():
    size(640, 360)

def draw():
    background(0)
    fill(255)
    
    # loop through the movers to update and display each one
    for mover in movers:
        mover.applyForce(wind)
        mover.update()
        mover.display()

```

Do you have any plan for how you might approach the “create a path that these particles can follow” part?

---

<div class="post-metadata">

**Author:** ![emyou](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@emyou](https://discourse.processing.org/u/emyou)\
**Post date:** [November 22, 2020, 11:46pm UTC](https://discourse.processing.org/t/pedestrian-behavior-simulation/25588/6 "2020-11-22T23:46:43Z")

</div>

I am still searching for a plan for the path code.  
This is my first time with processing, things are very new to me.  
if you have any insight or hint, I will be so grateful if you share it.  
Thanks
