How many times is code executed inside Draw if (mousePressed)?
in
Programming Questions
•
3 months ago
Hello everyone :)
- void setup() {
- }
- void draw() {
- println("...");
- if (mousePressed) {
- println("mouse is pressed");
- }
- }
Its result (just after clicking mouse only ONCE!):
...
...
...
mouse is pressed
...
mouse is pressed
...
mouse is pressed
...
mouse is pressed
...
...
...
...
I want to call twitter search API inside Draw() but apparently I want the code to be executed only once when a user clicks. Otherwise, the method will hit rate limits of the API.
Below is the actual code I am using in Draw() method, but everytime I get Rate Limit hits from Twitter:
- if (mousePressed) {
- //country selection
- int px = constrain(mouseX, 0, width);
- int py = constrain(mouseY, 0, height);
- int v = mapImage.pixels[py*mapImage.width + px];
- v = int(red(v) / 2);
- v = (int) constrain(v, 0, countries.length-1);
- lastselection = countries[v] + "";
- //country selection ends here
- //chooseing country and returning woeid of the location
- for (int j = 0; j<trendingLocations.size();j++) {
- if (lastselection.equals(trendingLocations.get(j))==true) {
- woeid = trendingLocationIDs.get(j);
- }
- }
- println(woeid);
- //retrieve trends for the given woeid
- trends.GetTrends(woeid);
- search = new Search();
- search.draw();
- }
1