q5play
    Preparing search index...

    Function color

    • 🎨 Creates a new Color object, which is primarily useful for storing a color that your sketch will reuse or modify later.

      With the default color mode, RGB, colors have r/red, g/green, b/blue, and a/alpha components.

      The fill, stroke, and background functions accept the same wide range of color representations as this function.

      The default color format is "float", so set color components to values between 0 and 1.

      Here are some examples of valid use:

      • color(1) (grayscale)
      • color(1, 0.8) (grayscale, alpha)
      • color(1, 0, 0) (r, g, b)
      • color(1, 0, 0, 0.1) (r, g, b, a)
      • color('red') (colorName)
      • color('#ff0000') (hexColor)
      • color([1, 0, 0]) (colorComponents)

      Parameters

      • c0: string | number | number[] | Color

        color or first color component

      • Optionalc1: number

        second color component

      • Optionalc2: number

        third color component

      • Optionalc3: number

        fourth color component (alpha)

      Returns Color

      a new Color object

      await Canvas(200);
      rect(-100, -100, 100, 200);

      // ( r, g, b, a)
      let bottle = color(0.35, 0.39, 1, 0.4);
      fill(bottle);
      stroke(bottle);
      strokeWeight(30);
      circle(0, 0, 155);
      await Canvas(200);
      // (gray, alpha)
      let c = color(0.8, 0.2);

      q5.draw = function () {
      background(c);
      circle(mouseX, mouseY, 50);
      c.g = (c.g + 0.005) % 1;
      };
      await Canvas(200);

      // (r, g, b, a)
      let c = color(0, 1, 1, 0.2);

      q5.draw = function () {
      fill(c);
      circle(mouseX, mouseY, 50);
      };