Color is not defined

edited October 2015 in p5.js

I'm trying to implement color into a sketch, and keep getting the error message "Uncaught ReferenceError: color is not defined". I tried a simple sketch from the reference page and still got the same error:

var c = color(255, 204, 0);

 function setup() {    
    createCanvas (800, 800);    
    noStroke();
}

function draw() {
    fill(c);
    ellipse(mouseX, mouseY, 80, 80);
 }

I'm running the p5 editor on Windows 10, if that helps at all

Tagged:

Answers

  • Answer ✓

    p5 functions aren't defined outside of setup and draw. it's best to declare variables outside setup, and assign them inside setup.

    var c;
    
    function setup() {
      createCanvas(800, 800);
      c = color(255, 204, 0);
      ...
    }
    
  • Fantastic, thanks Lauren!

Sign In or Register to comment.