# Instantiate Particle

**URL:** <https://discourse.processing.org/t/instantiate-particle/4407>\
**Category:** Coding Questions\
**Created:** [October 12, 2018, 11:03pm UTC](https://discourse.processing.org/t/instantiate-particle/4407 "2018-10-12T23:03:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![happyPerson](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@happyPerson](https://discourse.processing.org/u/happyPerson)\
**Post date:** [October 12, 2018, 11:03pm UTC](https://discourse.processing.org/t/instantiate-particle/4407/1 "2018-10-12T23:03:43Z")

</div>

Using ES6 I need to instantiate Particle constructor. Invoking constructor through default export I’m getting an error -\> **p.Particle is not a constructor**

I’ve scaffolded playground – [link](https://stackblitz.com/edit/js-mmjxzw)

```auto
'use strict';
import P5 from 'p5';

const sketch = (p5) => {
    const AMOUNT = 100;
    const p = p5;
    let particles = [];

    p.setup = () => {
        p.createCanvas(p.windowWidth, p.windowHeight);
        p.pixelDensity(1);

        const x = Array(AMOUNT).fill().map((x, index) => new p.Particle(320, 240));

        p.background(51);
    };

    p.draw = () => {
        p.background(p.mouseX, 100, 100);

        particles.forEach((x) => {
            x.update();
            x.show();
        });
    };
};

new P5(sketch);

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 13, 2018, 3:14am UTC](https://discourse.processing.org/t/instantiate-particle/4407/2 "2018-10-13T03:14:11Z")

</div>

> [@happyPerson](#):
>
> `import P5 from 'p5';`

I doubt that p5.js is compatible w/ `import`. Have you checked that out yourself? ❓

> [@happyPerson](#):
>
> `new p.Particle(320, 240)`

- Variable _p_ is an instance of class p5.
- However, in order to access a nested class inside of it, we need to directly use the p5 reference, not 1 of its instances.
- In your sketch above, variable _P5_ is supposed to point to class p5.
- But there’s yet another problem: AFAIK, class p5 doesn’t have any nested class named Particle! 😑

If you wish, you can study this sketch, which uses instance mode w/ multiple classes: 👨‍🎓

[GoSubRoutine.github.io/Ball-in-the-Chamber/instance/](http://GoSubRoutine.github.io/Ball-in-the-Chamber/instance/)

[GitHub.com/GoSubRoutine/Ball-in-the-Chamber/tree/master/instance](http://GitHub.com/GoSubRoutine/Ball-in-the-Chamber/tree/master/instance)

---

<div class="post-metadata">

**Author:** ![happyPerson](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@happyPerson](https://discourse.processing.org/u/happyPerson)\
**Post date:** [October 13, 2018, 1:08pm UTC](https://discourse.processing.org/t/instantiate-particle/4407/3 "2018-10-13T13:08:54Z")

</div>

My bad, class Particle is not from P5
