FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   MouseReleased() confusion
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: MouseReleased() confusion  (Read 511 times)
rgovostes

rgovostes
MouseReleased() confusion
« on: Sep 3rd, 2003, 10:55pm »

Code:
void setup() {
  size(300, 300);
  noBackground();
}
 
void mouseReleased() {
  fill(0, 0, 0);
  ellipse(mouseX, mouseY, 5, 5);
}

 
For some reason, whatever I do in the mouseReleased event doesn't happen. The example works for me, though I notice it uses a loop. Is there no way to draw directly from the mouseReleased event?
 
vent

WWW
Re: MouseReleased() confusion
« Reply #1 on: Sep 4th, 2003, 12:04am »

Not sure why exactly, but you just need to throw in the loop method for it to work.
 
Code:

void setup() {  
  size(300, 300);  
  noBackground();  
}  
 
 
void loop(){
 
}
 
void mouseReleased() {  
  fill(0, 0, 0);  
  ellipse(mouseX, mouseY, 5, 5);  
}  

 

http://www.shapevent.com/
rgovostes

rgovostes
Re: MouseReleased() confusion
« Reply #2 on: Sep 4th, 2003, 12:21am »

Hmm, thanks. Perhaps this is a bug?
 
I also noticed that this part
 
Code:
void mouseReleased() {
  fill(0, 0, 0);
  ellipse(mouseX, mouseY, 5, 5);
}

 
... does not generate a perfect circle?
« Last Edit: Sep 4th, 2003, 12:26am by rgovostes »  
arielm

WWW
Re: MouseReleased() confusion
« Reply #3 on: Sep 4th, 2003, 12:44am »

a bug, or maybe a design issue?
 
please take a look at:
Code:
void setup()
{  
  size(500, 500);  
}  
 
void loop()
{  
}  
 
void mouseMoved()
{  
  fill(0, 0, 0);  
  ellipse(mouseX, mouseY, 50, 50);  
}

 
with this one, the display is totally flickered!
 
technically, i think it's due to the fact that mouse events are processed in a parallel java thread, but for the "user", it should'nt matters (i mean, we should expect something similar as in director, dhtml or flash, where there can't be multiple scripts executed in parallel, by design)
 
but maybe all this have been already discussed, and is a well-known issue?
 
anyway, to my current knowledge, it's not clearly defined what it's possible to do (and what not) within mouse and keyboard events...
 
?
 

Ariel Malka | www.chronotext.org
vent

WWW
Re: MouseReleased() confusion
« Reply #4 on: Sep 4th, 2003, 3:14am »

on Sep 4th, 2003, 12:21am, rgovostes wrote:

 
... does not generate a perfect circle

 
adding smooth() to your setup method will clean up the ellipse but you may not want anti-aliasing on.
 

http://www.shapevent.com/
benelek

35160983516098 WWW Email
Re: MouseReleased() confusion
« Reply #5 on: Sep 4th, 2003, 8:39am »

whenever you start a sketch with setup(), you need either a loop() or a draw(). things like mouse events are optional.
 
toxi

WWW
Re: MouseReleased() confusion
« Reply #6 on: Sep 4th, 2003, 12:22pm »

re: unperfect circle - this would have to do with the algorithm we use to adapt the number of circle segments to the actual circle size, so when drawing small circles it's using considerably less than larger ones. it does speed up drawing, but IMHO still needs tweaking for extreme small radii... the results are better when you turn off stroking for ellipses (use noStroke(); in setup)
 
re: flickering - ariel, this really has to do with parallel threads for the loop() method and another one to process events. however, the flickering occurs because the mousePressed() will interrupt the loop() method and the ellipse is drawn immediately. then in your example, the screen is cleared again the moment Processing is starting a new frame and re-enters the loop method (which normally is responsible to update the screen). the original example used noBackground().
« Last Edit: Sep 4th, 2003, 12:22pm by toxi »  

http://toxi.co.uk/
arielm

WWW
Re: MouseReleased() confusion
« Reply #7 on: Sep 4th, 2003, 1:40pm »

toxi, i was just saying that for the average user (like those coming from flash or director), the multi-threading story behind is not relevant.
 
i was trying to bring the discussion to a non-technical level: what should be expected within mouse and keyboard events, because for now, it's not clearly said that drawing operations should be avoided there and only permited within loop().
 
if what makes the strength of P5 is the ability for beginners to do intuition-based programming without dealing with all the plumbery behind, then we should expect to be able to draw a circle within a mouseEvent, no?
 

Ariel Malka | www.chronotext.org
toxi

WWW
Re: MouseReleased() confusion
« Reply #8 on: Sep 4th, 2003, 2:28pm »

on Sep 4th, 2003, 1:40pm, arielm wrote:
i was trying to bring the discussion to a non-technical level: what should be expected within mouse and keyboard events, because for now, it's not clearly said that drawing operations should be avoided there and only permited within loop().

arielm, i do understand/appreciate you tried that, but it's is totally feasible to do drawing operations within mouse/keyboard events in P5. you only have to make sure you turn off background refreshs in order to keep those changes. i don't think that's something you can call un-intuitive. you know yourself, programming is applied logic, so i think it has more to do with that. that threading stuff i only repeated to explain the flickering, because you seemed surprised about that behaviour. though the reference for background() clearly states: "In the loop() function, the background color is used to refresh the display window between frames."
 
it is true that using P5 should make sense without knowing what's going on under the hood, but freedom of expression (compared to flash etc.) always comes at a price and this mainly is knowledge and taking responsibility for your (non)actions. the tool can only help paving the way, but the ultimate goal for the new user should always be to understand the underlying concepts. no
 
to compare the above example to drawing an ellipse upon mouse click in flash is not strictly fair, as in flash you actually are creating a new object (in the shape of an ellipse) which is then just another movieclip added to the render queue. this is again the classic conceptual difference between pixel graphics (stateless direct data manipulation) and vector graphics (objects within a render pipeline).
 
maybe we should create a new thread about that - you wanna
 

http://toxi.co.uk/
arielm

WWW
Re: MouseReleased() confusion
« Reply #9 on: Sep 4th, 2003, 3:38pm »

good idea (having a new thread!)
 
http://proce55ing.net/discourse/yabb/board_Proce55ing_Software__action_display_num_1062682517.html
 

Ariel Malka | www.chronotext.org
fry


WWW
Re: MouseReleased() confusion
« Reply #10 on: Sep 4th, 2003, 6:22pm »

i've responded to the mouse issue in that other thread.. but re: the loop() and draw() not running.. that *is* a design issue, that you need one or the other, otherwise it's not a valid p5 app.  
 
i guess i'll add something to provide an error message when that happens.
 
the problem is, you need one or the other, since there's no way to know whether you intend for it to be a draw mode app (just drawing something static) or something that's a loop (waiting for mouse events). i could default to loop, but it would be confusing since a static image drawn only in setup (for instance) would keep running inexplicably.
« Last Edit: Sep 4th, 2003, 6:24pm by fry »  
Pages: 1 

« Previous topic | Next topic »