how the hell i can set the variable back to zero when i load a new image. i am going crazy.
it returns
Image selected at: 182012 , 1355817104 , img07.png, 1 , 0 , 0 , 20 , 83 , 293154 , 42415 , 8517 , 14811 , 20290 , 7146 , 4326 , 3005
Image selected at: 182012 , 1355918119 ,
img07.png, 1 , 0 , 0 , 14 , 78 , 105199 , 14096 , 2910 , 8611 , 4536 , 9777 , 1863 , 1027
Image selected at: 182012 , 13551019076 ,
img12.png, 1 , 0 , 0 , 30 , 63 , 73823 , 80886 , 51831 , 15865 , 10788 , 18704 , 12489 , 7433
Image selected at: 182012 , 13551120085 , img12.png, 1 , 0 , 0 , 26 , 63 , 162977 , 135127 , 39442 , 8595 , 21275 , 16270 , 8027 , 2529
what i need is that when a new image updates the mousePressed event return to 0 instead of returning 1.
this is the structure i am using
if (mouseX > 100 && mouseX < 120){
if (mouseY > 50 && mouseY < 80){
happy = 1;
//println("box 1");
//output.println("extremely unhappy");
} else{
happy = 0;
}
here is the full code
import neurosky.*;
import org.json.*;
ThinkGearSocket neuroSocket;
int attention=10;
int meditation=10;
int happy=0;
int excitement=0;
int dominance=0;
//-------------------------------
PrintWriter output;
String imageFolderPath = "C:/Users/FerranGaldon/Desktop/final projects MA/- PROCESSING/_10_self_assesment_click_hard_code/data";
File[] files;
PImage[] images;
//-------------------------------
int counter; // Automatically initialized at 0
final int DISPLAY_TIME = 5000; // 15000 ms = 15 seconds
int lastTime; // When the current image was first displayed
//--------------------------------
int numCircles = 27;
int [][] circles; // use a two-dimensional array
//--------------------------------
PImage b;
int value = 150;
//--------------------------------
void setup () {
// Create a new file in the sketch directory
output = createWriter("positions.txt");
size(1024, 350);
//smooth();
//noStroke();
ThinkGearSocket neuroSocket = new ThinkGearSocket(this);
try {
neuroSocket.start();
}
catch (ConnectException e) {
//println("Is ThinkGear running??");
}
smooth();
circles = new int [numCircles][3]; // define the array, every circle needs three parameters (xPos, yPos, circleDiameter)
// fill array only once
for (int i=0; i<numCircles; i++) {
int circleDiameter = int(23);
int xPos = int(109); // keep distance from border
int yPos = int(67); // keep distance from border
circles[i][0]= xPos + (i % 9) * 38; //horizontal position
circles[i][1]= yPos + (i / 9) * 135;//vertical position
circles[i][2]= circleDiameter;
}
//Random Image array upload and timer
File imageFolder = new File(imageFolderPath);
files = imageFolder.listFiles(new FileFilter()
{
public boolean accept(File file)
{
if (file.isDirectory())
return false; // Only files. A directory can have a dot in its name...
String name = file.getName();
return name.endsWith(".png");// in case you want to extend > name.endsWith(".jpg") || name.endsWith(".png") || name.endsWith(".gif");
}
});
images = new PImage[files.length];
for (int i = 0; i < files.length; i++)
{
images[i] = loadImage(files[i].getAbsolutePath());
}
randomizeImages();
lastTime = millis();
}
void draw() {
// Images time display
background(255);
fill(#005599);
text(frameCount, 10, 20); // Shows the sketch isn't stopped between each image
if (millis() - lastTime >= DISPLAY_TIME) // Time to display next image
{
counter++;
if (counter == files.length) // Or IMAGE_NB
{
// Displayed all images, re-randomize the images
randomizeImages();
}
lastTime = millis();
}
image(images[counter], 552, 0, width - 582, height);
b = loadImage("manikin.jpg");
image(b, 0, 0, width/2, height);
for (int i=0; i<numCircles; i++) {
fill(value);
stroke(20);
ellipse(circles[i][0], circles[i][1], circles[i][2],circles[i][2]);
}
}
void poorSignalEvent(int sig) {
println("SignalEvent "+sig);
}
public void attentionEvent(int attentionLevel) {
println("Attention Level: " + attentionLevel);
attention = attentionLevel;
}
void meditationEvent(int meditationLevel) {
println("Meditation Level: " + meditationLevel);
meditation = meditationLevel;
}
void happyEvent(int happyLevel) {
println("Happy Level: " + happyLevel);
happy = happyLevel;
}
void excitementEvent(int escitementLevel) {
println("Excitement Level: " + escitementLevel);
excitement = escitementLevel;
}
void dominanceEvent(int dominanceLevel) {
println("Excitement Level: " + dominanceLevel);
dominance = dominanceLevel;
}
void blinkEvent(int blinkStrength) {
println("blinkStrength: " + blinkStrength);
}
void randomizeImages()
{
for (int i = images.length - 1; i > 0; i--)
{
int j = int(random(i + 1));
// Swap
PImage ti = images[i];
images[i] = images[j];
images[j] = ti;
// Swap
File tf = files[i];
files[i] = files[j];
files[j] = tf;
}
}
public void eegEvent(int delta, int theta, int low_alpha, int high_alpha, int low_beta, int high_beta, int low_gamma, int mid_gamma) {
println("delta Level: " + delta);
println("theta Level: " + theta);
println("low_alpha Level: " + low_alpha);
println("high_alpha Level: " + high_alpha);
println("low_beta Level: " + low_beta);
println("high_beta Level: " + high_beta);
println("low_gamma Level: " + low_gamma);
println("mid_gamma Level: " + mid_gamma);
File tf = files[counter];
output.println("Image selected at: "+day()+month()+year()+" , "+hour()+minute()+second()+millis()+" , "+ tf.getName()+ ", " + happy + " , " + excitement + " , " + dominance + " , " + attention + " , " + meditation + " , " + delta + " , " + theta + " , " + low_alpha + " , " + high_alpha + " , " + low_beta + " , " + high_beta + " , " + low_gamma + " , " + mid_gamma);
output.flush(); // Writes the remaining data to the file
}
void rawEvent(int[] raw) {
//println("rawEvent Level: " + raw);
}
void stop() {
neuroSocket.stop();
super.stop();
}
void mousePressed(){
//So set the variable back to zero when you load a new image.
//row 1
if (mouseX > 100 && mouseX < 120){
if (mouseY > 50 && mouseY < 80){
happy = 1;
//println("box 1");
//output.println("extremely unhappy");
} else{
happy = 0;
}
if (mouseY > 190 && mouseY < 210){
excitement = 1;
//println("box 10");
//output.println("extremely relaxed");
} else {
excitement = 0;
}
if (mouseY > 330 && mouseY < 350){
dominance = 9;
//println("box 19");
//output.println("extremely dominant");
}else {
dominance = 0;
}
}
//row 2
if (mouseX > 138 && mouseX < 158){
if (mouseY > 50 && mouseY < 80){
happy = 2;
// println("box 2");
//output.println("very unhappy");
} else {
happy = 0;
}
if (mouseY > 190 && mouseY < 210){
excitement = 2;
//println("box 11");
//output.println("very relaxed");
}else {
excitement = 0;
}
if (mouseY > 330 && mouseY < 350){
dominance = 8;
//println("box 20");
//output.println("very dominant");
}else {
dominance = 0;
}
}
//row 3
if (mouseX > 180 && mouseX < 200){
if (mouseY > 50 && mouseY < 80){
happy = 3;
//println("box 3");
//output.println("quite unhappy");
} else {
happy = 0;
}
if (mouseY > 190 && mouseY < 210){
excitement = 3;
//println("box 12");
//output.println("quite relaxed");
}else {
excitement = 0;
}
if (mouseY > 330 && mouseY < 350){
dominance = 7;
//println("box 21");
//output.println("quite dominant");
}else {
dominance = 0;
}
}
//row 4
if (mouseX > 210 && mouseX < 230){
if (mouseY > 50 && mouseY < 80){
happy = 4;
//println("box 4");
//output.println("unhappy");
} else {
happy = 0;
}
if (mouseY > 190 && mouseY < 210){
excitement = 4;
//println("box 13");
//output.println("relaxed");
}else {
excitement = 0;
}
if (mouseY > 330 && mouseY < 350){
dominance = 6;
//println("box 22");
//output.println("dominant");
}else {
dominance = 0;
}
}
//row 5
if (mouseX > 250 && mouseX < 270){
if (mouseY > 50 && mouseY < 80){
happy = 5;
//println("box 5");
//output.println("pleasure neutral");
} else {
happy = 0;
}
if (mouseY > 190 && mouseY < 210){
excitement = 5;
//println("box 14");
//output.println("arousal neutral");
}else {
excitement = 0;
}
if (mouseY > 330 && mouseY < 350){
dominance = 5;
//println("box 23");
//output.println("dominance neutral");
}else {
dominance = 0;
}
}
//row 6
if (mouseX > 290 && mouseX < 310){
if (mouseY > 50 && mouseY < 80){
happy = 6;
//println("box 6");
//output.println("happy");
} else {
happy = 0;
}
if (mouseY > 190 && mouseY < 210){
excitement = 6;
//println("box 15");
//output.println("excited");
}else {
excitement = 0;
}
if (mouseY > 330 && mouseY < 350){
dominance = 4;
//println("box 24");
//output.println("not dominant");
}else {
dominance = 0;
}
}
//row 7
if (mouseX > 330 && mouseX < 350){
if (mouseY > 50 && mouseY < 80){
happy = 7;
//println("box 7");
//output.println("quite happy");
} else {
happy = 0;
}
if (mouseY > 190 && mouseY < 210){
excitement = 7;
//println("box 16");
//output.println("quite excited");
}else {
excitement = 0;
}
if (mouseY > 330 && mouseY < 350){
dominance = 3;
//println("box 25");
//output.println("not quite dominant");
}else {
dominance = 0;
}
}
//row 8
if (mouseX > 370 && mouseX < 390){
if (mouseY > 50 && mouseY < 80){
happy = 8;
//println("box 8");
//output.println("very happy");
} else {
happy = 0;
}
if (mouseY > 190 && mouseY < 210){
excitement = 8;
//println("box 17");
//output.println("very excited");
}else {
excitement = 0;
}
if (mouseY > 330 && mouseY < 350){
dominance = 2;
//println("box 26");
//output.println("not very dominant");
}else {
dominance = 0;
}
}
//row 9
if (mouseX > 400 && mouseX < 420){
if (mouseY > 50 && mouseY < 80){
happy = 9;
//println("box 9");
//output.println("extremly happy");
} else {
happy = 0;
}
if (mouseY > 190 && mouseY < 210){
excitement = 9;
//println("box 18");
//output.println("extremly excited");
}else {
excitement = 0;
}
if (mouseY > 330 && mouseY < 350){
dominance = 1;
//println("box 27");
//output.println("extremeli not dominant");
}else {
dominance = 0;
}
}
output.flush(); // Writes the remaining data to the file
}
void exit(){
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
super.exit();
}
1