Processing Sketch: Colour Changing Brush

click somewhere in the box below… =)

(left click and drag to draw line, right click to clear and start again)

int cWidth = 580; // width of canvas
int cHeight = 500; // height of canvas
int circleSize = 5;
int r = 255;
int g = 0;
int b = 0;
int colorChangeSpeed = 2;
int count;
int weight;
boolean w = true;
int maxW = 30;

void setup()
{
  size(cWidth, cHeight);
  smooth();
  background(255);
  frameRate(60);
  weight = 3;
  rectMode(CENTER);
  rect(width/2, height/2, cWidth, cHeight);
}

void draw()
{
  if (mousePressed == true && (mouseButton == LEFT)) {
      if (w == true) {
        weight ++;
        if (weight > maxW) {
          w = false;
        }
      }
      if (w == false) {
        weight --;
        if (weight < 2) {
          w = true;
        }
      }
      strokeWeight(weight);

    if (count % 5 == 0) {
      int randomCircleSize = (int)random(3, 100);
      stroke(r, g, b);
      noFill();
      ellipse(mouseX, mouseY, randomCircleSize, randomCircleSize);
    }
    strokeCap(ROUND);
    line(pmouseX, pmouseY, mouseX, mouseY);
    if (r >= 250 && g <= 1 && b <= 250)
    {
      b = b + colorChangeSpeed;
    }
    else if (r >= 1 && g <= 1 && b >= 250)
    {
      r = r - colorChangeSpeed;
    }
    else if (r <= 1 && g <= 250 && b >= 250)
    {
      g = g + colorChangeSpeed;
    }
    else if (r <= 1 && g >= 250 && b >= 1)
    {
      b = b - colorChangeSpeed;
    }
    else if (r <= 250 && g >= 250 && b <= 1)
    {
      r = r + colorChangeSpeed;
    }
    else if (r >= 250 && g >= 1 && b <= 1)
    {
      g = g - colorChangeSpeed;
    }
    count ++;
  }
  if (mousePressed == true && (mouseButton == RIGHT)) {
    background(255);
  }
}
Share