The screen is updated every time draw() is finished and only when draw() is finished, looped or not. If you have something in a for loop in draw(), every iteration gets drawn before the draw() is ended and result is displayed on screen.
Therefor, in animation, you have to control the iteration for every loop of the draw(), and in your case also have a switch checked. For example like this:
Code:
float initx, inity, initangle, hlength, sangle, trotation, val;
boolean lowval;
boolean mouseSwitch=false; // This is a new one
float i; // The for loop i variable is now global
void setup(){
size(600,600);
background(70);
strokeWeight(15);
framerate(69);
}
void mouseReleased(){
initx = mouseX;
inity = mouseY;
initangle = PI/3;
hlength = 200;
sangle = PI/24;
trotation = 4*PI;
val = 0;
lowval = true;
mouseSwitch=true; // Set switch if mouse is clicked
i=initangle; // Same as in your for loop
}
void draw(){
if(mouseSwitch){ // If clicky, lets do something
i+=sangle; // Same as in your for loop
stroke(val);
hlength = hlength-0.8;
if(val==256){ lowval = !lowval; }
if(lowval){ val+=2; }
else if(!lowval){ val-=2; }
if(val==0){ lowval = true; }
// Moved down to be after calculations
line(initx, inity, sin(i)*hlength+initx, cos(i)*hlength+inity);
// Same as in your for loop, switch off when finished the spiral
if(hlength<=0) mouseSwitch=false;
delay(250);
}
}