Reputation: 24998
I have a very basic Processing sketch that will allow me to draw a line like in MS-Paint. Here it is:
void setup(){
size(640,480);
background(255);
}
void mouseDragged(){
line(pmouseX,pmouseY,mouseX,mouseY);
}
However, when I click and drag the mouse nothing happens.
What is going wrong ?
Upvotes: 0
Views: 121
Reputation: 974
This is the correct code:
void setup(){
size(640,480);
background(255);
}
void draw () {
}
void mouseDragged(){
line(pmouseX,pmouseY,mouseX,mouseY);
}
You need to explicitly tell the program to loop; you can find a more detailed description of the draw() function in the Processing Reference:
Called directly after setup(), the draw() function continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called.
There can only be one draw() function for each sketch, and draw() must exist if you want the code to run continuously, or to process events such as mouseDragged().
If you're looking for a nice Processing introduction, check out Processing site's tutorials and Jose Sanchez's Video Tutorial.
Upvotes: 4