# Code organization

**URL:** https://discourse.processing.org/t/code-organization/10643
**Category:** Coding Questions
**Created:** [April 25, 2019, 9:04pm UTC](https://discourse.processing.org/t/code-organization/10643 "2019-04-25T21:04:24Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![jarlook](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jarlook](https://discourse.processing.org/u/jarlook)
#### Post date: [April 25, 2019, 9:04pm UTC](https://discourse.processing.org/t/code-organization/10643/1 "2019-04-25T21:04:24Z")

</div>

I am about to convert a lengthy Processing sketch to p5.js. Currently the code is defined in several files (a common driver, some objects/classes, etc) and I’d like to keep them separate. This was doable with the Processing IDE. Essentially I’m looking for something like the “c” language’s #include.

Any suggestions?

Thanks.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 26, 2019, 1:13am UTC](https://discourse.processing.org/t/code-organization/10643/2 "2019-04-26T01:13:31Z")

</div>

you mean like  
[https://editor.p5js.org/kll/sketches/bNjtWjB\_P](https://editor.p5js.org/kll/sketches/bNjtWjB_P)

---

<div class="post-metadata">

### Author: ![jarlook](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jarlook](https://discourse.processing.org/u/jarlook)
#### Post date: [April 26, 2019, 2:28am UTC](https://discourse.processing.org/t/code-organization/10643/3 "2019-04-26T02:28:31Z")

</div>

Yes, that editor is much like the Processing IDE. However, I don’t want to use it if possible. I would prefer to use my editor of choice and maintain my files locally. Admittedly I never signed up – I was assuming that the files are maintained on the p5 site, again, not my preference. Also, I will still need the feature I am seeking, something like #include, if I want to execute the javascript outside of the p5 editor.

---

<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: [April 26, 2019, 2:29am UTC](https://discourse.processing.org/t/code-organization/10643/4 "2019-04-26T02:29:47Z")

</div>

> [@jarlook](#):
>
> I am about to convert a lengthy Processing sketch to p5.js.

1st you have to decide if it’s gonna be global or instance mode approach: 🌐

- [p5.js overview · processing/p5.js Wiki · GitHub](http://GitHub.com/processing/p5.js/wiki/p5.js-overview#instantiation--namespace)

You can see both approaches in the repo below: 😀

> **[GitHub - GoSubRoutine/Ball-in-the-Chamber: JS Native Modules coded in TS...](https://github.com/GoSubRoutine/Ball-in-the-Chamber)**
>
> JS Native Modules coded in TS & CS. Contribute to GoSubRoutine/Ball-in-the-Chamber development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 26, 2019, 2:53am UTC](https://discourse.processing.org/t/code-organization/10643/5 "2019-04-26T02:53:29Z")

</div>

did you even look at the code? or download it?

you not need to register/login for this, but well you should know how to click on the little arrows to find file/path …

it does not matter what editor or environment you use  
i make that example for you to show one way how to do the multi file thing  
( comparable with the multi \*.pde in processing IDE JAVA mode. )  
and commented all entries!

---

<div class="post-metadata">

### Author: ![jarlook](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jarlook](https://discourse.processing.org/u/jarlook)
#### Post date: [April 26, 2019, 3:16am UTC](https://discourse.processing.org/t/code-organization/10643/6 "2019-04-26T03:16:53Z")

</div>

Sorry kll, I clicked your link to the editor but I did not see the example you cite. And if, by the little arrows, you are referring to the p5 menu bar items (e.g., File, Edit), I see nothing that would lead me to the example.

---

<div class="post-metadata">

### Author: ![jarlook](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jarlook](https://discourse.processing.org/u/jarlook)
#### Post date: [April 26, 2019, 3:18am UTC](https://discourse.processing.org/t/code-organization/10643/7 "2019-04-26T03:18:46Z")

</div>

Thanks for the citation GoToLoop. I’ll go take a look.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 26, 2019, 3:20am UTC](https://discourse.processing.org/t/code-organization/10643/8 "2019-04-26T03:20:13Z")

</div>

yes that “\>” little arrow is much too small!

ok, i give up,  
i print it here:

* * *

sketch.js

```auto
function setup() {
  createCanvas(400, 400);
  rectMode(CENTER);
}

function draw() {
  background(200,200,0);
  translate(width/2,height/2);
  my_rectangle(); // see file my_function.js / see index.html
}

```

my\_function.js

```auto
/* 
 file: my_function.js
 called in index.html
 used in sketch.js
*/

function my_rectangle() {
  push();
  fill(0, 200, 0);
  stroke(0, 0, 200);
  strokeWeight(20);
  rect(0, 0, 100, 100);
  pop();
}

```

index.html

```auto
<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/addons/p5.dom.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/addons/p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />

  </head>
  <body>
    <script src="sketch.js"></script>
    <script src="my_function.js"></script> <!--- add --->
  </body>
</html>

```

---

<div class="post-metadata">

### Author: ![jarlook](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jarlook](https://discourse.processing.org/u/jarlook)
#### Post date: [April 26, 2019, 3:24am UTC](https://discourse.processing.org/t/code-organization/10643/9 "2019-04-26T03:24:02Z")

</div>

Aha, kll, I did find the contents of the Project Folder. True, I didn’t notice that particular arrow.

---

<div class="post-metadata">

### Author: ![jarlook](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jarlook](https://discourse.processing.org/u/jarlook)
#### Post date: [April 26, 2019, 3:26am UTC](https://discourse.processing.org/t/code-organization/10643/10 "2019-04-26T03:26:53Z")

</div>

Thanks kll for your perseverance.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 26, 2019, 3:27am UTC](https://discourse.processing.org/t/code-organization/10643/11 "2019-04-26T03:27:37Z")

</div>

as you not use the online editor it does not matter,

still i recommend that for communication/questions about p5.js  
you register and use it to ask for help here but play together with your MVCE code online.

so now you see the example code / here above / and online /  
did you get the idea?  
instead #include use index.html script

---

<div class="post-metadata">

### Author: ![jarlook](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jarlook](https://discourse.processing.org/u/jarlook)
#### Post date: [April 26, 2019, 4:30am UTC](https://discourse.processing.org/t/code-organization/10643/12 "2019-04-26T04:30:46Z")

</div>

Yes, once I saw the contents of your Project Folder, everything became clear.

Again, thanks.
