Hi,
I'm taking a basic programming course at my university and I just startet programming a month ago. To complete my course, I have to hand in a psychological program which I programmed myself. I've chosen for the "Ponzo Illusion Task" and I already began with it some time ago.
For those who do not know the "Ponzo Illusion Task": you get 2 lines, one is of fixed random length, the other one is manipulable by the participant. The participant's task is to make both lines equally long. This process is hindered by some background lines which make it difficult to simply compare the lengths of the lines.
I set up the background lines and programmed some buttons, which I want to use later (actually I do not want to use keys, but simply the eventhandler 'mousePressed', but I use the keys for now) and I started programming the 2 lines. I somehow used the command "rect" with the Center-mode and with h=0 for these lines, because it's simpler to make the lines longer or shorter.
I also began to program that the second line (I simply call it rect2 from now on) becomes shorter when I press key 's', but it simply does nothing...
When I press 'l' for longer, .... it's becoming longer, but I cannot find my mistake in the shorter part...
Can someone please help me with that? This might be a simple question, but I'm only a beginner tho.
Thanks in advance!
This is my code:
I'm taking a basic programming course at my university and I just startet programming a month ago. To complete my course, I have to hand in a psychological program which I programmed myself. I've chosen for the "Ponzo Illusion Task" and I already began with it some time ago.
For those who do not know the "Ponzo Illusion Task": you get 2 lines, one is of fixed random length, the other one is manipulable by the participant. The participant's task is to make both lines equally long. This process is hindered by some background lines which make it difficult to simply compare the lengths of the lines.
I set up the background lines and programmed some buttons, which I want to use later (actually I do not want to use keys, but simply the eventhandler 'mousePressed', but I use the keys for now) and I started programming the 2 lines. I somehow used the command "rect" with the Center-mode and with h=0 for these lines, because it's simpler to make the lines longer or shorter.
I also began to program that the second line (I simply call it rect2 from now on) becomes shorter when I press key 's', but it simply does nothing...
When I press 'l' for longer, .... it's becoming longer, but I cannot find my mistake in the shorter part...
Can someone please help me with that? This might be a simple question, but I'm only a beginner tho.
Thanks in advance!
This is my code:
- //Defining global variables
int canvasWidth = 600;
int canvasHeight = 600;
//variables for vertical lines
float lineX1 = canvasWidth/2;
float lineY1 = canvasHeight/8;
float lineY2 = canvasHeight * 6/8;
color bgColor = color (255,255,255);
color lineColor = color (0,0,0);
float dist = 50; //Distance between vertical lines
//Declaration and creation of the array to hold the values for the X2 coordinates of the vertical lines
float [] arrayOfLineX2 = {lineX1,lineX1-dist,lineX1+dist,lineX1-2*dist,lineX1+2*dist,lineX1-3*dist,lineX1+3*dist};
// variables for randomly given horizontal line
float rectX1 = 300;
float rectY1 = 275;
float rectW1 = random(110,160);
// variables for horizontal line that user can change in every trial
float rectY2 = 350;
float rectW2 = 130;
boolean shorterbutton = false;
// values for both horizontal lines
float rectH = 0;
//Variables for Buttons
float circleX = 50;
float circleY = 550;
float circleW = 50;
float circleH = 50;
//Declare and create array for the X coordinates of the buttons
float [] arrayOfButtonX = {circleX,circleX+500,circleX+125,circleX+200,circleX+350};
void setup () { // drawing canvas with white backgroundcolor
size(canvasWidth,canvasHeight);
background(bgColor);
}
void draw() { //draw the
stroke(0);
//drawing the "standard" seven vertical lines, later on programming "min" and "meer" button to make more or fewer lines
drawLines(lineX1, lineY1, arrayOfLineX2[0], lineY2);
drawLines(lineX1, lineY1, arrayOfLineX2[1], lineY2);
drawLines(lineX1, lineY1, arrayOfLineX2[2], lineY2);
drawLines(lineX1, lineY1, arrayOfLineX2[3], lineY2);
drawLines(lineX1, lineY1, arrayOfLineX2[4], lineY2);
drawLines(lineX1, lineY1, arrayOfLineX2[5], lineY2);
drawLines(lineX1, lineY1, arrayOfLineX2[6], lineY2);
//Draw Buttons for making the ZAP interactive
drawButtons(arrayOfButtonX[0], circleY, circleW, circleH); //HELPbutton
fill(0);
text("Help",38,555);
drawButtons(arrayOfButtonX[1], circleY, circleW, circleH); //Exitbutton
fill(0);
text("Exit",540,555);
drawButtons(arrayOfButtonX[2], circleY, circleW, circleH); //Shorterbutton
fill(0);
text("Shorter",155,555);
drawButtons(arrayOfButtonX[3], circleY, circleW, circleH); //Longerbutton
fill(0);
text("Longer",230,555);
drawButtons(arrayOfButtonX[4], circleY, circleW, circleH); // CheckButton
fill(0);
text("Check",380,555);
//draw rectangle with height 0 to draw the randomly given horizontal line, use CENTER-Mode for making width change possible (for each trial)
rectMode(CENTER);
rect(rectX1,rectY1,rectW1,rectH);
//draw 2nd rectangle with height 0 to draw the horizontal line that user can change in every trial
rectMode(CENTER);
rect (rectX1, rectY2, rectW2, rectH);
}
void drawLines(float lineX1, float lineY1, float arrayOfLineX2, float lineY2) {
stroke(0);
line(lineX1, lineY1, arrayOfLineX2, lineY2);
}
//Procedure that only draws the buttons
void drawButtons(float arrayOfButtonX, float circleY, float circleW, float circleH) {
stroke(0);
fill(0,255,255);
ellipseMode(CENTER);
ellipse(arrayOfButtonX,circleY,circleW,circleH);
}
void keyPressed () {
if (key == 'l') {
rect(rectX1, rectY2, rectW2, rectH);
rectW2= rectW2+5;
constrain (rectW2, 130,160);
}
if (key == 's') {
rect (rectX1, rectY2, rectW2, rectH);
rectW2 = rectW2-5;
}
}
1