Gleb Svechnikov
Gleb Svechnikov

Reputation: 373

How to draw in polar coordinates with P5.js?

There is a function angleMode(mode); in P5 documentation that sets mode either RADIANS or DEGREES but I can't figure out how to use it or how to draw in polar coordinates in p5.js. Does anybody know how to do it with p5.js?

Upvotes: 0

Views: 2063

Answers (2)

Blanc
Blanc

Reputation: 175

angleMode() changes wheter p5.js interprets your angle values as radians and degrees. It has no impact on the way drawing is done.

You can just use trigonometric functions to translate between polar and cartesian.

var x = r * cos(angle)
var y = r * sin(angle)

point(x, y);

If you need more information, you can see this example in p5.js documentation: https://p5js.org/examples/math-polartocartesian.html

The coding train also has a video tutorial on this: https://www.youtube.com/watch?v=N633bLi_YCw

Upvotes: 2

Ruben Kazumov
Ruben Kazumov

Reputation: 3872

RADIANS and DEGREES are the constants like 0 and 1. Therefore:

angleMode(DEGREES);// sets the mode

Upvotes: 0

Related Questions