Console throwing "cos is not defined", "sin is not defined" when i try to use sin, cos functions.

var r = 160; var theta = 0; var xvals = []; var yvals = []; while (theta <= 360) {var x = rcos(theta); var y = rsin(theta); xvals.push(x); yvals.push(y); theta += 4;}

Any idea what's up?

Answers

  • edited September 2015

    http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text

    It's hard to read since your post is messed up! /:)
    But I can't see any * multiplication operator between variable r and those aforementioned functions? :-&

  • It's taking the multiply signs as markup which is why some of the text is in italics

    var r = 160;
    var theta = 0;
    var xvals = [];
    var yvals = [];
    while (theta <= 360) {
      var x = r*cos(theta); 
      var y = r*sin(theta); 
      xvals.push(x); 
      yvals.push(y); 
      theta += 4;
    }
    
  • Are you using instance mode? Then you need to reference p5: p5.cos

    Though you could also directly reference the JS method with: Math.cos

Sign In or Register to comment.