Trying to make my own version of the "quick draw" game to build a library and teach an AI as a BEGINNER

You are right again!

using a random is a very good idea !

1 Like

awesome awesoomee!! thank you so much, that really looks a lot better now!! I’m still going through it and figuring out whats happening. The sketchPath is new to me, and something there is not quite right: It used to save the frames to a folder called “drawings”, now they are stored in the sketch library.


  // remove text !!!!!!!
  fill(250);
  noStroke(); 
  rect( 0, 0, width, 60); 

  // save now !!!!!
  String newName=
    "categories[index]"
    + ".png";
  if (fileExists(sketchPath("")+""+newName)) {
    //!!problem
    int i=0;

    while (fileExists(sketchPath("")+""+newName)) {

      newName=
        "categories[index]" 
        +trim(str(i))
        + ".png";
      i++;
    }
    save("drawings/newName");
  } else {
    save("drawings/newName");
  }

currently attempting to sort it out. But I had the idea, maybe its more useful to store each category in a seperate folder and name them with a time stamp variable + number or something?

or is it easier to have everything stored in 1? super excited about open CV, that would be the next level!! Glad to have you here in this thread, thanks! :grinning_face_with_smiling_eyes::sparkles:

1 Like

When I run it, the folder “drawings” is used and the folder “drawings”, is still in the Sketch’s folder.

I just use the sketchPath () function because the function fileExists seems to require a full path (absolute path) and not only a relative path.

float x = 10;

float prevMouseX = 0;
float prevMouseY = 0;

PFont F;

int index = 0; // = int(random(words.length))
int timer;

final String[] words = {
  "amused", 
  "joyful, cheerful", 
  "energized, pumped up", 
  "annoyed", 
  "excited", 
  "anxious, tense", "dreamy", 
  "creeped out, scared", "disgusted, revolted", "angry", "amazed, fascinated", "calm, realxed", "bored", "sad", 
  "flirty", "proud, couragous", "romantic, loving", "confrontational, argumentative", "tender, longing", 
  "triumphant, heroic", "bittersweet, melancholic", "euphoric, ecstatic", "disappointed", 
  "confused", "remorseful, sorry", "silly, goofy", "jealous", "sympathetic, pitiful"
  };


void setup() {
  size(500, 500);
  background(255);
  
  surface.setTitle("Emotive Drawing");
  surface.setResizable(true);
  surface.setLocation(100, 100);
  
  F = createFont("GTFAdieuTRIAL-Regular-48.vlw", 40);
  
  timer = millis();
}


void draw(){
    
  if (x<11){ellipser();}
  if (x>10){run();}
  println(x);
}

void ellipser(){
  background(255);
  
  fill(0, 0, 255);
  ellipse(mouseX, mouseY, 160,160);
  filter(BLUR, 4);
  
  PFont f = createFont("GTFAdieuTRIAL-Regular-48.vlw", 40);

  fill(0);
  textSize (50);
  textFont(f);
  String w = "emotive drawing";
  text(w, 250, 20);
  
  line(10,60,490,60);
  
  textAlign(LEFT);
  textSize (12);
  String s = "Can we express emotions without words - only by drawing lines? \nLet's teach a neural network, and find out it can learn to detect emotions in handwriting, drawings or font.";
  text(s, 15, 430, 485, 80);  // Text wraps within text box
  
  fill(255);
  textSize (20);
  textAlign(CENTER,CENTER);
  String t = "start";
  text(t,mouseX,mouseY);
}

void mousePressed(){
  x = 15;
  background(255);
}

void run(){
  fill(255);
  rect(0,0,500,60);
  rect(0,450,500,50);
  
  fill(0);
  textSize (12);
  textAlign(LEFT);
  
  String p = "category:";
  text(p + words[index] , 15, 13, 60, 40);
  
  String o = "starting with your first line, you have 15 sec. \nto draw - or press enter if you're done!";
  text(o, 200, 25);   //to do: create text box aligned RIGHT but text in it aligned LEFT
  
  //line(10,60,490,60);
  
  String j = "1/28";  //to do: create variable / counter for categories submitted
  text(j, 15, 480);
  
  String k = "00.15";
  text(k, 450, 480);  //to do: create counter for time left
  
  x =12;
}

void mouseDragged(){
  if (x>10){
  fill(0);  
  stroke(0);
  float distanceX;
  float distanceY;

  distanceX = abs(mouseX - prevMouseX);
  distanceY = abs(mouseY - prevMouseY);

  float avDistance;
  avDistance = (distanceX + distanceY)/2;
  //set range for strokeWeight: squash 0-200 (input range) into 2-10 (output range) 
  avDistance = map(avDistance, 0, 150, 1, 50);

  //ellipse(mouseX, mouseY, 10, 10);
  //ellipse(mouseX, mouseY, avDistance, avDistance);

  prevMouseX = mouseX;
  prevMouseY = mouseY;

  //line(pmouseX,pmouseY,mouseX,mouseY);
  //strokeWeight(avDistance);
  line(pmouseX, pmouseY, prevMouseX, prevMouseY);}
}

void keyPressed() {

  if (index>=words.length) {
    return; // LEAVE
  }
  SaveAndPrepareNextWord();
}

void SaveAndPrepareNextWord() {

  // remove text !!!!!!!
  fill(250);
  noStroke(); 
  rect( 0, 0, width, 60); 

  // save now !!!!!
  String newName="drawings\\"
    +words[index]
    + ".png";
  if (fileExists(sketchPath("")+""+newName)) {
    //!!problem
    int i=0;

    while (fileExists(sketchPath("")+""+newName)) {

      newName="drawings\\"
        +words[index] 
        +trim(str(i))
        + ".png";
      i++;
    }
    save(newName);
  } else {
    save(newName);
  }

  // prepare next word !!!!  
  index++;
  background(250);
  textSize (40);
  textFont(F);
  fill(0);
  stroke(0);
  timer=millis();
}


boolean fileExists(String fileName) {
  File file=new File(fileName);
  boolean exists = file.exists();
  if (!exists) {
    println(fileName);
    return false;
  } else {

    return true;
  }
} 

Update - I tried to implement my GUI layout, and realized I have no clue what I am doing haha. But I’ve come this far. The images are still saved in the wrong folder though, also the font I picked stopped working, so I think I have to look into folder structure again?

1 Like

I am not sure what you expect.

I will check it out now.

Do you want to save the images in the folder drawings within your Sketch’s folder?

  • When you in processing (in the IDE) type CTRL-k this folder opens.

Do you mean this folder?


the “drawings\” seems to be part of the naming and not the path, they are saved in the sketch folder, but i want them in an extra folder called “drawings”.

otherwise the numbering with the i++ system works fine :+1:

I see

I use win 10

you are using mac?

I enhanced your Sketch. You used x to indicate whether we are on start screen or not.

I replaced x with state and made an feedback screen.

gotta go.

[EDITED]

here :

  // save now !!!!!
  String newName="drawings/"
    +words[index]
    + ".png";

instead of / I had \\ previously (not working for you)

try either / (what I have now) OR // on your system

hint: it’s in 2 places in your code.
hint: check the reference

gotta go.


int state = 0; 

//float x = 10;

float prevMouseX = 0;
float prevMouseY = 0;

PFont F;

int index = 0; // = int(random(words.length))
int indexRND; 

int timer;

final String[] words = {
  "amused", 
  "joyful, cheerful", 
  "energized, pumped up", 
  "annoyed", 
  "excited", 
  "anxious, tense", "dreamy", 
  "creeped out, scared", "disgusted, revolted", "angry", "amazed, fascinated", "calm, realxed", "bored", "sad", 
  "flirty", "proud, couragous", "romantic, loving", "confrontational, argumentative", "tender, longing", 
  "triumphant, heroic", "bittersweet, melancholic", "euphoric, ecstatic", "disappointed", 
  "confused", "remorseful, sorry", "silly, goofy", "jealous", "sympathetic, pitiful"
};

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

void setup() {
  size(500, 500);
  background(255);

  surface.setTitle("Emotive Drawing");
  surface.setResizable(true);
  surface.setLocation(100, 100);

  F = createFont("GTFAdieuTRIAL-Regular-48.vlw", 50);
  textSize (50);
  textFont(F);

  noCursor(); 

  // timer = millis();
}

void draw() {
  if (state==0) {
    // START SCREEN
    ellipser();
  } else if (state==1) {
    // Drawing 
    run();
  } else if (state==2) {
    feedback();
  }
}

//-------------------------------------------------------------------------------------
// Functions called by draw() 

void feedback() {

  background(255);

  fill(0);
  textAlign(CENTER);
  textFont(F);
  textSize (30);

  String w = "I identify the emotion as....."
    +"\n"+"\n";
  text(w+words[indexRND], 250, 60);
  text("Press mouse for next emotion", 250, height-50);

  // go back to standard
  textSize (50);
  textAlign(LEFT);
}

void ellipser() {
  // START SCREEN

  background(255);

  fill(0, 0, 255);
  ellipse(mouseX, mouseY, 160, 160);
  filter(BLUR, 4);

  fill(0);
  textSize (50);
  textFont(F);
  String w = "emotive drawing";
  text(w, 250, 20);

  line(10, 60, 490, 60);

  textAlign(LEFT);
  textSize (12);
  String s = "Can we express emotions without words - only by drawing lines? \n"
    +"Let's teach a neural network, and find out it can learn to detect emotions in handwriting, drawings or font.";
  text(s, 15, 430, 485, 80);  // Text wraps within text box

  fill(255);
  textSize (20);
  textAlign(CENTER, CENTER);
  String t = "start";
  text(t, mouseX, mouseY);
}

void run() {
  fill(255);
  rect(0, 0, 500, 60);
  rect(0, 450, 500, 50);

  fill(0);
  textSize (12);
  textAlign(LEFT);

  String p = "category:\n";
  text(p + words[index], 15, 13, 60, 40);

  String o = "starting with your first line, you have 15 sec. \nto draw - or press enter if you're done!";
  text(o, 200, 25);   //to do: create text box aligned RIGHT but text in it aligned LEFT

  //line(10,60,490,60);

  String j = str(index+1)
    +"/"
    +str(words.length);  // using counter for categories submitted
  text(j, 15, 480);

  // String k = "00.15";
  text("Timer: "
    +nf((15000-(millis()-timer)) / 1000, 2, 0), 
    430, 480);  // using timer for time left

  if (millis()-timer>15000) {
    if (index>=words.length) {
      return; // LEAVE
    }
    state=2; 
    indexRND=int(random(words.length));
    // SaveAndPrepareNextWord();
  }
  //
}//func 

// ----------------------------------------------------------------------------
// Functions for INPUT

void mousePressed() {
  if (state==0) {
    // START SCREEN
    state=1; // go to drawing
    background(255);
    cursor(); 

    timer = millis();
  } else if (state==1) {
    // ignore
  } else if (state==2) {
    // go on
    SaveAndPrepareNextWord();
  }
}

void mouseDragged() {
  if (state==1) {
    fill(0);  
    stroke(0);
    float distanceX;
    float distanceY;

    distanceX = abs(mouseX - prevMouseX);
    distanceY = abs(mouseY - prevMouseY);

    float avDistance;
    avDistance = (distanceX + distanceY)/2;
    //set range for strokeWeight: squash 0-200 (input range) into 2-10 (output range) 
    avDistance = map(avDistance, 0, 150, 1, 50);

    //ellipse(mouseX, mouseY, 10, 10);
    //ellipse(mouseX, mouseY, avDistance, avDistance);

    prevMouseX = mouseX;
    prevMouseY = mouseY;

    //line(pmouseX,pmouseY,mouseX,mouseY);
    //strokeWeight(avDistance);
    line(pmouseX, pmouseY, prevMouseX, prevMouseY);
  }
}

void keyPressed() {
  switch(state) {
  case 0:
    //ignore
    break; 

  case 1: 
    state=2;
    indexRND=int(random(words.length));   // we need to improve this / to do 
    // SaveAndPrepareNextWord();
    break; 

  case 2:
    if (index>=words.length) {
      return; // LEAVE
    }
    SaveAndPrepareNextWord();
    break;
  }//switch
}//func 

// -------------------------------------------------------------------------
// Other functions 

void SaveAndPrepareNextWord() {

  // remove text !!!!!!!
  fill(250);
  noStroke(); 
  rect( 0, 0, width, 60); 

  // save now !!!!!
  String newName="drawings/"
    +words[index]
    + ".png";
  if (fileExists(sketchPath("")+""+newName)) {
    // problem: The file does already exist
    int i=0;

    while (fileExists(sketchPath("")+""+newName)) {

      newName="drawings/"
        +words[index] 
        +trim(str(i))
        + ".png";
      i++;
    }
    save(newName);
  } else {
    // It's a new file 
    save(newName);
  }

  // prepare next word !!!!  
  index++;
  background(250);
  textSize (40);
  textFont(F);
  fill(0);
  stroke(0);
  state=1; // go on 
  timer=millis();
}

boolean fileExists(String fileName) {
  File file=new File(fileName);
  boolean exists = file.exists();
  if (!exists) {
    println(fileName);
    return false;
  } else {

    return true;
  }
}
//


1 Like

Check out: GitHub - atduskgreg/opencv-processing: OpenCV for Processing. A creative coding computer vision library based on the official OpenCV Java API

OR boofCV: see: Libraries \ Processing.org

I also thought about how to go about it.

I just used a random number to display a pseudo feedback (identified emotion); you want to replace the random number with the recognized emotion.

I don’t know how the 2 programs in the links I posted work or whether they work for you. They are for image recognition.

  • When you check the current drawing, check the similarity to it for each image of each category separately and take the average of the similarity value for each category (emotion). Then each category has a score.
    The category with the highest score wins. Write it’s name/text on the screen.

so pseudo code:

get new image from user 
for loop over all emotions 
    for loop over all images of this emotion
           compare to new image -> score
           add score to sum1 
    }
    calc average from sum1/images number and store in an array (which is parallel to the emotion/words array)
}

//---

for loop over all emotions
      check the average score from array and pick the highest score
}

Chrisir

Ah that explains everything, should have known that Mac OS will do something weird. And what a wild concept that you can just assign states, I’m learning so much about processing rn :sweat_smile:
now we even have the switch statement that @debxyz suggested!

I solved the font problem too, mac apparently prefers otf or ttf.

1 Like

I have to admit I am not up to speed.

What I’ve been doing:
I tried to put the states in order (state0 aka start as first, then run, then feedback) but i got an error and I don’t understand why yet :see_no_evil:
And there is an issue with the saving (again)… The path is now correct and it runs nicely, however it crashed once I played the whole thing through till 28/28. BUT it saves only after giving feedback, and the drawing is gone by then.

int state = 0; 
//float x = 10;

float prevMouseX = 0;
float prevMouseY = 0;

PFont F;

int index = 0; // = int(random(words.length))
int indexRND; 

int timer;

final String[] words = {
  "amused", "joyful, cheerful", "energized, pumped up", 
  "annoyed", "excited", "anxious, tense", "dreamy", 
  "creeped out, scared", "disgusted, revolted", "angry", 
  "amazed, fascinated", "calm, realxed", "bored", "sad", 
  "flirty", "proud, couragous", "romantic, loving", 
  "confrontational, argumentative", "tender, longing", 
  "triumphant, heroic", "bittersweet, melancholic", 
  "euphoric, ecstatic", "disappointed", 
  "confused", "remorseful, sorry", "silly, goofy", 
  "jealous", "sympathetic, pitiful"
};

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

void setup() {
  size(500, 500);
  background(255);

  surface.setTitle("Emotive Drawing");
  surface.setResizable(true);
  surface.setLocation(100, 100);

  F = createFont("SportingGrotesque-Regular.otf", 50);
  textSize (50);
  textFont(F);

  noCursor(); 

  // timer = millis();
}

void draw() {
  if (state==0) {
    // START SCREEN
    startScreen();
  } else if (state==1) {
    // Drawing 
    run();
  } else if (state==2) {
    feedback();
  }
}

//-------------------------------------------------------------------------------------
// Functions called by draw() 

void feedback() {

  background(255);
  
  fill(0, 0, 255);
  ellipse(mouseX, mouseY, 160, 160);
  filter(BLUR, 4);

  fill(0);

  fill(0);
  textFont(F);
  textSize (12);
  textAlign(LEFT);
  String w = "Are you...";
  text(w, 15, 25);
  
  textAlign(CENTER);
  textSize (45);
  //text(str,the x-coordinate,  y-coordinate, width, height)
  text(words[indexRND]+"?", 15, 200, 470, 200);
  
  textSize (12);
  textAlign(LEFT);
  text("Press mouse for next emotion",15, 480);

  // go back to standard
  textSize (50);
  textAlign(LEFT);
}

void startScreen() {
  // START SCREEN

  background(255);

  fill(0, 0, 255);
  ellipse(mouseX, mouseY, 160, 160);
  filter(BLUR, 4);

  fill(0);
  textFont(F);
  String w = "emotive drawing";
  textSize (45);
  text(w, 250, 20);

  line(10, 60, 490, 60);

  textAlign(LEFT);
  textSize (12);
  String s = "Can we express emotions without words - only by drawing lines? \n"
    +"Let's teach a neural network, and find out it can learn to detect emotions in handwriting, drawings or font.";
  text(s, 15, 430, 485, 80);  // Text wraps within text box

  fill(255);
  textSize (20);
  textAlign(CENTER, CENTER);
  String t = "start";
  text(t, mouseX, mouseY);
}

void run() {
  //frameRate(200);
  fill(255);
  noStroke();
  rect(0, 0, 500, 60);
  rect(0, 450, 500, 50);

  fill(0);
  textSize (12);
  textAlign(LEFT);

  String p = "category:";
  text(p, 15, 25);
  text(words[index], 15, 40);

  String o = "starting with your first line, you have 15 sec. \nto draw - or press enter if you're done!";
  text(o, 150, 25);   //to do: create text box aligned RIGHT but text in it aligned LEFT
 
  stroke(0);
  line(10,60,490,60);

  String j = str(index+1)
    +"/"
    +str(words.length);  // using counter for categories submitted
  text(j, 15, 480);

  text("Timer: "
    +nf((15000-(millis()-timer)) / 1000, 2, 0), 
    400, 480);  // using timer for time left
    
    noStroke();

  if (millis()-timer>15000) {
    if (index>=words.length) {
      return; // LEAVE
    }
    indexRND=int(random(words.length));
    // SaveAndPrepareNextWord();
    state=2; //aka feedback
  }
  //
}//func 

// ----------------------------------------------------------------------------
// Functions for INPUT

void mousePressed() {
  if (state==0) {
    // START SCREEN
    state=1; // go to drawing
    background(255);
    cursor(); 

    timer = millis();
  } else if (state==1) {
    // ignore
  } else if (state==2) {
    // go on
    SaveAndPrepareNextWord();
  }
}

void mouseDragged() {
  if (state==1) {
    fill(0);  
    stroke(0);
    float distanceX;
    float distanceY;

    distanceX = abs(mouseX - prevMouseX);
    distanceY = abs(mouseY - prevMouseY);

    float avDistance;
    avDistance = 0;
    avDistance = (distanceX + distanceY)/2;
    //set range for strokeWeight: squash 0-200 (input range) into 2-10 (output range) 
    avDistance = map(avDistance, 0, 150, 1, 50);

    //ellipse(mouseX, mouseY, 10, 10);
    ellipse(mouseX, mouseY, avDistance, avDistance);

    prevMouseX = mouseX;
    prevMouseY = mouseY;

    //line(pmouseX,pmouseY,mouseX,mouseY);
    //strokeWeight(avDistance);
    //line(pmouseX, pmouseY, prevMouseX, prevMouseY);
  }
}

void keyPressed() {
  switch(state) {
  case 0:
    //ignore
    break; 

  case 1: 
    state=2;
    indexRND=int(random(words.length));   // we need to improve this / to do 
    // SaveAndPrepareNextWord();
    break; 

  case 2:
    if (index>=words.length) {
      return; // LEAVE
    }
    SaveAndPrepareNextWord();
    break; //Ends execution of a structure (here: switch) and jumps to the next statement after.
  }//switch
}//func 

// -------------------------------------------------------------------------
// Other functions 

void SaveAndPrepareNextWord() {

  // remove text !!!!!!!
  fill(250);
  //noStroke(); 
  rect( 0, 0, width, 60); 

  // save now !!!!!
  String newName="drawings/"
    +words[index]
    + ".png";
  if (fileExists(sketchPath("")+""+newName)) {
    // problem: The file does already exist
    int i=0;

    while (fileExists(sketchPath("")+""+newName)) {

      newName="drawings/"
        +words[index] 
        +trim(str(i))
        + ".png";
      i++;
    }
    save(newName);
  } else {
    // It's a new file 
    save(newName);
  }

  // prepare next word !!!!  
  index++;
  background(250);
  textSize (40);
  textFont(F);
  fill(0);
  stroke(0);
  state=1; // go on 
  timer=millis();
}

boolean fileExists(String fileName) {
  File file=new File(fileName);
  boolean exists = file.exists();
  if (!exists) {
    println(fileName);
    return false;
  } else {

    return true;
  }
}
//

I think I need some time to catch up and go through the basics.
Tomorrow morning I also have a meeting with two of my teachers (they don’t know anything about java but I asked them for feedback on the idea/design). I think i will show them what I have so far, and then come back here and read about open cv. Thank you for the input and links, it’s muuch appreciated!!

1 Like

It depends upon where you call this

But it changes state variable so remove this line

by the way, openCV is just a image recognition, not neural network (I think); so when you really want a neural network that’s learning, openCV is not the way to go.

here is a new version addressing your issues


final int START_SCREEN=0;
final int DRAWING = 1; 
final int FEEDBACK = 2; 
int state = 0; 

float prevMouseX = 0;
float prevMouseY = 0;

PFont F;

int index = 0; // = int(random(words.length))
int indexRND; 

int timer;

final String[] words = {
  "amused", "joyful, cheerful", "energized, pumped up", 
  "annoyed", "excited", "anxious, tense", "dreamy", 
  "creeped out, scared", "disgusted, revolted", "angry", 
  "amazed, fascinated", "calm, realxed", "bored", "sad", 
  "flirty", "proud, couragous", "romantic, loving", 
  "confrontational, argumentative", "tender, longing", 
  "triumphant, heroic", "bittersweet, melancholic", 
  "euphoric, ecstatic", "disappointed", 
  "confused", "remorseful, sorry", "silly, goofy", 
  "jealous", "sympathetic, pitiful"
};

// ---------------------------------------------------------------------------------
// Two Core functions 

void setup() {
  size(500, 500);
  background(255);

  surface.setTitle("Emotive Drawing");
  surface.setResizable(true);
  surface.setLocation(100, 100);

  F = createFont("ARIAL", 50); //  "SportingGrotesque-Regular.otf", 50);
  textSize (50);
  textFont(F);

  noCursor();
}

void draw() {
  if (state==START_SCREEN) {
    // START SCREEN
    startScreen();
  } else if (state==DRAWING) {
    // Drawing 
    run();
  } else if (state==FEEDBACK) {
    feedback();
  }
}

//-------------------------------------------------------------------------------------
// Functions called by draw() 

void startScreen() {
  // START SCREEN

  background(255);

  fill(0, 0, 255);
  ellipse(mouseX, mouseY, 160, 160);
  filter(BLUR, 4);

  fill(0);
  textFont(F);
  String w = "emotive drawing";
  textSize (45);
  text(w, 250, 20);

  line(10, 60, 490, 60);

  textAlign(LEFT);
  textSize (12);
  String s = "Can we express emotions without words - only by drawing lines? \n"
    +"Let's teach a neural network, and find out if it can learn to detect emotions in handwriting, drawings or font.";
  text(s, 15, 430, 485, 80);  // Text wraps within text box

  fill(255);
  textSize (20);
  textAlign(CENTER, CENTER);
  String t = "start";
  text(t, mouseX, mouseY);
}

void run() {
  fill(255);
  noStroke();
  rect(0, 0, 500, 60);
  rect(0, 450, 500, 50);

  fill(0);
  textSize (12);
  textAlign(LEFT);

  String p = "category:";
  text(p, 15, 25);
  text(words[index], 15, 40);

  String o = "starting with your first line, you have 15 sec. \nto draw - or press enter if you're done!";
  text(o, 150, 25);   //to do: create text box aligned RIGHT but text in it aligned LEFT

  stroke(0);
  line(10, 60, 490, 60);

  String j = str(index+1)
    +"/"
    +str(words.length);  // using counter for categories submitted
  text(j, 15, 480);

  text("Timer: "
    +nf((15000-(millis()-timer)) / 1000, 2, 0), 
    400, 480);  // using timer for time left

  noStroke();

  if (millis()-timer>15000) {
    if (index>=words.length) {
      return; // LEAVE
    }
    indexRND=int(random(words.length));
    SaveAndPrepareNextWord();
    state=2; //aka feedback
  }
  //
}//func 

void feedback() {

  background(255);

  fill(0, 0, 255);
  ellipse(mouseX, mouseY, 160, 160);
  filter(BLUR, 4);

  fill(0);

  fill(0);
  textFont(F);
  textSize (12);
  textAlign(LEFT);
  String w = "Are you...";
  text(w, 15, 25);

  textAlign(CENTER);
  textSize (45);
  //text(str,the x-coordinate,  y-coordinate, width, height)
  text(words[indexRND]+"?", 15, 200, 470, 200);

  textSize (12);
  textAlign(LEFT);
  text("Press mouse for next emotion", 15, 480);

  // go back to standard text
  textSize (50);
  textAlign(LEFT);
}

// ----------------------------------------------------------------------------
// Functions for INPUT

void mousePressed() {
  if (state==START_SCREEN) {
    // START SCREEN
    state=DRAWING; // go to drawing
    background(255);
    cursor(); 
    timer = millis();
  } else if (state==DRAWING) {
    // ignore
  } else if (state==FEEDBACK) {
    // go on
    state=DRAWING;
    timer=millis();
    // prepare next word !!!!  
    background(250);
    textSize (40);
    textFont(F);
    fill(0);
    stroke(0);
    index++;
    if (index>=words.length) {
      //state=END; 
      index=0;
    }//if
  }//else if
}

void mouseDragged() {
  if (state==DRAWING) {
    fill(0);  
    stroke(0);
    float distanceX;
    float distanceY;

    distanceX = abs(mouseX - prevMouseX);
    distanceY = abs(mouseY - prevMouseY);

    float avDistance;
    avDistance = 0;
    avDistance = (distanceX + distanceY)/2;
    //set range for strokeWeight: squash 0-200 (input range) into 2-10 (output range) 
    avDistance = map(avDistance, 0, 150, 1, 50);

    //ellipse(mouseX, mouseY, 10, 10);
    ellipse(mouseX, mouseY, avDistance, avDistance);

    prevMouseX = mouseX;
    prevMouseY = mouseY;

    //line(pmouseX,pmouseY,mouseX,mouseY);
    //strokeWeight(avDistance);
    //line(pmouseX, pmouseY, prevMouseX, prevMouseY);
  }
}

void keyPressed() {
  switch(state) {

  case START_SCREEN:
    //ignore
    break;  //Ends execution of a structure (here: switch) and jumps to the next statement after.

  case DRAWING: 
    state=FEEDBACK;
    prevMouseX = mouseX;
    prevMouseY = mouseY;
    SaveAndPrepareNextWord();
    indexRND=int(random(words.length));   // we need to improve this / to do 
    break;  //Ends execution of a structure (here: switch) and jumps to the next statement after.

  case FEEDBACK:
    // ignore
    break; //Ends execution of a structure (here: switch) and jumps to the next statement after.
  }//switch
  //
}//func 

// -------------------------------------------------------------------------
// Other functions 

void SaveAndPrepareNextWord() {

  // remove text !!!!!!!
  fill(250);
  //noStroke(); 
  rect( 0, 0, width, 60); 

  // save now !!!!!
  String newName="drawings/"
    +words[index]
    + ".png";
  if (fileExists(sketchPath("")+""+newName)) {
    // problem: The file name does already exist
    int i=0;

    while (fileExists(sketchPath("")+""+newName)) {

      newName="drawings/"
        +words[index] 
        +trim(str(i))
        + ".png";
      i++;
    }
  } 
  save(newName);
}

boolean fileExists(String fileName) {
  File file=new File(fileName);
  boolean exists = file.exists();
  return 
    exists;
}
//

1 Like

Hey hey @Chrisir, thank you for going through the code again! Now it’s not crashing anymore, and i have an overall idea what’s happening haha. I will definitely give you credit if this project is going anywhere!

So I got good feedback from my teachers, and I asked two people who have worked with AI before for help. I also thought about open cv, the problem would be to assign what attributes to look for, and what they mean right? Like “If you detect zig-zag-lines, the mood is angry”. It would be really cool to ask an AI to look for own parameters, and learn what defines the moods according to the collected data. But idk how to get there yet. :see_no_evil:

Maybe the next steps are to make an online version of the program?

1 Like

That’s one way to go. But not so good. A zig-zag-line is just YOUR understanding of angry.

Instead, when 10 people played your game, you have 10 images for each emotion. For a new image, the AI (openCV) checks which 10 images of each emotion are in average most similar to the new one (the emotion with the highest average score wins). I tried to describe this above. So you don’t rely on rules (zig-zag-line) but on the gathered images (more statistically).

The term AI

AI is a broad term though. OpenCV would not really qualify as AI. A neural network would. A neural network would learn (be trained) from your 10 example images for each emotion and then give answers. There must be libraries for this.

Check out Neural Network

tutorial 10.1: Introduction to Neural Networks - The Nature of Code - YouTube

check out the forum search Search results for 'neural' - Processing Foundation

for example Improving the accuracy of a neural network for digit recognition - #2 by SomeOne

Chrisir

I agree with @Chrisir OpenCV will not help you. Line drawing could may be transformed to a set of meaningful numbers for a machine learning model. Most of the work would be in finding those numeric representations. Depending a bit on image size you can use premade neural networks (transfer learning) and fine tune them to your images. I recon 100 images for each category is minimum. Naturally it doesn’t hurt to have more.
I have no experience with Java and neural networks. Python is by far most commonly used with machine learning and neural networks. You can do machine learning part with python and deploy the created model with Java.

1 Like

Hey @Chrisir that’s exactly what I mean, it would be a problem to set the parameters, and I’d rather use AI like I said in the description :slight_smile: I have seen some interesting projects using Generative adversarial networks (GANS, especially since StyleGAN2) and I would love to try that. But it’s not so easy to get a start haha. Maybe I should switch to python like SomeOne suggested :thinking:

1 Like

I stumbled upon a great little example for neual networks a while back in processing.

Its a simple network allows you to specify how deep you would like the network. It only makes use of the signoid function. And the sigmoid is calculated in setup to save computation time.

Do bear in mind that there are no filters or encoders its just the network and the neurons.

2 Likes

See Deep Vision - Machine Learning Computer Vision for Processing (Library)

1 Like