Urgent Code help (Draw Program)

//Minim Library
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;


//Global Variables  <------------------------------------------------------------->

PVector v1;
int PenPrevX,PenPrevY;

//Spray Button
final int maxIterations = 500000;  // that's how fast spraying happens

// for image saving
int counter=0;

//Line Art
PImage[] imageList = new PImage[10];
int indexImage=0;
int i;
//Quit & Undo & Redo & Reset Button Variables
float quitButtonX, quitButtonY, quitButtonWidth, quitButtonHeight;
color buttonColour, resetWhite=#FFFFFF;
color circleRed = #FF0303;
float reset = #FFFFFF;
float ResetX, ResetY, ResetWidth, ResetHeight;
float undoX, undoY, undoWidth, undoHeight;
float redoX, redoY, redoWidth, redoHeight;
boolean controlDown = false;
boolean shiftDown = false;

//Canvas Variables
Boolean draw=true; // 
int thick = 5; //initial thickness
float drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight; ///ßßß?????

float drawingDiameter;

// Background Song
float PauseButtonX1, PauseButtonY1, PauseButtonDiameter;
int loopIntNum = 1;

String[] namesOfCommands = {

  "Rectangle", 
  "Pencil",
  "Triangle", 
  "Circle", 
  "Spray", 
  "Fill", 
  "Caligraphy", 
  "Save", 

};
CellForCommandButton[] buttons = new CellForCommandButton[namesOfCommands.length];

//Global Variables 

FloodFill1 myFloodFill;
AudioPlayer song1;
Minim minim;
Undo undo;
ColorPicker cp;

int mode = 0; // NONE

void setup() {
  
    
  for (int i=0; i<9; i++) {
    imageList[i] = loadImage("img00 ("+i+").jpg" ) ;
    imageList[i].resize(80, 0);
  }
  
  population();
  textSetup();
  fullScreen();
  background(#A59696);
  frameRate ( 100 );
  //noFill();

  // command buttons !!!!!!!!!!!!!!
  for (int j=0; j<buttons.length; j++) {
    // j is y here 
    buttons[j] = new CellForCommandButton(270+ j*110, 44, 
      100, 40, 
      namesOfCommands[j] );
  }//for 

  // Sound File

  minim = new Minim(this);
  song1 = minim.loadFile("Sample.mp3");
  song1.play();

  //COLOR WHEEL SIZE
  cp = new ColorPicker( 10, 10, 225, 225, 255 );
  //UNDO
  undo = new Undo(10);

  //Canvas
  rect(drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight);

  //ClearCanvas
 
}
// DRAW < ================================================ >

  void draw() {
    
    menu();
    
    fill(0); 
  text("Click mouse to show an Image", 
    13, 14);
    
if ( draw == true &&
    mousePressed && 
    mouseX>drawingSurfaceX  &&
    mouseX<drawingSurfaceX+drawingSurfaceWidth  &&
    mouseY>drawingSurfaceY &&
    mouseY<drawingSurfaceY+drawingSurfaceHeight) {

      
    switch (mode) {
    case 0:
      println("here");
      strokeWeight(thick);
      stroke(cp.penTool);
      line(mouseX, mouseY, pmouseX, pmouseY);
      break; 

    case 1:
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(mouseX, mouseY, 100, 100);
      break;

    case 2:
      stroke(0); 
      fill(255);
      strokeWeight(1);
      triangle(mouseX, mouseY, 
        mouseX+100, mouseY-100, 
        mouseX+200, mouseY+200);
      break;

    case 3:
      stroke(0); 
      fill(255);
      strokeWeight(1);
      ellipse(mouseX, mouseY, 
        100, 100);
      break;

    case 4:
      if (mousePressed) {
      loadPixels();
      myFloodFill = new FloodFill1();
      myFloodFill.DoFill(mouseX, mouseY, color(cp.penTool));
      updatePixels(); }
      break;

    case 5:
      stroke(cp.penTool); 
      for (int i= 0; i < random(39); i++) {
        point (mouseX+random(-23, 23), 
          mouseY+random(-23, 23));
      }
      break;
      
      case 6:
      
      v1=new PVector();
    if(mousePressed){
       // brush(pmouseX,pmouseY,mouseX,mouseY);
        strokeWeight(thick);
        stroke(cp.penTool);
        smooth();
      for(int i=0;i<60;i++){
      line(pmouseX+5,pmouseY-5,mouseX-5,mouseY+5);
      line(pmouseX+4,pmouseY-4,mouseX-4,mouseY+4);
      line(pmouseX+3,pmouseY-3,mouseX-3,mouseY+3);
      line(pmouseX+2,pmouseY-2,mouseX-2,mouseY+2);
      line(pmouseX+1,pmouseY-1,mouseX-1,mouseY+1);
      line(pmouseX,pmouseY,mouseX,mouseY);
      line(pmouseX-1,pmouseY+1,mouseX+1,mouseY-1);
      line(pmouseX-2,pmouseY+2,mouseX+2,mouseY-2);
      line(pmouseX-3,pmouseY+3,mouseX+3,mouseY-3);
      line(pmouseX+4,pmouseY-4,mouseX-4,mouseY+4);
      line(pmouseX+5,pmouseY-5,mouseX-5,mouseY+5);
      //brush(pmouseX,pmouseY,PenPrevX,PenPrevY);
      }
    }
    }//switch
  }//if

      strokeWeight(1);
  if ( mouseX>quitButtonX && mouseX<quitButtonX+quitButtonWidth && mouseY>quitButtonY && mouseY<quitButtonY+quitButtonHeight ) { 
    buttonColour = circleRed;
  } else { 
    buttonColour = resetWhite;
  } 
  fill(buttonColour);
  rect(quitButtonX, quitButtonY, quitButtonWidth, quitButtonHeight);
  textDraw();
  fill(0);

  cp.render();

  // command buttons !!!!!!!!!!!!!!
  for (CellForCommandButton currentButton : buttons) {
    currentButton.display();
  }
}

 void menu(){ //interface for the Left
//color & thick display
  stroke(cp.penTool);
  strokeWeight(thick);
  line(90,450,90,650); 
//buttons
  stroke(10);
  strokeWeight(3.7); 
  fill(255);
  rect(25, 355, 60, 60);//plus button
  rect(95, 355, 60, 60);//minus button
  rect(25, 800, 135, 60);//reset button
  rect(25, 700, 135, 60); //eraser button
//text on the button
  fill(0);
  text("Line Art",87,730); 
  text("RESET",87,833); 
  noStroke(); 
  rect(50,360,10,50);//symbol increase thickness
  rect(30,380,50,10);//symbol increase thickness
  rect(100,380,50,10);//symbol decrease thickness
 }

// Mouse Pressed  < ================================================ >


void mousePressed() {
  
       if (indexImage<imageList.length-1)
    image( imageList[indexImage], mouseX, mouseY);
  indexImage++;
  println(indexImage);

  
 if ( mouseX>drawingSurfaceX  &&
    mouseX<drawingSurfaceX+drawingSurfaceWidth  &&
    mouseY>drawingSurfaceY && 
    mouseY<drawingSurfaceY+drawingSurfaceHeight) {
    println("drawing surface");
    //if (draw == false) {
    draw = true;
    //} else {
    //  draw = false;
    }
    if (mousePressed && pmouseX>25 && pmouseX<85 && pmouseY>355 && pmouseY<415){
    thick = constrain(thick+1,5,60); //increase the thickness when click the "plus" button
    }else if (mousePressed && pmouseX>95 && pmouseX<155 && pmouseY>355 && pmouseY<415){
    thick = constrain(thick-1,5,60);//decrease the thickness when click the "minus" button
    }
    //Line Art
    
    
  // Press to Exit
  if ( mouseX>quitButtonX &&
    mouseX<quitButtonX+quitButtonWidth &&
    mouseY>quitButtonY &&
    mouseY<quitButtonY+quitButtonHeight )
    exit();

  // command buttons !!!!!!!!!!!!!!
  // Check mouseX/mouseY against button position/size
  String foundCMD="NONE"; 
  for (CellForCommandButton currentButton : buttons) {
    foundCMD = currentButton.checkMouseOver();  
    if (!foundCMD.equals("NONE") ) {
      break;
    }//if
  }//for

  // if found a command 
  if  (!foundCMD.equals("NONE") ) {
    println(foundCMD);

    // eval cmd 
    switch(foundCMD) {

    case "Save":
      //// Save image here 
      String fileName = "savedImage-" + nf(counter, 3) + ".png";
      println("saving "+fileName); 
      save(fileName);
      counter++;
      break;

    case "Pencil":
      mode = 0;
      break;

    case "Rectangle":
      mode = 1; 
      break; 

    case "Triangle":
      mode = 2; 
      break; 

    case "Circle":
      mode = 3; 
      break; 

    case "Fill":
      mode=4; 
      break; 

    case "Spray":
      // 
      mode = 5; 
      break; 

    case "caligraphy":
    //
    mode = 6;
      break; 
      //
    }//switch
  }

  if (mousePressed && pmouseX>25 && pmouseX<160 && pmouseY>800 && pmouseY<860){
    fill(255);
    rect(drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight); }

}
// Mouse Released  < ================================================ >
void mouseReleased() {
  // Save each line we draw to our stack of UNDOs
  undo.takeSnap();
}
//  KeyPressed  < ================================================ >

void keyPressed() {

  /*if ( key == 'a' || key == 'A' ) {
    // shuffle 
    img=shuffle( img );
  }*/

  //Music control Buttons

  if ( key == ' ' ) { // ??????
    // Press Space to PAUSE & PLAY
    println("[space]");
    if ( song1.isPlaying() ) {
      song1.pause();
    } else if ( song1.position() == song1.length() ) {
      song1.rewind();   
      song1.play();
    } else {
      song1.play();
      //Play
    }
  }
  //
  if ( key == 's' || key == 'S' ) {
    if ( song1.isPlaying() ) {
      song1.pause();
      song1.rewind();
    } else if ( song1.position() == song1.length() ) {
      song1.rewind();
    } else {
      song1.rewind();
    }
  }

  if ( key == 'f' || key == 'f' ) song1.skip(1000);
  if ( key == 'r' || key == 'R' ) song1.skip(-1000);
  if ( key == 'l' || key == 'L' ) song1.loop(loopIntNum);

  //UNDO AND REDO
  if (key == CODED) {
    if (keyCode == CONTROL) 
      controlDown = true;
    if (keyCode == SHIFT)
      shiftDown = true;
    return;
  } 
  // redo(control shift Z) or an undo(control Z)
  if (controlDown) {
    if (keyCode == 'Z') {
      if (shiftDown)
        undo.redo();
      else
        undo.undo();
    }
    return;
  }
  if (key=='s') {
    saveFrame("image####.png");
  }
}//end of keyPressed


// KeyReleased Code  < ================================================ >

void keyreleased() {

  if (key == CODED) {
    if (keyCode == CONTROL) 
      controlDown = false;
    if (keyCode == SHIFT)
      shiftDown = false;
  }
}//end of keyReleased 


// MAIN COLOR WHEEL CODE < ================================================ >

public class ColorPicker 
{
  int x, y, w, h, c;
  PImage cpImage;
  color penTool;

  public ColorPicker ( int x, int y, int w, int h, int c )
  {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.c = c;
    this.penTool = c;

    cpImage = new PImage( w, h );

    init();
  }

  private void init ()
  {
    // draw color.
    int cw = w - 60;
    for ( int i=0; i<cw; i++ ) 
    {
      float nColorPercent = i / (float)cw;
      float rad = (-360 * nColorPercent) * (PI / 180);
      int nR = (int)(cos(rad) * 127 + 128) << 16;
      int nG = (int)(cos(rad + 2 * PI / 3) * 127 + 128) << 8;
      int nB = (int)(Math.cos(rad + 4 * PI / 3) * 127 + 128);
      int nColor = nR | nG | nB;

      setGradient( i, 0, 1, h/2, 0xFFFFFF, nColor );
      setGradient( i, (h/2), 1, h/2, nColor, 0x000000 );
    }

    // draw black/white.
    drawRect( cw, 0, 30, h/2, 0xFFFFFF );
    drawRect( cw, h/2, 30, h/2, 0 );

    // draw grey scale.
    for ( int j=0; j<h; j++ )
    {
      int g = 255 - (int)(j/(float)(h-1) * 255 );
      drawRect( w-30, j, 30, 1, color( g, g, g ) );
    }
  }

  private void setGradient(int x, int y, float w, float h, int c1, int c2 )
  {
    float deltaR = red(c2) - red(c1);
    float deltaG = green(c2) - green(c1);
    float deltaB = blue(c2) - blue(c1);

    for (int j = y; j<(y+h); j++)
    {
      int c = color( red(c1)+(j-y)*(deltaR/h), green(c1)+(j-y)*(deltaG/h), blue(c1)+(j-y)*(deltaB/h) );
      cpImage.set( x, j, c );
    }
  }

  private void drawRect( int rx, int ry, int rw, int rh, int rc )
  {
    for (int i=rx; i<rx+rw; i++) 
    {
      for (int j=ry; j<ry+rh; j++) 
      {
        cpImage.set( i, j, rc );
      }
    }
  }

  public void render ()
  {
    image( cpImage, x, y );
    if ( mousePressed &&
      mouseX >= x && 
      mouseX < x + w &&
      mouseY >= y &&
      mouseY < y + h )
    {
      c = get( mouseX, mouseY );
    }
    fill( c );
    rect( x, y+h+10, 20, 20 );
    penTool = color(c);
  }
}


// Class for UNDO & REDO <---------------------------------------------------->

class Undo {
  // Number ss taken
  int undoSteps=0, redoSteps=0;  
  CircImgCollection images;
  //
  Undo(int levels) {
    images = new CircImgCollection(levels);
  }

  public void takeSnap() {
    undoSteps = min(undoSteps+1, images.amount-1);
    // each time we draw we disable redo
    redoSteps = 0;
    images.next();
    images.capture();
  }
  public void undo() {
    if (undoSteps > 0) {
      undoSteps--;
      redoSteps++;
      images.prev();
      images.show();
    }
  }
  public void redo() {
    if (redoSteps > 0) {
      undoSteps++;
      redoSteps--;
      images.next();
      images.show();
    }
  }
}


class CircImgCollection {
  int amount, current;
  PImage[] img;
  CircImgCollection(int amountOfImages) {
    amount = amountOfImages;

    // Initialize all images as copies of the current display
    img = new PImage[amount];
    for (int i=0; i<amount; i++) {
      img[i] = createImage(width, height, RGB);
      img[i] = get();
    }
  }
  void next() {
    // ????
    if (amount!=0)
      current = (current + 1) % amount;
  }
  void prev() {
    current = (current - 1 + amount) % amount;
  }
  void capture() {
    // ???
    if (img!=null&&img.length>=1)
      img[current] = get();
  }
  void show() {
    image(img[current], 0, 0);
  }
}

// -------------------------------------------------------
void Spraybrush () {

  int width1=30; // that be the width of your brush
  //
  float radx;   // Radius
  float rady;
  float angle1; // angle
  float x;      // result
  float y;
  //
  for (int i=0; i < maxIterations; i++) {
    radx=random(width1);
    rady=random(width1);
    angle1= random(359);
    //
    x=(radx*cos(radians(angle1)))+mouseX;
    y=(radx*sin(radians(angle1)))+mouseY;
    //
    point(x, y);
  }
} // func

void Calligraphybrush(int x1,int y1,int x2,int y2)
{
  strokeWeight(1);
    line(x1+5,y1-5,x1-5,y1+5);
    line(x2+5,y2-5,x2-5,y2+5);
}

// ----------------------------------------------------------

public class FloodFill1
{
  protected int iw; // Image width
  protected int ih; // Image height
  protected color[] imagePixels;
  protected color backColor; // Color found at given position
  protected color fillColor; // Color to apply
  // Stack is almost deprecated and slow (synchronized).
  // I would use Deque but that's Java 1.6, excluding current (mid-2009) Macs...
  protected ArrayList stack = new ArrayList();
  //
  public FloodFill1()
  {
    iw = width;
    ih = height;
    imagePixels = pixels; // Assume loadPixels have been done before
  }
  //
  public FloodFill1(PImage imageToProcess)
  {
    iw = imageToProcess.width;
    ih = imageToProcess.height;
    imagePixels = imageToProcess.pixels; // Assume loadPixels have been done before if sketch image
  }
  //
  public void DoFill(int startX, int startY, color fc)
  {
    // start filling
    fillColor = fc;
    backColor = imagePixels[startX + startY * iw];
    // don't run if fill color is the same as background one
    if (fillColor == backColor)
      return;
    stack.add(new PVector(startX, startY));
    while (stack.size () > 0)
    {
      PVector p = (PVector) stack.remove(stack.size() - 1);
      // Go left
      FillScanLine((int) p.x, (int) p.y, -1);
      // Go right
      FillScanLine((int) p.x + 1, (int) p.y, 1);
    }
  }
  //
  protected void FillScanLine(int x, int y, int dir)
  {
    // compute current index in pixel buffer array
    int idx = x + y * iw;
    boolean inColorRunAbove = false;
    boolean inColorRunBelow = false;
    // fill until boundary in current scanline...
    // checking neighbouring pixel rows
    while (x >= 0 && x < iw && imagePixels[idx] == backColor)
    {
      imagePixels[idx] = fillColor;
      if (y > 0) // Not on top line
      {
        if (imagePixels[idx - iw] == backColor)
        {
          if (!inColorRunAbove)
          {
            // The above pixel needs to be flooded too, we memorize the fact.
            // Only once per run of pixels of back color (hence the inColorRunAbove test)
            stack.add(new PVector(x, y-1));
            inColorRunAbove = true;
          }
        } else // End of color run (or none)
        {
          inColorRunAbove = false;
        }
      }
      if (y < ih - 1) // Not on bottom line
      {
        if (imagePixels[idx + iw] == backColor)
        {
          if (!inColorRunBelow)
          {
            // Idem with pixel below, remember to process there
            stack.add(new PVector(x, y + 1));
            inColorRunBelow = true;
          }
        } else // End of color run (or none)
        {
          inColorRunBelow = false;
        }
      }
      // Continue in given direction
      x += dir;
      idx += dir;
    } //
  } // func
} // class
// ----------------------------------------------------------
class CellForCommandButton {

  // for the Command Buttons !!!!!!!!!

  float x, y, 
    w, h;
  String textCommandButton=""; 

  CellForCommandButton (float tempX, float tempY, 
    float tempW, float tempH, 
    String tempText1) {
    x = tempX;
    y = tempY;
    w = tempW;
    h = tempH;
    textCommandButton = tempText1;
  }

  void display() {
    // rect 
    stroke(0);
    strokeWeight(1);
    fill(111); 
    rect(x, y, w, h);

    //text 
    fill(255);
    textAlign(CENTER, CENTER); 
    text(textCommandButton, 
      x+w/2, y+h/2);
  }

  String checkMouseOver() {
    if (mouseX > x &&
      mouseX < x+w && 
      mouseY > y && 
      mouseY < y+h) {
      return textCommandButton;
    }//if
    return "NONE";
  }//method
  //
}//class
//
// ======================================================

I added the for loop, But it still says could not run the sketch error at line 76 . Thanks

Here is a space sign

In the names of your hard drive is not

I updated that and It still gives me an error at the resize(); line 76 could not run sketch. Thanks

nvm, I got the code to work but the images are all in the corner when I press the line art button, normally we would populate but how would I make the image present as drawn in the photo I uploaded

//Minim Library
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;


//Global Variables  <------------------------------------------------------------->

PVector v1;
int PenPrevX,PenPrevY;

//Spray Button
final int maxIterations = 50000;  // that's how fast spraying happens

// for image saving
int counter=0;

//Line Art
PImage[] imageList = new PImage[9];
int indexImage=0;
int i;
//Quit & Undo & Redo & Reset Button Variables
float quitButtonX, quitButtonY, quitButtonWidth, quitButtonHeight;
color buttonColour, resetWhite=#FFFFFF;
color circleRed = #FF0303;
float reset = #FFFFFF;
float ResetX, ResetY, ResetWidth, ResetHeight;
float undoX, undoY, undoWidth, undoHeight;
float redoX, redoY, redoWidth, redoHeight;
boolean controlDown = false;
boolean shiftDown = false;

//Canvas Variables
Boolean draw=true; // 
int thick = 5; //initial thickness
float drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight; ///ßßß?????

float drawingDiameter;

// Background Song
float PauseButtonX1, PauseButtonY1, PauseButtonDiameter;
int loopIntNum = 1;

String[] namesOfCommands = {

  "Rectangle", 
  "Pencil",
  "Triangle", 
  "Circle", 
  "Spray", 
  "Fill", 
  "Caligraphy", 
  "Save", 

};
CellForCommandButton[] buttons = new CellForCommandButton[namesOfCommands.length];

//Global Variables 

FloodFill1 myFloodFill;
AudioPlayer song1;
Minim minim;
Undo undo;
ColorPicker cp;

int mode = 0; // NONE

void setup() {
  
    //Line Art
 for (int i=0; i<9; i++) {
    imageList[i] = loadImage("img00 ("+i+").jpg" ) ;
    imageList[i].resize(500, 0);
  }
  
  population();
  textSetup();
  fullScreen();
  background(#A59696);
  frameRate ( 100 );
  //noFill();

  // command buttons !!!!!!!!!!!!!!
  for (int j=0; j<buttons.length; j++) {
    // j is y here 
    buttons[j] = new CellForCommandButton(270+ j*110, 44, 
      100, 40, 
      namesOfCommands[j] );
  }//for 

  // Sound File

  minim = new Minim(this);
  song1 = minim.loadFile("Sample.mp3");
  song1.play();

  //COLOR WHEEL SIZE
  cp = new ColorPicker( 10, 10, 225, 225, 255 );
  //UNDO
  undo = new Undo(10);

  //Canvas
  rect(drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight);

  //ClearCanvas
 
}
// DRAW < ================================================ >

  void draw() {
    
    menu();
    
    
if ( draw == true &&
    mousePressed && 
    mouseX>drawingSurfaceX  &&
    mouseX<drawingSurfaceX+drawingSurfaceWidth  &&
    mouseY>drawingSurfaceY &&
    mouseY<drawingSurfaceY+drawingSurfaceHeight) {

      
    switch (mode) {
    case 0:
      println("here");
      strokeWeight(thick);
      stroke(cp.penTool);
      line(mouseX, mouseY, pmouseX, pmouseY);
      break; 

    case 1:
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(mouseX, mouseY, 100, 100);
      break;

    case 2:
      stroke(0); 
      fill(255);
      strokeWeight(1);
      triangle(mouseX, mouseY, 
        mouseX+100, mouseY-100, 
        mouseX+200, mouseY+200);
      break;

    case 3:
      stroke(0); 
      fill(255);
      strokeWeight(1);
      ellipse(mouseX, mouseY, 
        100, 100);
      break;

    case 4:
      if (mousePressed) {
      loadPixels();
      myFloodFill = new FloodFill1();
      myFloodFill.DoFill(mouseX, mouseY, color(cp.penTool));
      updatePixels(); }
      break;

    case 5:
      stroke(cp.penTool); 
      for (int i= 0; i < random(39); i++) {
        point (mouseX+random(-23, 23), 
          mouseY+random(-23, 23));
      }
      break;
      
      case 6:
      
      v1=new PVector();
    if(mousePressed){
        strokeWeight(thick);
        stroke(cp.penTool);
        smooth();
      for(int i=0;i<60;i++){
      line(pmouseX+5,pmouseY-5,mouseX-5,mouseY+5);
      line(pmouseX+4,pmouseY-4,mouseX-4,mouseY+4);
      line(pmouseX+3,pmouseY-3,mouseX-3,mouseY+3);
      line(pmouseX+2,pmouseY-2,mouseX-2,mouseY+2);
      line(pmouseX+1,pmouseY-1,mouseX-1,mouseY+1);
      line(pmouseX,pmouseY,mouseX,mouseY);
      line(pmouseX-1,pmouseY+1,mouseX+1,mouseY-1);
      line(pmouseX-2,pmouseY+2,mouseX+2,mouseY-2);
      line(pmouseX-3,pmouseY+3,mouseX+3,mouseY-3);
      line(pmouseX+4,pmouseY-4,mouseX-4,mouseY+4);
      line(pmouseX+5,pmouseY-5,mouseX-5,mouseY+5);
      }
      break;
    }
    }//switch
  }//if

      strokeWeight(1);
  if ( mouseX>quitButtonX && mouseX<quitButtonX+quitButtonWidth && mouseY>quitButtonY && mouseY<quitButtonY+quitButtonHeight ) { 
    buttonColour = circleRed;
  } else { 
    buttonColour = resetWhite;
  } 
  fill(buttonColour);
  rect(quitButtonX, quitButtonY, quitButtonWidth, quitButtonHeight);
  textDraw();
  fill(0);

  cp.render();

  // command buttons !!!!!!!!!!!!!!
  for (CellForCommandButton currentButton : buttons) {
    currentButton.display();
  }
}

 void menu(){ //interface for the Left
//color & thick display
 //rect();
  stroke(cp.penTool);
  strokeWeight(thick);
  line(90,450,90,650); 
//buttons
  stroke(10);
  strokeWeight(3.7); 
  fill(255);
  rect(25, 355, 60, 60);//plus button
  rect(95, 355, 60, 60);//minus button
  rect(25, 800, 135, 60);//reset button
  rect(25, 700, 135, 60); //Line Art button
//text on the button
  fill(0);
  text("Line Art",87,730); 
  text("RESET",87,833); 
  noStroke(); 
  rect(50,360,10,50);//symbol increase thickness
  rect(30,380,50,10);//symbol increase thickness
  rect(100,380,50,10);//symbol decrease thickness
 }



// Mouse Pressed  < ================================================ >


void mousePressed() {


  
 if ( mouseX>drawingSurfaceX  &&
    mouseX<drawingSurfaceX+drawingSurfaceWidth  &&
    mouseY>drawingSurfaceY && 
    mouseY<drawingSurfaceY+drawingSurfaceHeight) {
    println("drawing surface");
    //if (draw == false) {
    draw = true;
    }
    if (mousePressed && pmouseX>25 && pmouseX<85 && pmouseY>355 && pmouseY<415){
    thick = constrain(thick+1,5,60);
    line(90,450,90,650);//increase the thickness when click the "plus" button
    }else if (mousePressed && pmouseX>95 && pmouseX<155 && pmouseY>355 && pmouseY<415){
    thick = constrain(thick-1,5,60);//decrease the thickness when click the "minus" button
    line(90,450,90,650);
    }
    
    //Line Art rect(25, 700, 135, 60);
    if (mousePressed && pmouseX>25 && pmouseX<160 && pmouseY>700 && pmouseY<760){
      if (indexImage<imageList.length-1)
    image( imageList[indexImage], mouseX, mouseY);
  indexImage++;
  println(indexImage);
    }
    
  // Press to Exit
  if ( mouseX>quitButtonX &&
    mouseX<quitButtonX+quitButtonWidth &&
    mouseY>quitButtonY &&
    mouseY<quitButtonY+quitButtonHeight )
    exit();

  // command buttons !!!!!!!!!!!!!!
  // Check mouseX/mouseY against button position/size
  String foundCMD="NONE"; 
  for (CellForCommandButton currentButton : buttons) {
    foundCMD = currentButton.checkMouseOver();  
    if (!foundCMD.equals("NONE") ) {
      break;
    }//if
  }//for

  // if found a command 
  if  (!foundCMD.equals("NONE") ) {
    println(foundCMD);

    // eval cmd 
    switch(foundCMD) {

    case "Save":
      //// Save image here 
      String fileName = "savedImage-" + nf(counter, 3) + ".png";
      println("saving "+fileName); 
      save(fileName);
      counter++;
      break;

    case "Pencil":
      mode = 0;
      break;

    case "Rectangle":
      mode = 1; 
      break; 

    case "Triangle":
      mode = 2; 
      break; 

    case "Circle":
      mode = 3; 
      break; 

    case "Fill":
      mode=4; 
      break; 

    case "Spray":
      // 
      mode = 5; 
      break; 

    case "caligraphy":
    mode = 6;
    break; 
    
    default:
      println("UNKNOWN foundCMD !!!!!!!!!!!!!!!!     "
        +foundCMD
        + "   +++++++++++++++++++++++++++++++++++++++++++++++++");
      exit(); 
      break; 
    }//switch
  }

  if (mousePressed && pmouseX>25 && pmouseX<160 && pmouseY>800 && pmouseY<860){
    fill(255);
    rect(drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight); }

}

// Mouse Released  < ================================================ >
void mouseReleased() {
  // Save each line we draw to our stack of UNDOs
  undo.takeSnap();
}
//  KeyPressed  < ================================================ >

void keyPressed() {

  //Music control Buttons

  if ( key == ' ' ) { // ??????
    // Press Space to PAUSE & PLAY
    println("[space]");
    if ( song1.isPlaying() ) {
      song1.pause();
    } else if ( song1.position() == song1.length() ) {
      song1.rewind();   
      song1.play();
    } else {
      song1.play();
      //Play
    }
  }
  //
  if ( key == 's' || key == 'S' ) {
    if ( song1.isPlaying() ) {
      song1.pause();
      song1.rewind();
    } else if ( song1.position() == song1.length() ) {
      song1.rewind();
    } else {
      song1.rewind();
    }
  }

  if ( key == 'f' || key == 'f' ) song1.skip(1000);
  if ( key == 'r' || key == 'R' ) song1.skip(-1000);
  if ( key == 'l' || key == 'L' ) song1.loop(loopIntNum);

  //UNDO AND REDO
  if (key == CODED) {
    if (keyCode == CONTROL) 
      controlDown = true;
    if (keyCode == SHIFT)
      shiftDown = true;
    return;
  } 
  // redo(control shift Z) or an undo(control Z)
  if (controlDown) {
    if (keyCode == 'Z') {
      if (shiftDown)
        undo.redo();
      else
        undo.undo();
    }
    return;
  }
 /*( if (key=='s') {
    saveFrame("image####.png");
  }*/
}//end of keyPressed


// KeyReleased Code  < ================================================ >

void keyreleased() {

  if (key == CODED) {
    if (keyCode == CONTROL) 
      controlDown = false;
    if (keyCode == SHIFT)
      shiftDown = false;
  }
}//end of keyReleased 


// MAIN COLOR WHEEL CODE < ================================================ >

public class ColorPicker 
{
  int x, y, w, h, c;
  PImage cpImage;
  color penTool;

  public ColorPicker ( int x, int y, int w, int h, int c )
  {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.c = c;
    this.penTool = c;

    cpImage = new PImage( w, h );

    init();
  }

  private void init ()
  {
    // draw color.
    int cw = w - 60;
    for ( int i=0; i<cw; i++ ) 
    {
      float nColorPercent = i / (float)cw;
      float rad = (-360 * nColorPercent) * (PI / 180);
      int nR = (int)(cos(rad) * 127 + 128) << 16;
      int nG = (int)(cos(rad + 2 * PI / 3) * 127 + 128) << 8;
      int nB = (int)(Math.cos(rad + 4 * PI / 3) * 127 + 128);
      int nColor = nR | nG | nB;

      setGradient( i, 0, 1, h/2, 0xFFFFFF, nColor );
      setGradient( i, (h/2), 1, h/2, nColor, 0x000000 );
    }

    // draw black/white.
    drawRect( cw, 0, 30, h/2, 0xFFFFFF );
    drawRect( cw, h/2, 30, h/2, 0 );

    // draw grey scale.
    for ( int j=0; j<h; j++ )
    {
      int g = 255 - (int)(j/(float)(h-1) * 255 );
      drawRect( w-30, j, 30, 1, color( g, g, g ) );
    }
  }

  private void setGradient(int x, int y, float w, float h, int c1, int c2 )
  {
    float deltaR = red(c2) - red(c1);
    float deltaG = green(c2) - green(c1);
    float deltaB = blue(c2) - blue(c1);

    for (int j = y; j<(y+h); j++)
    {
      int c = color( red(c1)+(j-y)*(deltaR/h), green(c1)+(j-y)*(deltaG/h), blue(c1)+(j-y)*(deltaB/h) );
      cpImage.set( x, j, c );
    }
  }

  private void drawRect( int rx, int ry, int rw, int rh, int rc )
  {
    for (int i=rx; i<rx+rw; i++) 
    {
      for (int j=ry; j<ry+rh; j++) 
      {
        cpImage.set( i, j, rc );
      }
    }
  }

  public void render ()
  {
    image( cpImage, x, y );
    if ( mousePressed &&
      mouseX >= x && 
      mouseX < x + w &&
      mouseY >= y &&
      mouseY < y + h )
    {
      c = get( mouseX, mouseY );
    }
    fill( c );
    rect( x, y+h+10, 20, 20 );
    penTool = color(c);
  }
}


// Class for UNDO & REDO <---------------------------------------------------->

class Undo {
  // Number ss taken
  int undoSteps=0, redoSteps=0;  
  CircImgCollection images;
  //
  Undo(int levels) {
    images = new CircImgCollection(levels);
  }

  public void takeSnap() {
    undoSteps = min(undoSteps+1, images.amount-1);
    // each time we draw we disable redo
    redoSteps = 0;
    images.next();
    images.capture();
  }
  public void undo() {
    if (undoSteps > 0) {
      undoSteps--;
      redoSteps++;
      images.prev();
      images.show();
    }
  }
  public void redo() {
    if (redoSteps > 0) {
      undoSteps++;
      redoSteps--;
      images.next();
      images.show();
    }
  }
}


class CircImgCollection {
  int amount, current;
  PImage[] img;
  CircImgCollection(int amountOfImages) {
    amount = amountOfImages;

    // Initialize all images as copies of the current display
    img = new PImage[amount];
    for (int i=0; i<amount; i++) {
      img[i] = createImage(width, height, RGB);
      img[i] = get();
    }
  }
  void next() {
    // ????
    if (amount!=0)
      current = (current + 1) % amount;
  }
  void prev() {
    current = (current - 1 + amount) % amount;
  }
  void capture() {
    // ???
    if (img!=null&&img.length>=1)
      img[current] = get();
  }
  void show() {
    image(img[current], 0, 0);
  }
}

// -------------------------------------------------------
void Spraybrush () {

  int width1=30; // that be the width of your brush
  //
  float radx;   // Radius
  float rady;
  float angle1; // angle
  float x;      // result
  float y;
  //
  for (int i=0; i < maxIterations; i++) {
    radx=random(width1);
    rady=random(width1);
    angle1= random(359);
    //
    x=(radx*cos(radians(angle1)))+mouseX;
    y=(radx*sin(radians(angle1)))+mouseY;
    //
    point(x, y);
  }
} // func

void Calligraphybrush(int x1,int y1,int x2,int y2)
{
  strokeWeight(1);
    line(x1+5,y1-5,x1-5,y1+5);
    line(x2+5,y2-5,x2-5,y2+5);
}

// ----------------------------------------------------------

public class FloodFill1
{
  protected int iw; // Image width
  protected int ih; // Image height
  protected color[] imagePixels;
  protected color backColor; // Color found at given position
  protected color fillColor; // Color to apply
  // Stack is almost deprecated and slow (synchronized).
  // I would use Deque but that's Java 1.6, excluding current (mid-2009) Macs...
  protected ArrayList stack = new ArrayList();
  //
  public FloodFill1()
  {
    iw = width;
    ih = height;
    imagePixels = pixels; // Assume loadPixels have been done before
  }
  //
  public FloodFill1(PImage imageToProcess)
  {
    iw = imageToProcess.width;
    ih = imageToProcess.height;
    imagePixels = imageToProcess.pixels; // Assume loadPixels have been done before if sketch image
  }
  //
  public void DoFill(int startX, int startY, color fc)
  {
    // start filling
    fillColor = fc;
    backColor = imagePixels[startX + startY * iw];
    // don't run if fill color is the same as background one
    if (fillColor == backColor)
      return;
    stack.add(new PVector(startX, startY));
    while (stack.size () > 0)
    {
      PVector p = (PVector) stack.remove(stack.size() - 1);
      // Go left
      FillScanLine((int) p.x, (int) p.y, -1);
      // Go right
      FillScanLine((int) p.x + 1, (int) p.y, 1);
    }
  }
  //
  protected void FillScanLine(int x, int y, int dir)
  {
    // compute current index in pixel buffer array
    int idx = x + y * iw;
    boolean inColorRunAbove = false;
    boolean inColorRunBelow = false;
    // fill until boundary in current scanline...
    // checking neighbouring pixel rows
    while (x >= 0 && x < iw && imagePixels[idx] == backColor)
    {
      imagePixels[idx] = fillColor;
      if (y > 0) // Not on top line
      {
        if (imagePixels[idx - iw] == backColor)
        {
          if (!inColorRunAbove)
          {
            // The above pixel needs to be flooded too, we memorize the fact.
            // Only once per run of pixels of back color (hence the inColorRunAbove test)
            stack.add(new PVector(x, y-1));
            inColorRunAbove = true;
          }
        } else // End of color run (or none)
        {
          inColorRunAbove = false;
        }
      }
      if (y < ih - 1) // Not on bottom line
      {
        if (imagePixels[idx + iw] == backColor)
        {
          if (!inColorRunBelow)
          {
            // Idem with pixel below, remember to process there
            stack.add(new PVector(x, y + 1));
            inColorRunBelow = true;
          }
        } else // End of color run (or none)
        {
          inColorRunBelow = false;
        }
      }
      // Continue in given direction
      x += dir;
      idx += dir;
    } //
  } // func
} // class
// ----------------------------------------------------------
class CellForCommandButton {

  // for the Command Buttons !!!!!!!!!

  float x, y, 
    w, h;
  String textCommandButton=""; 

  CellForCommandButton (float tempX, float tempY, 
    float tempW, float tempH, 
    String tempText1) {
    x = tempX;
    y = tempY;
    w = tempW;
    h = tempH;
    textCommandButton = tempText1;
  }

  void display() {
    // rect 
    stroke(0);
    strokeWeight(1);
    fill(111); 
    rect(x, y, w, h);

    //text 
    fill(255);
    textAlign(CENTER, CENTER); 
    text(textCommandButton, 
      x+w/2, y+h/2);
  }

  String checkMouseOver() {
    if (mouseX > x &&
      mouseX < x+w && 
      mouseY > y && 
      mouseY < y+h) {
      return textCommandButton;
    }//if
    return "NONE";
  }//method
  //
}//class
//
// ======================================================

Also the cases you taught me, I made ‘Caligraphy’ a case but it doesn’t seem to work I looked over it and look at references but I still can’t fix it… any ideas what might be causing this issue.

Thanks,
Regards.

Hello,

it is hard to work with you!

You always start a new discussion for every mini question (although we are talking about the same program all the time).

Caligraphy

That’s because you don’t understand your code. You really need to step back, read carefully and understand your code.

It’s in the mousePressed() function:

    case "caligraphy":
      mode = 6;
      break;

It’s case-sensitive, so caligraphy won’t work, try with “Caligraphy” !
Because that is the name of the button! Caligraphy.

Line Art

Here:

  //Line Art rect(25, 700, 135, 60);
  if (mousePressed && pmouseX>25 && pmouseX<160 && pmouseY>700 && pmouseY<760) {
    if (indexImage<imageList.length-1)
      image( imageList[indexImage], mouseX, mouseY);
    indexImage++;
    println(indexImage);
  }

This is wrong.

You have to distinguish between

  • where you click Line Art button, so that we are in mode Line Art
  • and when we are in the mode and click with the mouse in the canvas, the image appears there.

By the way: I made a list of buttons that work with the class CellForCommandButton but you don’t use it! Instead you bring in your own buttons like Line Art and Clear and + and - . That is unfortunate.

Remark

You haven’t posted

population();
textSetup();

so we can’t run your code! Why?
What is population(); doing??

Distinguish between mousePressed and mousePressed()

Distinguish between mousePressed (internal boolean variable) and mousePressed () (function)

see reference for both!

For continuous drawing you want mousePressed in draw().

For single clicks to show images (in “Line Art” you want mousePressed() as a function! Can you tell me why?

Thickness

You have an example line to show how thick your line is. Nice.
BUT you don’t delete the line. So when the line gets thinner again, we don’t see this!!!

Color

Initially the color is white but the canvas is also white, so your stroke is invisible.
Bad.

Warm regards,

Chrisir


Full Sketch

//
//Minim Library    <------------------------------------------------------------->
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;


//Global Variables  <------------------------------------------------------------->

PVector v1;
int PenPrevX, PenPrevY;

//Spray Button
final int maxIterations = 50000;  // that's how fast spraying happens

// for image saving
int counter=0;

//Line Art
PImage[] imageList = new PImage[9];
int indexImage=0;
int i;

//Quit & Undo & Redo & Reset Button Variables
float quitButtonX, quitButtonY, quitButtonWidth, quitButtonHeight;
color buttonColour, resetWhite=#FFFFFF;
color circleRed = #FF0303;
float reset = #FFFFFF;
float ResetX, ResetY, ResetWidth, ResetHeight;
float undoX, undoY, undoWidth, undoHeight;
float redoX, redoY, redoWidth, redoHeight;
boolean controlDown = false;
boolean shiftDown = false;

//Canvas Variables
Boolean draw=true; // 
int thick = 5; //initial thickness
float drawingSurfaceX=270, drawingSurfaceY=120, 
  drawingSurfaceWidth=600, drawingSurfaceHeight=600; ///ßßß?????

float drawingDiameter;

// Background Song
float PauseButtonX1, PauseButtonY1, PauseButtonDiameter;
int loopIntNum = 1;

String[] namesOfCommands = {
  "Rectangle", 
  "Pencil", 
  "Triangle", 
  "Circle", 
  "Spray", 
  "Fill", 
  "Caligraphy", 
  "Save"
};

CellForCommandButton[] buttons = new CellForCommandButton[namesOfCommands.length];

//Global Variables 

FloodFill1 myFloodFill;
AudioPlayer song1;
Minim minim;
Undo undo;
ColorPicker cp;

int mode = 0; // NONE

// ---------------------------------------------------------------------------------------

void setup() {

  //Line Art
  for (int i=0; i<9; i++) {
    imageList[i] = loadImage("img00 ("+i+").JPG" ) ;
    imageList[i].resize(40, 0);
  }

  //population();
  //textSetup();

  fullScreen();
  background(#A59696);
  frameRate ( 100 );
  //noFill();

  // command buttons !!!!!!!!!!!!!!
  for (int j=0; j<buttons.length; j++) {
    // j is y here 
    buttons[j] = new CellForCommandButton(270+ j*110, 44, 
      100, 40, 
      namesOfCommands[j] );
  }//for 

  // Sound File

  minim = new Minim(this);
  song1 = minim.loadFile("Sample.mp3");
  // song1.play(); // ??? 

  //COLOR WHEEL SIZE
  cp = new ColorPicker( 10, 10, 225, 225, 255 );
  //UNDO
  undo = new Undo(10);

  //Canvas
  rect(drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight);

  //ClearCanvas
}

// DRAW < ============================================================================ >

void draw() {

  menu();

  fill(255); 
  rect(width-43, 0, 50, 50);
  fill(0); 
  text(mode, 
    width-23, 23); 

  //
  if (  true &&  // draw == true
    mousePressed  
    //&& mouseX>drawingSurfaceX  &&
    //mouseX<drawingSurfaceX+drawingSurfaceWidth  &&
    //mouseY>drawingSurfaceY &&
    //mouseY<drawingSurfaceY+drawingSurfaceHeight
    ) {

    switch (mode) {
    case 0:
      println("here");
      strokeWeight(thick);
      stroke(cp.penTool);
      line(mouseX, mouseY, 
        pmouseX, pmouseY);
      break; 

    case 1:
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(mouseX, mouseY, 100, 100);
      break;

    case 2:
      stroke(0); 
      fill(255);
      strokeWeight(1);
      triangle(mouseX, mouseY, 
        mouseX+100, mouseY-100, 
        mouseX+200, mouseY+200);
      break;

    case 3:
      stroke(0); 
      fill(255);
      strokeWeight(1);
      ellipse(mouseX, mouseY, 
        100, 100);
      break;

    case 4:
      if (mousePressed) {
        loadPixels();
        myFloodFill = new FloodFill1();
        myFloodFill.DoFill(mouseX, mouseY, color(cp.penTool));
        updatePixels();
      }
      break;

    case 5:
      stroke(cp.penTool); 
      for (int i= 0; i < random(39); i++) {
        point (mouseX+random(-23, 23), 
          mouseY+random(-23, 23));
      }
      break;

    case 6:
      //  "Caligraphy"
      // 
      println("I am here");
      v1=new PVector();
      if (mousePressed) {
        strokeWeight(thick);
        stroke(cp.penTool);
        smooth();
        for (int i=0; i<60; i++) {
          line(pmouseX+5, pmouseY-5, mouseX-5, mouseY+5);
          line(pmouseX+4, pmouseY-4, mouseX-4, mouseY+4);
          line(pmouseX+3, pmouseY-3, mouseX-3, mouseY+3);
          line(pmouseX+2, pmouseY-2, mouseX-2, mouseY+2);
          line(pmouseX+1, pmouseY-1, mouseX-1, mouseY+1);
          line(pmouseX, pmouseY, mouseX, mouseY);
          line(pmouseX-1, pmouseY+1, mouseX+1, mouseY-1);
          line(pmouseX-2, pmouseY+2, mouseX+2, mouseY-2);
          line(pmouseX-3, pmouseY+3, mouseX+3, mouseY-3);
          line(pmouseX+4, pmouseY-4, mouseX-4, mouseY+4);
          line(pmouseX+5, pmouseY-5, mouseX-5, mouseY+5);
        }
      }
      break;

    case 7:
      // see function mousePressed
      break; 
      //
    default:
      println("unknown mode in draw. It was "
        + mode);
      exit(); 
      break;
      //
    }//switch
  }//if

  strokeWeight(1);
  if ( mouseX>quitButtonX && mouseX<quitButtonX+quitButtonWidth && mouseY>quitButtonY && mouseY<quitButtonY+quitButtonHeight ) { 
    buttonColour = circleRed;
  } else { 
    buttonColour = resetWhite;
  } 
  fill(buttonColour);
  rect(quitButtonX, quitButtonY, quitButtonWidth, quitButtonHeight);
  //textDraw();
  fill(0);

  cp.render();

  // command buttons !!!!!!!!!!!!!!
  for (CellForCommandButton currentButton : buttons) {
    currentButton.display();
  }
}

void menu() { //interface for the Left
  //color & thick display
  //rect();

  fill(#A59696);
  rect(90-35, 450, 
    60, 60);
  stroke(cp.penTool);
  strokeWeight(thick);

  line(90, 450, 90, 650); 

  //buttons
  stroke(10);
  strokeWeight(3.7); 
  fill(255);
  rect(25, 355, 60, 60);//plus button
  rect(95, 355, 60, 60);//minus button
  rect(25, 800, 135, 60);//reset button
  rect(25, 700, 135, 60); //Line Art button

  //text on the button
  fill(0);
  text("Line Art", 87, 730); 
  text("RESET", 87, 833); 
  noStroke(); 
  rect(50, 360, 10, 50);//symbol increase thickness
  rect(30, 380, 50, 10);//symbol increase thickness
  rect(100, 380, 50, 10);//symbol decrease thickness
}

// Mouse Pressed  < ================================================ >

void mousePressed() {
  if (  true &&  // draw == true
    mousePressed  &&
    mouseX>drawingSurfaceX  &&
    mouseX<drawingSurfaceX+drawingSurfaceWidth  &&
    mouseY>drawingSurfaceY &&
    mouseY<drawingSurfaceY+drawingSurfaceHeight
    ) {

    switch (mode) {
    case 7:
      // Line Art !!!!
      if (indexImage<imageList.length-1) {
        image( imageList[indexImage], mouseX, mouseY);
        indexImage++;
      } else {
        println("indexImage is MAX  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        text("indexImage is MAX  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", 
          width-400, height/2, 100, 70);
      }
      println(indexImage);
      break;
    }
    return; // leave function
  }

  if ( mouseX>drawingSurfaceX  &&
    mouseX<drawingSurfaceX+drawingSurfaceWidth  &&
    mouseY>drawingSurfaceY && 
    mouseY<drawingSurfaceY+drawingSurfaceHeight) {
    println("drawing surface");
    //if (draw == false) {
    draw = true;
  }
  if (mousePressed && pmouseX>25 && pmouseX<85 && pmouseY>355 && pmouseY<415) {
    thick++;
    thick = constrain(thick, 5, 60);
    line(90, 450, 90, 650);//increase the thickness when click the "plus" button
  } else if (mousePressed && pmouseX>95 && pmouseX<155 && pmouseY>355 && pmouseY<415) {
    thick--; 
    thick = constrain(thick, 5, 60);//decrease the thickness when click the "minus" button
    line(90, 450, 90, 650);
  }

  //Line Art rect(25, 700, 135, 60);
  if (pmouseX>25 && 
    pmouseX<160 && 
    pmouseY>700 && 
    pmouseY<760) {
    mode = 7;
  }

  // Press to Exit
  if ( mouseX>quitButtonX &&
    mouseX<quitButtonX+quitButtonWidth &&
    mouseY>quitButtonY &&
    mouseY<quitButtonY+quitButtonHeight )
    exit();

  // command buttons !!!!!!!!!!!!!!
  // Check mouseX/mouseY against button position/size
  String foundCMD="NONE"; 
  for (CellForCommandButton currentButton : buttons) {
    foundCMD = currentButton.checkMouseOver();  
    if (!foundCMD.equals("NONE") ) {
      break;
    }//if
  }//for

  // if found a command 
  if  (!foundCMD.equals("NONE") ) {
    println(foundCMD);

    // eval cmd 
    switch(foundCMD) {

    case "Save":
      //// Save image here 
      String fileName = "savedImage-" + nf(counter, 3) + ".png";
      println("saving "+fileName); 
      save(fileName);
      counter++;
      break;

    case "Pencil":
      mode = 0;
      break;

    case "Rectangle":
      mode = 1; 
      break; 

    case "Triangle":
      mode = 2; 
      break; 

    case "Circle":
      mode = 3; 
      break; 

    case "Fill":
      mode=4; 
      break; 

    case "Spray":
      // 
      mode = 5; 
      break; 

    case "Caligraphy":
      mode = 6;
      break; 

    default:
      println("UNKNOWN foundCMD !!!!!!!!!!!!!!!!     "
        +foundCMD
        + "   +++++++++++++++++++++++++++++++++++++++++++++++++");
      exit(); 
      break;
    }//switch
  }

  if (mousePressed && pmouseX>25 && pmouseX<160 && pmouseY>800 && pmouseY<860) {
    fill(255);
    rect(drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight);
  }
}

// Mouse Released  < ================================================ >
void mouseReleased() {
  // Save each line we draw to our stack of UNDOs
  undo.takeSnap();
}
//  KeyPressed  < ================================================ >

void keyPressed() {

  //Music control Buttons

  if ( key == ' ' ) { // ??????
    // Press Space to PAUSE & PLAY
    println("[space]");
    if ( song1.isPlaying() ) {
      song1.pause();
    } else if ( song1.position() == song1.length() ) {
      song1.rewind();   
      song1.play();
    } else {
      song1.play();
      //Play
    }
  }
  //
  if ( key == 's' || key == 'S' ) {
    if ( song1.isPlaying() ) {
      song1.pause();
      song1.rewind();
    } else if ( song1.position() == song1.length() ) {
      song1.rewind();
    } else {
      song1.rewind();
    }
  }

  if ( key == 'f' || key == 'f' ) song1.skip(1000);
  if ( key == 'r' || key == 'R' ) song1.skip(-1000);
  if ( key == 'l' || key == 'L' ) song1.loop(loopIntNum);

  //UNDO AND REDO
  if (key == CODED) {
    if (keyCode == CONTROL) 
      controlDown = true;
    if (keyCode == SHIFT)
      shiftDown = true;
    return;
  } 
  // redo(control shift Z) or an undo(control Z)
  if (controlDown) {
    if (keyCode == 'Z') {
      if (shiftDown)
        undo.redo();
      else
        undo.undo();
    }
    return;
  }
  /*( if (key=='s') {
   saveFrame("image####.png");
   }*/
}//end of keyPressed


// KeyReleased Code  < ================================================ >

void keyreleased() {

  if (key == CODED) {
    if (keyCode == CONTROL) 
      controlDown = false;
    if (keyCode == SHIFT)
      shiftDown = false;
  }
}//end of keyReleased 


// MAIN COLOR WHEEL CODE < ================================================ >

public class ColorPicker 
{
  int x, y, w, h, c;
  PImage cpImage;
  color penTool;

  public ColorPicker ( int x, int y, int w, int h, int c )
  {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.c = c;
    this.penTool = c;

    cpImage = new PImage( w, h );

    init();
  }

  private void init ()
  {
    // draw color.
    int cw = w - 60;
    for ( int i=0; i<cw; i++ ) 
    {
      float nColorPercent = i / (float)cw;
      float rad = (-360 * nColorPercent) * (PI / 180);
      int nR = (int)(cos(rad) * 127 + 128) << 16;
      int nG = (int)(cos(rad + 2 * PI / 3) * 127 + 128) << 8;
      int nB = (int)(Math.cos(rad + 4 * PI / 3) * 127 + 128);
      int nColor = nR | nG | nB;

      setGradient( i, 0, 1, h/2, 0xFFFFFF, nColor );
      setGradient( i, (h/2), 1, h/2, nColor, 0x000000 );
    }

    // draw black/white.
    drawRect( cw, 0, 30, h/2, 0xFFFFFF );
    drawRect( cw, h/2, 30, h/2, 0 );

    // draw grey scale.
    for ( int j=0; j<h; j++ )
    {
      int g = 255 - (int)(j/(float)(h-1) * 255 );
      drawRect( w-30, j, 30, 1, color( g, g, g ) );
    }
  }

  private void setGradient(int x, int y, float w, float h, int c1, int c2 )
  {
    float deltaR = red(c2) - red(c1);
    float deltaG = green(c2) - green(c1);
    float deltaB = blue(c2) - blue(c1);

    for (int j = y; j<(y+h); j++)
    {
      int c = color( red(c1)+(j-y)*(deltaR/h), green(c1)+(j-y)*(deltaG/h), blue(c1)+(j-y)*(deltaB/h) );
      cpImage.set( x, j, c );
    }
  }

  private void drawRect( int rx, int ry, int rw, int rh, int rc )
  {
    for (int i=rx; i<rx+rw; i++) 
    {
      for (int j=ry; j<ry+rh; j++) 
      {
        cpImage.set( i, j, rc );
      }
    }
  }

  public void render ()
  {
    image( cpImage, x, y );
    if ( mousePressed &&
      mouseX >= x && 
      mouseX < x + w &&
      mouseY >= y &&
      mouseY < y + h )
    {
      c = get( mouseX, mouseY );
    }
    fill( c );
    rect( x, y+h+10, 20, 20 );
    penTool = color(c);
  }
}


// Class for UNDO & REDO <---------------------------------------------------->

class Undo {
  // Number ss taken
  int undoSteps=0, redoSteps=0;  
  CircImgCollection images;
  //
  Undo(int levels) {
    images = new CircImgCollection(levels);
  }

  public void takeSnap() {
    undoSteps = min(undoSteps+1, images.amount-1);
    // each time we draw we disable redo
    redoSteps = 0;
    images.next();
    images.capture();
  }
  public void undo() {
    if (undoSteps > 0) {
      undoSteps--;
      redoSteps++;
      images.prev();
      images.show();
    }
  }
  public void redo() {
    if (redoSteps > 0) {
      undoSteps++;
      redoSteps--;
      images.next();
      images.show();
    }
  }
}


class CircImgCollection {
  int amount, current;
  PImage[] img;
  CircImgCollection(int amountOfImages) {
    amount = amountOfImages;

    // Initialize all images as copies of the current display
    img = new PImage[amount];
    for (int i=0; i<amount; i++) {
      img[i] = createImage(width, height, RGB);
      img[i] = get();
    }
  }
  void next() {
    // ????
    if (amount!=0)
      current = (current + 1) % amount;
  }
  void prev() {
    current = (current - 1 + amount) % amount;
  }
  void capture() {
    // ???
    if (img!=null&&img.length>=1)
      img[current] = get();
  }
  void show() {
    image(img[current], 0, 0);
  }
}

// -------------------------------------------------------
void Spraybrush () {

  int width1=30; // that be the width of your brush
  //
  float radx;   // Radius
  float rady;
  float angle1; // angle
  float x;      // result
  float y;
  //
  for (int i=0; i < maxIterations; i++) {
    radx=random(width1);
    rady=random(width1);
    angle1= random(359);
    //
    x=(radx*cos(radians(angle1)))+mouseX;
    y=(radx*sin(radians(angle1)))+mouseY;
    //
    point(x, y);
  }
} // func

void Calligraphybrush(int x1, int y1, int x2, int y2)
{
  strokeWeight(1);
  line(x1+5, y1-5, x1-5, y1+5);
  line(x2+5, y2-5, x2-5, y2+5);
}

// ----------------------------------------------------------

public class FloodFill1
{
  protected int iw; // Image width
  protected int ih; // Image height
  protected color[] imagePixels;
  protected color backColor; // Color found at given position
  protected color fillColor; // Color to apply
  // Stack is almost deprecated and slow (synchronized).
  // I would use Deque but that's Java 1.6, excluding current (mid-2009) Macs...
  protected ArrayList stack = new ArrayList();
  //
  public FloodFill1()
  {
    iw = width;
    ih = height;
    imagePixels = pixels; // Assume loadPixels have been done before
  }
  //
  public FloodFill1(PImage imageToProcess)
  {
    iw = imageToProcess.width;
    ih = imageToProcess.height;
    imagePixels = imageToProcess.pixels; // Assume loadPixels have been done before if sketch image
  }
  //
  public void DoFill(int startX, int startY, color fc)
  {
    // start filling
    fillColor = fc;
    backColor = imagePixels[startX + startY * iw];
    // don't run if fill color is the same as background one
    if (fillColor == backColor)
      return;
    stack.add(new PVector(startX, startY));
    while (stack.size () > 0)
    {
      PVector p = (PVector) stack.remove(stack.size() - 1);
      // Go left
      FillScanLine((int) p.x, (int) p.y, -1);
      // Go right
      FillScanLine((int) p.x + 1, (int) p.y, 1);
    }
  }
  //
  protected void FillScanLine(int x, int y, int dir)
  {
    // compute current index in pixel buffer array
    int idx = x + y * iw;
    boolean inColorRunAbove = false;
    boolean inColorRunBelow = false;
    // fill until boundary in current scanline...
    // checking neighbouring pixel rows
    while (x >= 0 && x < iw && imagePixels[idx] == backColor)
    {
      imagePixels[idx] = fillColor;
      if (y > 0) // Not on top line
      {
        if (imagePixels[idx - iw] == backColor)
        {
          if (!inColorRunAbove)
          {
            // The above pixel needs to be flooded too, we memorize the fact.
            // Only once per run of pixels of back color (hence the inColorRunAbove test)
            stack.add(new PVector(x, y-1));
            inColorRunAbove = true;
          }
        } else // End of color run (or none)
        {
          inColorRunAbove = false;
        }
      }
      if (y < ih - 1) // Not on bottom line
      {
        if (imagePixels[idx + iw] == backColor)
        {
          if (!inColorRunBelow)
          {
            // Idem with pixel below, remember to process there
            stack.add(new PVector(x, y + 1));
            inColorRunBelow = true;
          }
        } else // End of color run (or none)
        {
          inColorRunBelow = false;
        }
      }
      // Continue in given direction
      x += dir;
      idx += dir;
    } //
  } // func
} // class
// ----------------------------------------------------------
class CellForCommandButton {

  // for the Command Buttons !!!!!!!!!

  float x, y, 
    w, h;
  String textCommandButton=""; 

  CellForCommandButton (float tempX, float tempY, 
    float tempW, float tempH, 
    String tempText1) {
    x = tempX;
    y = tempY;
    w = tempW;
    h = tempH;
    textCommandButton = tempText1;
  }

  void display() {
    // rect 
    stroke(0);
    strokeWeight(1);
    fill(111); 
    rect(x, y, w, h);

    //text 
    fill(255);
    textAlign(CENTER, CENTER); 
    text(textCommandButton, 
      x+w/2, y+h/2);
  }

  String checkMouseOver() {
    if (mouseX > x &&
      mouseX < x+w && 
      mouseY > y && 
      mouseY < y+h) {
      return textCommandButton;
    }//if
    return "NONE";
  }//method
  //
}//class
//
// ======================================================

Keywords: Draw Program, Drawing Sketch, Caligraphy, Calligraphy, Spray, Fill, Flood Fill

here is the entire program

//Minim Library
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;


//Global Variables  <------------------------------------------------------------->
int x1;
int y1;
int x2;
int y2;
PVector v1;
int PenPrevX,PenPrevY;

//Spray Button
final int maxIterations = 50000;  // that's how fast spraying happens

// for image saving
int counter=0;

//Line Art
PImage[] imageList = new PImage[9];
int indexImage=0;
int i;
//Quit & Undo & Redo & Reset Button Variables
float quitButtonX, quitButtonY, quitButtonWidth, quitButtonHeight;
color buttonColour, resetWhite=#FFFFFF;
color circleRed = #FF0303;
float reset = #FFFFFF;
float ResetX, ResetY, ResetWidth, ResetHeight;
float undoX, undoY, undoWidth, undoHeight;
float redoX, redoY, redoWidth, redoHeight;
boolean controlDown = false;
boolean shiftDown = false;

//Canvas Variables
Boolean draw=true; // 
int thick = 5; //initial thickness
float drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight; ///ßßß?????

float drawingDiameter;

// Background Song
float PauseButtonX1, PauseButtonY1, PauseButtonDiameter;
int loopIntNum = 1;

String[] namesOfCommands = {

  "Rectangle", 
  "Pencil",
  "Triangle", 
  "Circle", 
  "Spray", 
  "Fill", 
  "Caligraphy", 
  "Save", 

};
CellForCommandButton[] buttons = new CellForCommandButton[namesOfCommands.length];

//Global Variables 

FloodFill1 myFloodFill;
AudioPlayer song1;
Minim minim;
Undo undo;
ColorPicker cp;

int mode = 0; // NONE

void setup() {
  
    //Line Art
 for (int i=0; i<9; i++) {
    imageList[i] = loadImage("img00 ("+i+").jpg" ) ;
    imageList[i].resize(500, 0);
  }
  
  population();
  textSetup();
  fullScreen();
  background(#A59696);
  frameRate ( 100 );
  //noFill();

  // command buttons !!!!!!!!!!!!!!
  for (int j=0; j<buttons.length; j++) {
    // j is y here 
    buttons[j] = new CellForCommandButton(270+ j*110, 44, 
      100, 40, 
      namesOfCommands[j] );
  }//for 

  // Sound File

  minim = new Minim(this);
  song1 = minim.loadFile("Sample.mp3");
  song1.play();

  //COLOR WHEEL SIZE
  cp = new ColorPicker( 10, 10, 225, 225, 255 );
  //UNDO
  undo = new Undo(10);

  //Canvas
  rect(drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight);

  //ClearCanvas
 
}
// DRAW < ================================================ >

  void draw() {
    
    menu();
    
    
if ( draw == true &&
    mousePressed && 
    mouseX>drawingSurfaceX  &&
    mouseX<drawingSurfaceX+drawingSurfaceWidth  &&
    mouseY>drawingSurfaceY &&
    mouseY<drawingSurfaceY+drawingSurfaceHeight) {

      
    switch (mode) {
    case 0:
      println("here");
      strokeWeight(thick);
      stroke(cp.penTool);
      line(mouseX, mouseY, pmouseX, pmouseY);
      break; 

    case 1:
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(mouseX, mouseY, 100, 100);
      break;

    case 2:
      stroke(0); 
      fill(255);
      strokeWeight(1);
      triangle(mouseX, mouseY, 
        mouseX+100, mouseY-100, 
        mouseX+200, mouseY+200);
      break;

    case 3:
      stroke(0); 
      fill(255);
      strokeWeight(1);
      ellipse(mouseX, mouseY, 
        100, 100);
      break;

    case 4:
      if (mousePressed) {
      loadPixels();
      myFloodFill = new FloodFill1();
      myFloodFill.DoFill(mouseX, mouseY, color(cp.penTool));
      updatePixels(); }
      break;

    case 5:
      stroke(cp.penTool); 
      for (int i= 0; i < random(39); i++) {
        point (mouseX+random(-23, 23), 
          mouseY+random(-23, 23));
      }
      break;
      
      case 6:
     
      v1=new PVector();
    if(mousePressed){
      strokeWeight(thick);
        stroke(cp.penTool);
        smooth();
      for(int i=0;i<60;i++){
      line(pmouseX+5,pmouseY-5,mouseX-5,mouseY+5);
      line(pmouseX+4,pmouseY-4,mouseX-4,mouseY+4);
      line(pmouseX+3,pmouseY-3,mouseX-3,mouseY+3);
      line(pmouseX+2,pmouseY-2,mouseX-2,mouseY+2);
      line(pmouseX+1,pmouseY-1,mouseX-1,mouseY+1);
      line(pmouseX,pmouseY,mouseX,mouseY);
      line(pmouseX-1,pmouseY+1,mouseX+1,mouseY-1);
      line(pmouseX-2,pmouseY+2,mouseX+2,mouseY-2);
      line(pmouseX-3,pmouseY+3,mouseX+3,mouseY-3);
      line(pmouseX+4,pmouseY-4,mouseX-4,mouseY+4);
      line(pmouseX+5,pmouseY-5,mouseX-5,mouseY+5);
      }
      break;
    }
    }//switch
  }//if

      strokeWeight(1);
  if ( mouseX>quitButtonX && mouseX<quitButtonX+quitButtonWidth && mouseY>quitButtonY && mouseY<quitButtonY+quitButtonHeight ) { 
    buttonColour = circleRed;
  } else { 
    buttonColour = resetWhite;
  } 
  fill(buttonColour);
  rect(quitButtonX, quitButtonY, quitButtonWidth, quitButtonHeight);
  textDraw();
  fill(0);

  cp.render();

  // command buttons !!!!!!!!!!!!!!
  for (CellForCommandButton currentButton : buttons) {
    currentButton.display();
  }
  
  fill(0);
  text("Music Controls :", 111, 887);
  text(" SpaceBar for Play&Pause", 115, 930);
  text("Press F for Forward", 125, 960);
  text("Press R for Rewind", 125, 990);
  text("Press L for Loop", 111, 1020);
  text("Press S for Stop", 111, 1050);
  
}



 void menu(){ //interface for the Left
//color & thick display
 //rect();
  stroke(cp.penTool);
  strokeWeight(thick);
  line(90,450,90,650); 
//buttons
  stroke(10);
  strokeWeight(3.7); 
  fill(255);
  rect(25, 355, 60, 60);//plus button
  rect(95, 355, 60, 60);//minus button
  rect(25, 800, 135, 60);//reset button
  rect(25, 700, 135, 60); //Line Art button
//text on the button
  fill(0);
  text("Line Art",87,730); 
  text("RESET",87,833); 
  noStroke(); 
  rect(50,360,10,50);//symbol increase thickness
  rect(30,380,50,10);//symbol increase thickness
  rect(100,380,50,10);//symbol decrease thickness
 
 }



// Mouse Pressed  < ================================================ >


void mousePressed() {


  
 if ( mouseX>drawingSurfaceX  &&
    mouseX<drawingSurfaceX+drawingSurfaceWidth  &&
    mouseY>drawingSurfaceY && 
    mouseY<drawingSurfaceY+drawingSurfaceHeight) {
    println("drawing surface");
    //if (draw == false) {
    draw = true;
    }
    if (mousePressed && pmouseX>25 && pmouseX<85 && pmouseY>355 && pmouseY<415){
    thick = constrain(thick+1,5,60);
    line(90,450,90,650);//increase the thickness when click the "plus" button
    }else if (mousePressed && pmouseX>95 && pmouseX<155 && pmouseY>355 && pmouseY<415){
    thick = constrain(thick-1,5,60);//decrease the thickness when click the "minus" button
    line(90,450,90,650);
    }
    
    //Line Art rect(25, 700, 135, 60);
    if (mousePressed && pmouseX>25 && pmouseX<160 && pmouseY>700 && pmouseY<760){
      if (indexImage<imageList.length-1)
    image( imageList[indexImage], mouseX, mouseY);
  indexImage++;
  println(indexImage);
    }
    
  // Press to Exit
  if ( mouseX>quitButtonX &&
    mouseX<quitButtonX+quitButtonWidth &&
    mouseY>quitButtonY &&
    mouseY<quitButtonY+quitButtonHeight )
    exit();

  // command buttons !!!!!!!!!!!!!!
  // Check mouseX/mouseY against button position/size
  String foundCMD="NONE"; 
  for (CellForCommandButton currentButton : buttons) {
    foundCMD = currentButton.checkMouseOver();  
    if (!foundCMD.equals("NONE") ) {
      break;
    }//if
  }//for

  // if found a command 
  if  (!foundCMD.equals("NONE") ) {
    println(foundCMD);

    // eval cmd 
    switch(foundCMD) {

    case "Save":
      //// Save image here 
      String fileName = "savedImage-" + nf(counter, 3) + ".png";
      println("saving "+fileName); 
      save(fileName);
      counter++;
      break;

    case "Pencil":
      mode = 0;
      break;

    case "Rectangle":
      mode = 1; 
      break; 

    case "Triangle":
      mode = 2; 
      break; 

    case "Circle":
      mode = 3; 
      break; 

    case "Fill":
      mode=4; 
      break; 

    case "Spray":
      // 
      mode = 5; 
      break; 

    case "Caligraphy":
    mode = 6;
    break; 
    
    default:
      println("UNKNOWN foundCMD !!!!!!!!!!!!!!!!     "
        +foundCMD
        + "   +++++++++++++++++++++++++++++++++++++++++++++++++");
      exit(); 
      break; 
    }//switch
  }

  if (mousePressed && pmouseX>25 && pmouseX<160 && pmouseY>800 && pmouseY<860){
    fill(255);
    rect(drawingSurfaceX, drawingSurfaceY, drawingSurfaceWidth, drawingSurfaceHeight); }

}

// Mouse Released  < ================================================ >
void mouseReleased() {
  // Save each line we draw to our stack of UNDOs
  undo.takeSnap();
}
//  KeyPressed  < ================================================ >

void keyPressed() {

  //Music control Buttons

  if ( key == ' ' ) { // ??????
    // Press Space to PAUSE & PLAY
    println("[space]");
    if ( song1.isPlaying() ) {
      song1.pause();
    } else if ( song1.position() == song1.length() ) {
      song1.rewind();   
      song1.play();
    } else {
      song1.play();
      //Play
    }
  }
  //
  if ( key == 's' || key == 'S' ) {
    if ( song1.isPlaying() ) {
      song1.pause();
      song1.rewind();
    } else if ( song1.position() == song1.length() ) {
      song1.rewind();
    } else {
      song1.rewind();
    }
  }

  if ( key == 'f' || key == 'f' ) song1.skip(1000);
  if ( key == 'r' || key == 'R' ) song1.skip(-1000);
  if ( key == 'l' || key == 'L' ) song1.loop(loopIntNum);

  //UNDO AND REDO
  if (key == CODED) {
    if (keyCode == CONTROL) 
      controlDown = true;
    if (keyCode == SHIFT)
      shiftDown = true;
    return;
  } 
  // redo(control shift Z) or an undo(control Z)
  if (controlDown) {
    if (keyCode == 'Z') {
      if (shiftDown)
        undo.redo();
      else
        undo.undo();
    }
    return;
  }
 /*( if (key=='s') {
    saveFrame("image####.png");
  }*/
}//end of keyPressed


// KeyReleased Code  < ================================================ >

void keyreleased() {

  if (key == CODED) {
    if (keyCode == CONTROL) 
      controlDown = false;
    if (keyCode == SHIFT)
      shiftDown = false;
  }
}//end of keyReleased 


// MAIN COLOR WHEEL CODE < ================================================ >

public class ColorPicker 
{
  int x, y, w, h, c;
  PImage cpImage;
  color penTool;

  public ColorPicker ( int x, int y, int w, int h, int c )
  {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.c = c;
    this.penTool = c;

    cpImage = new PImage( w, h );

    init();
  }

  private void init ()
  {
    // draw color.
    int cw = w - 60;
    for ( int i=0; i<cw; i++ ) 
    {
      float nColorPercent = i / (float)cw;
      float rad = (-360 * nColorPercent) * (PI / 180);
      int nR = (int)(cos(rad) * 127 + 128) << 16;
      int nG = (int)(cos(rad + 2 * PI / 3) * 127 + 128) << 8;
      int nB = (int)(Math.cos(rad + 4 * PI / 3) * 127 + 128);
      int nColor = nR | nG | nB;

      setGradient( i, 0, 1, h/2, 0xFFFFFF, nColor );
      setGradient( i, (h/2), 1, h/2, nColor, 0x000000 );
    }

    // draw black/white.
    drawRect( cw, 0, 30, h/2, 0xFFFFFF );
    drawRect( cw, h/2, 30, h/2, 0 );

    // draw grey scale.
    for ( int j=0; j<h; j++ )
    {
      int g = 255 - (int)(j/(float)(h-1) * 255 );
      drawRect( w-30, j, 30, 1, color( g, g, g ) );
    }
  }

  private void setGradient(int x, int y, float w, float h, int c1, int c2 )
  {
    float deltaR = red(c2) - red(c1);
    float deltaG = green(c2) - green(c1);
    float deltaB = blue(c2) - blue(c1);

    for (int j = y; j<(y+h); j++)
    {
      int c = color( red(c1)+(j-y)*(deltaR/h), green(c1)+(j-y)*(deltaG/h), blue(c1)+(j-y)*(deltaB/h) );
      cpImage.set( x, j, c );
    }
  }

  private void drawRect( int rx, int ry, int rw, int rh, int rc )
  {
    for (int i=rx; i<rx+rw; i++) 
    {
      for (int j=ry; j<ry+rh; j++) 
      {
        cpImage.set( i, j, rc );
      }
    }
  }

  public void render ()
  {
    image( cpImage, x, y );
    if ( mousePressed &&
      mouseX >= x && 
      mouseX < x + w &&
      mouseY >= y &&
      mouseY < y + h )
    {
      c = get( mouseX, mouseY );
    }
    fill( c );
    rect( x, y+h+10, 20, 20 );
    penTool = color(c);
  }
}


// Class for UNDO & REDO <---------------------------------------------------->

class Undo {
  // Number ss taken
  int undoSteps=0, redoSteps=0;  
  CircImgCollection images;
  //
  Undo(int levels) {
    images = new CircImgCollection(levels);
  }

  public void takeSnap() {
    undoSteps = min(undoSteps+1, images.amount-1);
    // each time we draw we disable redo
    redoSteps = 0;
    images.next();
    images.capture();
  }
  public void undo() {
    if (undoSteps > 0) {
      undoSteps--;
      redoSteps++;
      images.prev();
      images.show();
    }
  }
  public void redo() {
    if (redoSteps > 0) {
      undoSteps++;
      redoSteps--;
      images.next();
      images.show();
    }
  }
}


class CircImgCollection {
  int amount, current;
  PImage[] img;
  CircImgCollection(int amountOfImages) {
    amount = amountOfImages;

    // Initialize all images as copies of the current display
    img = new PImage[amount];
    for (int i=0; i<amount; i++) {
      img[i] = createImage(width, height, RGB);
      img[i] = get();
    }
  }
  void next() {
    // ????
    if (amount!=0)
      current = (current + 1) % amount;
  }
  void prev() {
    current = (current - 1 + amount) % amount;
  }
  void capture() {
    // ???
    if (img!=null&&img.length>=1)
      img[current] = get();
  }
  void show() {
    image(img[current], 0, 0);
  }
}

// -------------------------------------------------------
void Spraybrush () {

  int width1=30; // that be the width of your brush
  //
  float radx;   // Radius
  float rady;
  float angle1; // angle
  float x;      // result
  float y;
  //
  for (int i=0; i < maxIterations; i++) {
    radx=random(width1);
    rady=random(width1);
    angle1= random(359);
    //
    x=(radx*cos(radians(angle1)))+mouseX;
    y=(radx*sin(radians(angle1)))+mouseY;
    //
    point(x, y);
  }
} // func

void Calligraphybrush(int x1,int y1,int x2,int y2)
{
  strokeWeight(1);
    line(x1+5,y1-5,x1-5,y1+5);
    line(x2+5,y2-5,x2-5,y2+5);
}

// ----------------------------------------------------------

public class FloodFill1
{
  protected int iw; // Image width
  protected int ih; // Image height
  protected color[] imagePixels;
  protected color backColor; // Color found at given position
  protected color fillColor; // Color to apply
  // Stack is almost deprecated and slow (synchronized).
  // I would use Deque but that's Java 1.6, excluding current (mid-2009) Macs...
  protected ArrayList stack = new ArrayList();
  //
  public FloodFill1()
  {
    iw = width;
    ih = height;
    imagePixels = pixels; // Assume loadPixels have been done before
  }
  //
  public FloodFill1(PImage imageToProcess)
  {
    iw = imageToProcess.width;
    ih = imageToProcess.height;
    imagePixels = imageToProcess.pixels; // Assume loadPixels have been done before if sketch image
  }
  //
  public void DoFill(int startX, int startY, color fc)
  {
    // start filling
    fillColor = fc;
    backColor = imagePixels[startX + startY * iw];
    // don't run if fill color is the same as background one
    if (fillColor == backColor)
      return;
    stack.add(new PVector(startX, startY));
    while (stack.size () > 0)
    {
      PVector p = (PVector) stack.remove(stack.size() - 1);
      // Go left
      FillScanLine((int) p.x, (int) p.y, -1);
      // Go right
      FillScanLine((int) p.x + 1, (int) p.y, 1);
    }
  }
  //
  protected void FillScanLine(int x, int y, int dir)
  {
    // compute current index in pixel buffer array
    int idx = x + y * iw;
    boolean inColorRunAbove = false;
    boolean inColorRunBelow = false;
    // fill until boundary in current scanline...
    // checking neighbouring pixel rows
    while (x >= 0 && x < iw && imagePixels[idx] == backColor)
    {
      imagePixels[idx] = fillColor;
      if (y > 0) // Not on top line
      {
        if (imagePixels[idx - iw] == backColor)
        {
          if (!inColorRunAbove)
          {
            // The above pixel needs to be flooded too, we memorize the fact.
            // Only once per run of pixels of back color (hence the inColorRunAbove test)
            stack.add(new PVector(x, y-1));
            inColorRunAbove = true;
          }
        } else // End of color run (or none)
        {
          inColorRunAbove = false;
        }
      }
      if (y < ih - 1) // Not on bottom line
      {
        if (imagePixels[idx + iw] == backColor)
        {
          if (!inColorRunBelow)
          {
            // Idem with pixel below, remember to process there
            stack.add(new PVector(x, y + 1));
            inColorRunBelow = true;
          }
        } else // End of color run (or none)
        {
          inColorRunBelow = false;
        }
      }
      // Continue in given direction
      x += dir;
      idx += dir;
    } //
  } // func
} // class
// ----------------------------------------------------------
class CellForCommandButton {

  // for the Command Buttons !!!!!!!!!

  float x, y, 
    w, h;
  String textCommandButton=""; 

  CellForCommandButton (float tempX, float tempY, 
    float tempW, float tempH, 
    String tempText1) {
    x = tempX;
    y = tempY;
    w = tempW;
    h = tempH;
    textCommandButton = tempText1;
  }

  void display() {
    // rect 
    stroke(0);
    strokeWeight(1);
    fill(111); 
    rect(x, y, w, h);

    //text 
    fill(255);
    textAlign(CENTER, CENTER); 
    text(textCommandButton, 
      x+w/2, y+h/2);
  }

  String checkMouseOver() {
    if (mouseX > x &&
      mouseX < x+w && 
      mouseY > y && 
      mouseY < y+h) {
      return textCommandButton;
    }//if
    return "NONE";
  }//method
  //
}//class
//
// ======================================================

Population

void population() {

  //Canvas Location
  
  drawingSurfaceX = width*2.6/20;
  drawingSurfaceY = height*0.095;
  drawingSurfaceWidth = width*12/14;
  drawingSurfaceHeight = height*11.3/12.6;
  fill(255);

  // Quit Button Location
  
  quitButtonX = width*18.3/19;
  quitButtonY = height*0.1/300;
  quitButtonWidth = width*1/27;
  quitButtonHeight = height*1/27;
  

}


Text

String buttonText = "X";
PFont titleFont;

void textSetup() { 
  titleFont = createFont ("Arial", 55);
}

void textDraw() { 
  fill(0); 
  textAlign (CENTER, CENTER); 
  textFont(titleFont, 20); 
  text(buttonText, quitButtonX, quitButtonY, quitButtonWidth, quitButtonHeight);
  fill(255);
}

Thank you for the brush, I was probably really tired so I missed the capital that’s my bad sorry.

I will defenitly look into the mousepressed function, and see if I can get that to work because the line art button is my last feature.

Thank you so much for all the help through this project

1 Like

I made a few changes throughout the program and fixed a few things.

Did you run my version and test it or did you think I posted it for fun?

LineArt works and Caligraphy and the line for thickness changes

1 Like

I ran your program and that’s how I updated mine to work, if you try to run it I made the changes, But I still
need to position line art image every time I press the line art button, also I need to make it so that if I click on the button and after the 10 images finish it repeats instead of getting that println error.

1 Like

I got this working too.

Just set mode to 7 and Later act on this in function mousePressed

Yeah where it says text/ println just say indeximage=0;

Hi, yea thank you so much I completed it… I have planing to make a shuffle button… any ideas where I can find code for that. I’m sorry the last minute but I need it handed in like 10hrs, its for a minim music program.

strokeWeight(3);
  fill(white);
  rect(ShuffleX, ShuffleY,ShuffleW, ShuffleH);
  noStroke();
  fill(black);
  ellipse(ShuffleCX, ShuffleCY ,ShuffleCD, ShuffleCD);
  textDraw3();
  stroke(1);

here is what the button looks like I have 10 songs that play and after pressing this button it should randomly play the songs not in the order they are put. Thanks.

If not its okay, thanks for all the help throughout my program.

1 Like

[Sound-Program]

When you have the songs in an arraylist you can shuffle them

Then Collections.shuffle ( songs );

when your arraylist is called songs

[Edited]