OK, seriously, here is an old sketch I did, meanwhile I added your constraint:
Code:int queueSize = -1; // Was 50 before the change
ArrayDeque lines;
void setup()
{
size(700, 700);
frameRate(40);
lines = new ArrayDeque();
noFill();
ellipseMode(CENTER);
noLoop();
PFont f = createFont("Verdana", 16);
textFont(f);
}
void draw()
{
background(128, 128, 255);
if (queueSize < 0)
{
text("Type a number between 1 and 9", 10, 20);
return;
}
if (mouseX != pmouseX || mouseY != pmouseY)
{
PVector p = new PVector(mouseX, mouseY);
lines.addFirst(p);
}
if (lines.size() > queueSize)
{
lines.removeLast();
}
Iterator it = lines.iterator();
PVector pp = null;
while (it.hasNext())
{
PVector cp = (PVector) it.next();
if (pp != null)
{
stroke(14, 7, 42);
strokeWeight(1);
line(pp.x, pp.y, cp.x, cp.y);
stroke(214, 7, 142);
strokeWeight(5);
ellipse(cp.x, cp.y, 21, 21);
}
pp = cp;
}
}
void keyReleased()
{
int number = int(key) - int('0');
if (number > 0)
{
println(number);
queueSize = 10 * number;
loop();
}
}
It can be improved on GUI side, but basically it does what you need.
I highlighted the parts I added, as the code itself isn't really important.
[EDIT] Funny, Cedric was faster than me at coding, we came up independently at basically the same implementation, with little variants.