Continuous Line
Notice the gaps between dots in the first drawing programs. That's because the mouse position is only checked each frame, but it doesn't necessarily travel through all the points between Point A and Point B. To draw a continuous line you need to know not only where the mouse is NOW, but where it WAS.pmouseX : built-in variable; Previous MouseX
pmouseY: previous MouseY
void setup ()
{
size(640,480);
background(255);
stroke(0);
fill(0);
}
void draw()
{
line(mouseX,mouseY,pmouseX,pmouseY);
}
If you want to draw only when the mouse button's pressed, just use the mousePressed variable.
void setup ()
{
size(640,480);
background(255);
stroke(0);
fill(0);
}
void draw()
{
if (mousePressed)
{
line(mouseX,mouseY,pmouseX,pmouseY);
}
}
The stroke() function changes color, but it can also change the opacity of the stroke if you give it a fourth number.
void setup ()
{
size(640,480);
background(255);
stroke(0,0,0,32);
}
void draw()
{
if (mousePressed)
{
line(mouseX,mouseY,pmouseX,pmouseY);
}
}