# When can you use cos and sin outside of setup or draw

**URL:** <https://discourse.processing.org/t/when-can-you-use-cos-and-sin-outside-of-setup-or-draw/11805>\
**Category:** Beginners\
**Created:** [June 3, 2019, 5:29pm UTC](https://discourse.processing.org/t/when-can-you-use-cos-and-sin-outside-of-setup-or-draw/11805 "2019-06-03T17:29:07Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [June 3, 2019, 6:19pm UTC](https://discourse.processing.org/t/when-can-you-use-cos-and-sin-outside-of-setup-or-draw/11805/4 "2019-06-03T18:19:02Z")

</div>

> [@paulgoux](#):
>
> I’m currently using p5.js,

I’ve changed your post to the p5.js forum category then. 😑

p5js is a diff. flavor beast. 🐻

Indeed, none of its API is available until either it finds out that **setup()** or **draw()** is in the global context (_window_) or we manually instantiate class p5: `new p5;` 🤠

```auto
new p5; // prematurely instantiate class p5. ;-)

const SQRT_3 = sqrt(3); // we can access p5's sqrt() method outside functions!

function setup() {
	print(SQRT_3);
}

```

For **cos()** & **sin()** and similar, we can always directly rely on the class Math: 💡

> **[Math - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math)**
>
> The Math namespace object contains static properties and methods for mathematical constants and functions.

```auto
const SQRT_3 = Math.sqrt(3); // Directly accessing JS' Math method sqrt().

function setup() {
	print(SQRT_3);
}

```

---

_[View the full topic](https://discourse.processing.org/t/when-can-you-use-cos-and-sin-outside-of-setup-or-draw/11805)._
