# Add grid (function) to global namespace

**URL:** https://discourse.processing.org/t/add-grid-function-to-global-namespace/5425
**Category:** Gallery
**Created:** [November 11, 2018, 7:00am UTC](https://discourse.processing.org/t/add-grid-function-to-global-namespace/5425 "2018-11-11T07:00:30Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![nick3499](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nick3499/32/2308_2.png) [@nick3499](https://discourse.processing.org/u/nick3499)
#### Post date: [November 11, 2018, 7:00am UTC](https://discourse.processing.org/t/add-grid-function-to-global-namespace/5425/1 "2018-11-11T07:00:30Z")

</div>

Add [grid](https://github.com/nick3499/p5_intro/blob/master/grid/sketch.js) function to p5.js sketch:

```auto
setup = () => {
  createCanvas(800, 200)
  background(249, 202, 6)
}

draw = () => {
  grid(30, 10, 20) // cols, rows, grid size
}

// x = num of cols; y = num of rows; s = grid size
grid = (x, y, s) => {
  fill(33, 43, 47)
  stroke(249, 202, 6)
  for (let i=0; i<x*s; i=i+s) {
    for (let j=0; j<y*s; j=j+s) {
      rect(i, j, s, s)
    }
  }
}

```

 ![grid-function-p5js](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/02bbb481b7e5842109104c6b56f48ac022a860f8.png)

Since `grid` function was added to the global namespace, its params can be passed in the `draw` function, which is also in the global namespace.
