We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › clear array if mousreleased
Page Index Toggle Pages: 1
clear array if mousreleased (Read 821 times)
clear array if mousreleased
May 1st, 2009, 6:10am
 
hello

i want to modify the storing-input example http://www.processing.org/learning/basics/storinginput.html

just if the mouse button is pressed, the blobs should be visible.

the problem is, if i release und press the mouse button again then is visible the old tail.

how can i realize that the old tail will delete, if i release the mouse button

Code:
int num = 60;
float mx[] = new float[num];
float my[] = new float[num];

void setup()
{
 size(200, 200);
 smooth();
 noStroke();
 fill(255, 153);
}

void draw()
{
 background(51);
 
 // Reads throught the entire array
 // and shifts the values to the left

 for(int i=1; i<num; i++) {
   mx[i-1] = mx[i];
   my[i-1] = my[i];
 }
 // Add the new values to the end of the array
 mx[num-1] = mouseX;
 my[num-1] = mouseY;
 if (mousePressed == true){
 for(int i=0; i<num; i++) {
   ellipse(mx[i], my[i], i/2, i/2);
 }}
}
Re: clear array if mousreleased
Reply #1 - May 1st, 2009, 6:38am
 
Code:
Arrays.fill(mx, 0); 

Re: clear array if mousreleased
Reply #2 - May 1st, 2009, 7:27am
 
thanks

but why is in the top left corner a blob, if i press the mouse button?

Code:
int num = 60;
float mx[] = new float[num];
float my[] = new float[num];

void setup()
{
size(200, 200);
smooth();
noStroke();
fill(255, 153);
}

void draw()
{
background(51);

for(int i=1; i<num; i++) {
mx[i-1] = mx[i];
my[i-1] = my[i];
}
mx[num-1] = mouseX;
my[num-1] = mouseY;
if (mousePressed == true){
for(int i=0; i<num; i++) {
ellipse(mx[i], my[i], i/2, i/2);
}}
else {
Arrays.fill(mx, 0);
Arrays.fill(my, 0);
}

}
Page Index Toggle Pages: 1