<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with thread() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=thread%28%29</link>
      <pubDate>Sun, 08 Aug 2021 18:56:07 +0000</pubDate>
         <description>Tagged with thread() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedthread%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How do I register pressing keys tabbed out of the application window</title>
      <link>https://forum.processing.org/two/discussion/28072/how-do-i-register-pressing-keys-tabbed-out-of-the-application-window</link>
      <pubDate>Fri, 13 Jul 2018 23:10:10 +0000</pubDate>
      <dc:creator>CentricArts</dc:creator>
      <guid isPermaLink="false">28072@/two/discussions</guid>
      <description><![CDATA[<p>Currently trying to make a over complicated software to run alongside other software and I'm currrently trying to get something to register colour changes in pixels while holding down a key. However, after trying to figure out why my idea wasn't working after 2 hours of messing around, pressing keys aren't registered while tabbed out of the application window.</p>

<p>Is there a way around it?</p>

<pre><code>import java.awt.Rectangle;
import java.awt.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.AWTException;
import java.awt.event.InputEvent;
import java.awt.event.KeyListener;

PImage screenshot;
int PixelY;
int PixelX;
int Trigger;
int buttons;
Robot robot;
int triggerkey;

static final String RENDERER = FX2D;
static final int FPS = 60, DELAY = 100/FPS/4, SMOOTH = 3;

void setup() {
  size(1920, 1080, RENDERER);

  smooth(SMOOTH);
  frameRate(FPS);
  imageMode(CORNER);

  screenshot = createImage(displayWidth, displayHeight, ARGB);
  thread("screenshotThread");
  //
  try { 
    robot = new Robot();
  } catch (AWTException e) {
    e.printStackTrace();
    exit();
  }
}

void draw() {
  image(screenshot, 0, 0, width, height);
  frame.setTitle("FPS : " + round(frameRate));
  fill(1,1,1);
  rect((1920/2),(1080/2+1),1,1);
  PixelX = get((1920/2),(1080/2));

  if(PixelY != PixelX){
    print("Trigger Enabled");
      Trigger = 1;
  } 

  if (PixelY == PixelX){
    Trigger = 0;
  } else {
    Trigger = 1;
    println("Toggled");
  }
  delay(1);
  PixelY = get((1920/2),(1080/2));

  print("(");
  print(PixelY);
  print(":");
  print(PixelX);
  print("(");
  println();
  if (keyPressed) {
    println(true);
    if(key == 'f'){
      println("Holding");
      triggerkey = 1;
    }
  } else { 
      triggerkey = 0;
      println(false);
  }
}

void screenshotThread(){
  final PImage shot = screenshot;
  final Rectangle dimension = new Rectangle(displayWidth, displayHeight);
  final Robot robot;

  try {
    robot = new Robot();
  }

  catch (AWTException cause) {
    exit();
    throw new RuntimeException(cause);
  }
  for (;; delay(DELAY))  grabScreenshot(shot, dimension, robot);
}

static final PImage grabScreenshot(PImage img, Rectangle dim, Robot bot) {
  bot.createScreenCapture(dim).getRGB(
    0, 0, 
    dim.width, dim.height, 
    img.pixels, 0, dim.width);

  img.updatePixels();
  return img;
}

void alt(KeyEvent e){
  if(e.getKeyCode() == 18){
  }
}

void keypressed(){
  if(triggerkey == 1){
    if(Trigger == 1){
       robot.mousePress(InputEvent.BUTTON1_MASK); 
       robot.mouseRelease(InputEvent.BUTTON1_MASK);
       print("Active");
       println("");
       delay(450);
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Multiple videos smoothness - threaded playback</title>
      <link>https://forum.processing.org/two/discussion/28057/multiple-videos-smoothness-threaded-playback</link>
      <pubDate>Fri, 15 Jun 2018 20:57:02 +0000</pubDate>
      <dc:creator>grumo</dc:creator>
      <guid isPermaLink="false">28057@/two/discussions</guid>
      <description><![CDATA[<p>Hello!
This script only requires a bunch of .mp4s in the data folder. You'll see a collage of 9 videos (or duplicates) in different positions and transparencies. The thing runs ok but even pre-loading the videos at the beginning every time there's a change/swap in one of the videos (around every 4 seconds) the whole thing freezes for a sec, sometimes (try to use mp4s of different sizes).</p>

<p>I tried to use the thread() command in the switching of the videos but nothing happened. I put a println to see the thread but alway show the main thread, I really don't know if I'm doing this ok..</p>

<p>Thanks a LOT for any help!</p>

<pre><code>import processing.video.*;

File path; 
String[] files;
int numfiles = 0;
int timer = -5000;
int tcontrol= 2000;
int numVideos=9;

VideoM[] v = new VideoM[numVideos];
Movie[] vv;

void setup(){
  size(1920, 1080, P2D);
  frameRate(60);
  files = files(); 
  numfiles = files.length;
  if (numfiles&gt;11) numfiles=11;
  loadvideos();

  for(int i = 0;i &lt; numVideos;i++){
     v[i] = new VideoM();
  }
}


void draw() {

  background(0);
  for(int i = 0; i &lt;numVideos; i++){
     v[i].display();
  }

  if ((millis() - timer) &gt; tcontrol)  {
    thread("newvideo");   
    timer = millis();
    tcontrol= int(random(2,6))*1000; 
}
}


void loadvideos(){

 String video;
 vv = new Movie[numfiles];

 for (int i=0; i&lt;numfiles; i++){
   video= files[int(random(numfiles))];
   vv[i] = new Movie(this, video);
   println ("Loading ", video);
 }
}

class VideoM {

 Movie m;
 String video;

 int x;
 int y;
 int w;
 int h;
 int alpha;
 int alphai;
 int fadeout=0;

 VideoM() {
  genera();
  println(numfiles);
  m = vv[int(random(numfiles)) ];
  m.loop();
  // m.volume(random(0.4,0.6));
  // m.speed(random(0.6,1.0));
  m.jump(random(m.duration()));  
  //m.play(); 
 }

 void genera(){
    x=int(random(50, width/2+width/4)); 
    y=int(random(50, height/2+height/4)); 
    w=int(random(280,820));
    h=int(w/1.88);
    alpha=int(random(100,255)); 
    alphai=0; 
 }

 void display(){
   tint(255, alphai);
   if (fadeout==0) {
     alphai++; if (alphai&gt;alpha) alphai=alpha;
   } else {  alphai--; if (alphai&lt;0) {alphai=0;fadeout=0;this.newvid();}
     }

   if (frameCount &gt; 1) { image(m, x, y, w, h); }
 } 

 void cambiavid(){
   fadeout=1;
 }

void newvid() {  
   m=null;
   int j=int(random(numfiles));
   println("cambio: ", j);
   m = vv[j];
   m.loop();
   genera();
   m.jump(random(m.duration())); 
   println(Thread.currentThread());
 }
}  

void newset(){
  for(int i = 0;i &lt; numVideos;i++){
    println(i);
    v[i].newvid();
  }
}

void newvideo(){
  int i = int(random(numVideos));
  //v[i].nuevovid(this);
  v[i].cambiavid();
}

void movieEvent(Movie m) {
  m.read();
}

boolean bStop,bColor=true;
boolean bSave=false,bVidO=false;
void keyPressed()
{
  int k = keyCode;

  // reset all videos
  if (key == 'n' || key == 'N') {
    newset();
    }

}  


// load files in data

String[] files(){
// The data path of the folder to look in (write your own)
java.io.File folder = new java.io.File(dataPath(""));

// let's set a filter (which returns true if file's extension is .jpg)
java.io.FilenameFilter pngFilter = new java.io.FilenameFilter() {
  public boolean accept(File dir, String name) {
    return name.toLowerCase().endsWith(".mp4");
  }
};

// list all the folders inside the main directory
String[] listFolders = folder.list(new java.io.FilenameFilter() {
  public boolean accept(File current, String name) {
    return new File(current, name).isDirectory();
  }
});

// list the files in the data folder, passing the filter as parameter
String[] filenames = folder.list(pngFilter);

return(filenames);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to make Processing hang without eating CPU?</title>
      <link>https://forum.processing.org/two/discussion/27960/how-to-make-processing-hang-without-eating-cpu</link>
      <pubDate>Sat, 12 May 2018 15:00:10 +0000</pubDate>
      <dc:creator>Architector_4</dc:creator>
      <guid isPermaLink="false">27960@/two/discussions</guid>
      <description><![CDATA[<p>I am making a project that relies on the thread("..."); function extensively, and I want to find a way to make one of these threads to stop in the middle of the code without eating CPU.</p>

<p>The thing I am currently using is this:</p>

<pre><code>void lag(float time){
int millis=millis();
while(millis()&lt;millis+time/1000){float wow=floor(sin(0));}
}
</code></pre>

<p>This makes me able to run function lag(5); and that will make it wait 5 seconds, however this also eats a lot of CPU while it waits.</p>

<p>Or I can spam loadStrings("<a href="https://www.google.com" target="_blank" rel="nofollow">https://www.google.com</a>"); a couple of times, which does <em>not</em> eat CPU, but is too unpredictable.</p>

<p>Is there a function that will work the same as my lag() function, but does not actually consume CPU?</p>
]]></description>
   </item>
   <item>
      <title>threads blocking draw loop or vice versa ? [background processes slowed]</title>
      <link>https://forum.processing.org/two/discussion/27814/threads-blocking-draw-loop-or-vice-versa-background-processes-slowed</link>
      <pubDate>Sat, 21 Apr 2018 04:23:17 +0000</pubDate>
      <dc:creator>AndrewS</dc:creator>
      <guid isPermaLink="false">27814@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,
I have some processing code running on a remote system, so very difficult to diagnose. It has some problems (see end of this long post). At home the software works fine (of course).</p>

<p><strong>The purpose of the code</strong> is to read a json file located on my home server every minute and write it to a local file that is then read by the main artwork processing sketch which drives a large inflatable sculpture. The value in the json file is live share market prices and the artwork is : <a href="https://andrewstyan.com/portfolio/life-support-system/" target="_blank" rel="nofollow">https://andrewstyan.com/portfolio/life-support-system/</a></p>

<p>The code has a draw loop which simply draws a performance chart of various monitoring variables and some stats. This is emailed to me when requested (hourly as triggered by a flag in the json file).  As far as I can tell there is no code in the draw loop that should take any time. The frameRate() is set to 2 as the draw loop does very little and does not need to run any faster.</p>

<p><strong>Four threads do the work</strong>, each based on a while(true) {   .. code ... delay() } loop:</p>

<p>1) <em>internet quality checker:</em></p>

<ul>
<li><p>3 times per minute (at 10, 30, 50 sec) check within a try/catch what is returned by: Process ping = Runtime.getRuntime().exec("ping " +" -c "+" 1 "+"www.google.com" );</p></li>
<li><p>maintain an internetOK boolean</p></li>
<li><p>maintain an error count for consecutive failures</p></li>
<li><p>maintain a ping time</p></li>
</ul>

<p>2) <em>read the server file:</em></p>

<ul>
<li><p>at 20 seconds into the minute read the server json file if internetOK == true;</p></li>
<li><p>maintain some monitor flags and variables - eg. loadFailed, loadTime</p></li>
</ul>

<p>3) <em>write the local data file</em></p>

<ul>
<li>at 40 seconds into the minute write the data read from the server file to the local data file (if the "read the server" thread has not completed it's task then the previous data will be written)</li>
</ul>

<p>4) an <em>error loop</em> which monitors all the status variables and escalates compounding issues, such as bad internet quality or repeated read errors.</p>

<p>A log file is maintained (and emailed on request) that logs the 'write local data' event and errors that can be detected by various logic tests, such as a file load taking too long or escalating errors.</p>

<p><strong>Two problems</strong> are occurring which are probably related.</p>

<p>1) Every 5 or 6 minutes the server file is not communicated through to the next sketch. This was much worse (every 2 minutes) until I realised the file was frequently taking 10 seconds to be read from the server (the wifi quality is quite poor in the gallery where the work is installed). The sketch should be able to deal with this and I reduced the problem by extending the time I allowed for reading a file.</p>

<p>2) Although the framerate of the draw loop is set at 2 fps it actually runs MUCH slower, frequently running less than 7 frames per minute rather than 120. I can tell this from the event log which includes a time stamp and frame count for each entry, and there is an entry about every minute.</p>

<p>Perhaps problem 1 is caused by problem 2 but I do not understand what is slowing the draw loop. I can probably recode the sketch to better handle the poor wifi, but still need to understand the slow frame rate as they may be related. It shouldn't be a computer power issue as the sketch for the main artwork is far more computer intensive but is operating correctly at the set rate of 17 fps.</p>

<p><strong>Help please:</strong></p>

<ul>
<li><p>Can anyone suggest what would be slowing the draw loop? It does very little and I understood that threads do not/cannot block the draw loop. Does the slow draw loop impact on the performance/timing of the threads or vice versa? Each thread uses the second() function to trigger its action, does this depend on the draw loop? I have made a simple sketch that confirms that none of these interactions should occur.</p></li>
<li><p>Any suggestions for diagnosing this from afar? The local staff are not computer literate at all. I can add more sophisticated remote diagnostics to the sketch (especially around actual durations to read and save files) and get them to compile it locally but that may be a stretch.</p></li>
<li><p>Any ideas for simulating the behaviour locally? What could I try to slow the draw loop like this ?</p></li>
</ul>

<p>I can post code or segments here, but it is massive and for obvious reasons I can't reduce it down to the minimum size that causes the problem. The draw() loop is below. The booleans are set in the threads. The calls are to simple functions that shouldn't block.</p>

<p>The remote machine is a 2014 mac-mini, definitely not latest OS and probably not latest Java. Processing 3.3.6 (I think).</p>

<p>Thanks in advance,
Andrew</p>

<pre><code>    void draw() {
      background(50);
      fill(160);
      stroke(200);

      if (frameCount == 150)  // start the status writing thread once the system stabilises
      {
        thread("statusLoop");
        statusRecord = "starting status loop";
      }

      getTime();

      if(hour()==0 &amp;&amp; minute()==0 &amp;&amp; second()&lt;2) resetChart();

      // end of draw

      // internet
      img.beginDraw();
      if (internetOK) fl = green;
      else fl = red;
      if (inChecking) fl = blue;
      stroke(fl);
      fill(fl);
      rect(10, 10, 10, 10);
      float pt = map(pingTime, 0, 300, 75, 0);
      img.fill(fl);
      img.stroke(fl);
      if (!inChecking) img.line(scrapeMins, pt, scrapeMins+3, pt);

      if (internetFailed) fl = red;
      else fl = green;
      if (inChecking) fl = blue;
      stroke(fl);
      fill(fl);
      rect(22, 10, 10, 10); 
      img.fill(fl);
      img.stroke(fl);
      pt = map(timeDiff, 0, 270000, 150, 75);
      if (!loadingPackage) img.ellipse(scrapeMins, pt, 2, 2);

      img.endDraw();
      image(img, 0, 30);
      stroke(170);
      line(scrapeMins, 30+50, scrapeMins, 30+100);

      fill(150);
      text(pingTime, 50, 20);
      text("Fails: "+internetFails, 150, 20);

      // time
      text(scrapeTimeHMS(now), 400, 20);

      // reader
      if (!loadFailed) fill(0, 255, 0);
      else fill(255, 0, 0);
      if (loadingPackage) fill(0, 0, 255);
      rect(10, 200, 10, 10);
      fill(150);
      text("Load time: "+nf(loadTime, 2, 0)+"   Time stamp difference: "+timeDiff, 50, 200);
      text(packageTxt, 50, 220);

      text(statusRecord, 50, 300);

      text(getRowSummary(), 50, 350);

      reportLoop();
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Fast loading images directly from Disk</title>
      <link>https://forum.processing.org/two/discussion/27792/fast-loading-images-directly-from-disk</link>
      <pubDate>Wed, 18 Apr 2018 12:50:47 +0000</pubDate>
      <dc:creator>tom_tm</dc:creator>
      <guid isPermaLink="false">27792@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>is there a way to sequencially load images directly from disk with realtime perfomance?
loadImage is very slow, and I would like to avoid preloading the images first.</p>

<p>I could do this with old good Flash with Full HD imagery in realtime, so it has nothing to do with my disk performance.</p>

<p>Thanks for any hints
Tom</p>
]]></description>
   </item>
   <item>
      <title>Comunicacion loadstring http</title>
      <link>https://forum.processing.org/two/discussion/26858/comunicacion-loadstring-http</link>
      <pubDate>Thu, 15 Mar 2018 10:11:07 +0000</pubDate>
      <dc:creator>Cachicot</dc:creator>
      <guid isPermaLink="false">26858@/two/discussions</guid>
      <description><![CDATA[<p>Hola.
Estoy intentando comunicar de forma bidireccional arduino a traves del modulo esp8266 con android usando http, el esquema seria el siguiente.</p>

<p>Android==&gt;ESP8266==&gt;Arduino                    arduino responda a la peticion.</p>

<p>Android&lt;==ESP8266&lt;==Arduino</p>

<p>Para esto Android realiza la peticion utilizando loadstring, el codigo android seria el siguiente.</p>

<pre><code>    void setup() {
      fullScreen();//ANCHO DE LA PANTALLA
      background(#000000);//COLOR DEL FONDO HEXADECIMAL (NEGRO)
      //stroke(#FFFFFE);//GROSOR DEL TRAZO EN  HEXADECIMAL
      strokeWeight(5);//GROSOR DEL TRAZO EN PIXELES
    }

    void draw() { 
     fill(#848484);//COLOR RECTANGULO
     rect (150,50,150,50);//DIBUJA UN RECTANGULO X,Y,ANCHO,ALTO
     fill(#000000);//COLOR RECTANGULO
     rect (10,10,100,100);//DIBUJA UN RECTANGULO X,Y,ANCHO,ALTO

     textSize(26);//TAMAÑO DEL TEXTO
     fill(#FFFFFF);//COLOR PARA TEXTO 
     text("PETICION", 160 , 75);//DIBUJA EL TEXTO

     }
     void mousePressed  (){ //PARA PRESIONAR BOTONES

       if(mouseX &gt; 150 &amp;&amp; mouseX &lt; 650)
         if (mouseY &gt; 50 &amp;&amp; mouseY &lt; 200){
           textSize(26);fill(#BDBDBD); text("PETICION", 160 , 75); 
           thread("Envio");
         }
    }
      //FUNCIONES METODO THREAD
      void  Envio () {
        String[] lines = loadStrings("<a href="http://192.168.1.37/A" target="_blank" rel="nofollow">http://192.168.1.37/A</a>");
    println("there are " + lines.length + " lines");
    for (int i = 0 ; i &lt; lines.length; i++) {
      println(lines[i]);//IMPRIME EN EL TERMINAL
    }
      }
</code></pre>

<p>La sentencia loadstring es  String[] lines = loadStrings("<a href="http://192.168.1.37/A" target="_blank" rel="nofollow">http://192.168.1.37/A</a>"); se cambia al subir el post.
Esta sacado del ejemplo loadstring, el tema es que cuando realiza una peticion por internet a cualquier pagina funciona correctamente, sin embargo cuando se realiza a arduino esto es lo que se recibe a traves de la consola de arduino.</p>

<pre><code>    0,CONNECT

    +IPD,0,187:GET /A HTTP/1.1
    User-Agent: Dalvik/2.1.0 (Linux; U; Android 8.0.0; Android SDK built for x86 Build/OSR1.170901.056)
    Host: 192.168.1.37
    Connection: Keep-Alive
    Accept-Encoding: gzip
</code></pre>

<p>Hasta aqui la cosa va bien entonces utilizando el metodo AT+CIPSEND envio algunos caracteres escribiendo en el terminal</p>

<pre><code>AT+CIPSEND=0,33
&gt;&lt;html&gt;&lt;h2&gt;holamundo&lt;/h2&gt;&lt;/html&gt;\n
</code></pre>

<p>tambien he probado quitandole la terminacion \n</p>

<p>y se recibe esto en arduino diciendo que se ha enviado con exito.</p>

<pre><code>AT+CIPSEND=0,33


OK
&gt; 

busy s...

Recv 33 bytes

SEND OK
AT+CIPCLOSE=0

0,CLOSED

OK
</code></pre>

<p>Pero cuando cierro la conexion se produce un null pointer con un monton de excepciones y no se recibe nada.</p>

<pre><code>java.io.IOException: unexpected end of stream on com.android.okhttp.Address@cd6325c0
    at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:201)
    at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
    at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
    at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:609)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:471)
</code></pre>

<p>A alguien se le ocurre que estoy haciendo mal.</p>

<p>El caso es que si lo hago a traves de un navegador como Chrome se recibe lo siguiente:</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/338/6ORBTEIFBMY8.png" alt="imagen" title="imagen" /></p>
]]></description>
   </item>
   <item>
      <title>check that file exists after call</title>
      <link>https://forum.processing.org/two/discussion/25826/check-that-file-exists-after-call</link>
      <pubDate>Thu, 04 Jan 2018 23:50:20 +0000</pubDate>
      <dc:creator>jeffmarc</dc:creator>
      <guid isPermaLink="false">25826@/two/discussions</guid>
      <description><![CDATA[<p>I call a utility and copy the output to a text file then read the text file.
The file is created ok, but when i read it with loadStrings its not all there unless i include
a delay of =&gt;600 even though i erase the old file and create a new one and wait for it to appear
Why doesn't the file checking work?</p>

<pre><code>// read properties

     final File f2 = dataFile(STILLPROP_PATH);
     if(f2.exists()) { f2.delete(); }
     open("c:/avspit/stillcap /listproperties &gt; c:/avspit/stillprop.txt");
     delay(600);
     while (!f2.exists()) { s+="."; 
     delay(300); // Avoids frying CPU!
     //println(s);                
     }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Progress bar inside a calculation (for loop)</title>
      <link>https://forum.processing.org/two/discussion/25028/progress-bar-inside-a-calculation-for-loop</link>
      <pubDate>Wed, 15 Nov 2017 20:27:06 +0000</pubDate>
      <dc:creator>TheUltimateKrtek</dc:creator>
      <guid isPermaLink="false">25028@/two/discussions</guid>
      <description><![CDATA[<p>Hello, everyone!
I am working on a school project, photoshop.
When I use the blur effect it takes a very long time. So, I want to tell the user, how much progress has the algorithm made so far.
I have a single function doing all the work. Inside that function is a for loop and the most work is done inside that for loop.</p>

<p>The only values it is showing me are 0% and 100%.
I want to find a way to either draw the progress bar individually or redraw the whole screen inside that for loop.</p>

<p>Thx for help in advance.</p>
]]></description>
   </item>
   <item>
      <title>Using a thread to fire off function, doesn't render text</title>
      <link>https://forum.processing.org/two/discussion/24518/using-a-thread-to-fire-off-function-doesn-t-render-text</link>
      <pubDate>Thu, 12 Oct 2017 15:09:49 +0000</pubDate>
      <dc:creator>ianm</dc:creator>
      <guid isPermaLink="false">24518@/two/discussions</guid>
      <description><![CDATA[<p>I'm using a thread to fire an event every few seconds. When I call the function in setup, it works. When I call the function from the thread, it runs, as I can debug through, but nothing is printed to screen using rect/text.</p>

<pre><code>final static int TIMER = 5 * 1000;  
static String msg; 
static boolean isEnabled = true; 
int left=0;
int f = 255;

void setup() {
  size(320, 240);
  fill(#FFFF00);
  textSize(32);
  textAlign(CENTER, CENTER);
  fireTimer();            // this one works
  thread("timer");  
}

void draw() {
   f = (f &gt; 10) ? f-10 : 255;
  fill(f);
  rect(left, 10, 10, 10);
  left += 10;
  if (left &gt; width) left = 0;
}

void fireTimer() {
    msg = nf(minute(), 2) + ":" + nf(second(), 2);
    println("Triggered @ " + msg);
    fill(0);
    rect(width/4, height/4, width/2, height/2);
    fill(255);
    text(msg, width/2, height/2);
}

void timer() {
 while (isEnabled) {
    delay(TIMER);
    fireTimer();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Fixed update function?</title>
      <link>https://forum.processing.org/two/discussion/23960/fixed-update-function</link>
      <pubDate>Tue, 29 Aug 2017 11:39:36 +0000</pubDate>
      <dc:creator>theliquu69</dc:creator>
      <guid isPermaLink="false">23960@/two/discussions</guid>
      <description><![CDATA[<p>I want to make a pixel water physics simulation, and I want to add gravity to the water pixels. This is my code so far:</p>

<pre><code>int[][] map;
int mapWidth = 100;
int mapHeight = 100;
int drawScale = 4;

int tick = 0;
int tickRate = 2;

void settings() {
  size(mapWidth*drawScale, mapHeight*drawScale);
}

void setup() {
  frameRate(240);
  surface.setTitle("Pixel Fluid");
  map = new int[mapWidth][mapHeight];

  for (int i = 0; i &lt; mapWidth; i++) {
    for (int j = 0; j &lt; mapHeight; j++) {
      setMap(i, j, 0);
    }
  }
  thread("physics");
}

void draw() {
  tick++;
  surface.setTitle("Pixel Fluid | " + frameRate + " " + tick % tickRate);
  for (int i = 0; i &lt; mapWidth-1; i++) {
    for (int j = 0; j &lt; mapHeight-1; j++) {
      fill(mapTileColor(i, j)); 
      noStroke();
      rect(i*drawScale, j*drawScale, drawScale, drawScale);
    }
  }

  thread("physics");

  if (mousePressed) {
    switch (mouseButton) {
    case RIGHT:
      setMap(mouseX/drawScale, mouseY/drawScale, 1);
      break;

    case LEFT:
      setMap(mouseX/drawScale, mouseY/drawScale, 2);
      break;
    }
  }
}

void physics() {
  for (int i = 0; i &lt; mapWidth-1; i++) {
    for (int j = 0; j &lt; mapHeight-1; j++) {
      if (getMap(i, j) == 2 &amp;&amp; getMap(i, j+1) == 0 &amp;&amp; tick % tickRate == 0) {
        setMap(i, j+1, 2);
        setMap(i, j, 0);
      }
    }
  }
}

void setMap(int x, int y, int tile) {
  map[x][y] = tile;
}

int getMap(int x, int y) {
  return map[x][y];
}

color mapTileColor(int x, int y) {
  switch(getMap(x, y)) {

  case 1:
    return #000000;

  case 2:
    return #0000FF;

  default:
    return #FFFFFF;
  }
}
</code></pre>

<p>I want to make the gravity work on a water particle every 2 ticks, so it looks like it's falling. Instead, when you left click to place the water it falls instantly. How can I have a "fixed update" function, where the gravity would only occur every a certain amount of frames?</p>
]]></description>
   </item>
   <item>
      <title>How to communicate with c# TcpListener (server) as a client?</title>
      <link>https://forum.processing.org/two/discussion/23654/how-to-communicate-with-c-tcplistener-server-as-a-client</link>
      <pubDate>Mon, 31 Jul 2017 18:52:07 +0000</pubDate>
      <dc:creator>MDEV</dc:creator>
      <guid isPermaLink="false">23654@/two/discussions</guid>
      <description><![CDATA[<p>Hi!</p>

<p>I'm trying to do a game wich is written in <strong>c#</strong> and I want to force this game to coexistence with a Processing application and communicate with it. So the default stage is --&gt; <strong>C# server</strong> read and write data too to the <strong>client  : Processing.Net OR java.net</strong> (I have tried both) read and write data too but don't blocking the Processing main thread because I need the draw method in Processing too.</p>

<p>So as I write here I have already tried processing.net.client to connect to the <strong>C#</strong> <strong>TcpListener</strong> but I think this is just not possible? And now I can connect to the server with java.net.Socket but when I trying to write a message in <strong>C# to the Processing</strong> the C# says to me how the Processing is forced the socket to close.. So I can't send data to it.. (The threading is created with the Processing <a rel="nofollow" href="https://processing.org/reference/thread_.html">thread("...") method</a>)</p>

<p>M. Márkó (MDEV) , Hungary</p>
]]></description>
   </item>
   <item>
      <title>Is the meta method "method(String)" default to java or just processing?</title>
      <link>https://forum.processing.org/two/discussion/22885/is-the-meta-method-method-string-default-to-java-or-just-processing</link>
      <pubDate>Sat, 03 Jun 2017 00:31:17 +0000</pubDate>
      <dc:creator>CantSayIHave</dc:creator>
      <guid isPermaLink="false">22885@/two/discussions</guid>
      <description><![CDATA[<p>Often in my own Applets I use the <code>method(String)</code> method for button callbacks. I learned about it a while back from a thread here. For example:</p>

<pre><code>void handleClicks (ArrayList buttons) {
  for (Button button : buttons) {
    if (button.isPressed()) {
      method(button.getCallback());
    }
  }
}
</code></pre>

<p>I wanted to know more about it. However, google hasn't been too helpful locating this due to the meta nature of the method. Is this from Java or Processing Core?</p>
]]></description>
   </item>
   <item>
      <title>mouseClicked() becomes laggy and slow</title>
      <link>https://forum.processing.org/two/discussion/22907/mouseclicked-becomes-laggy-and-slow</link>
      <pubDate>Sat, 03 Jun 2017 21:31:12 +0000</pubDate>
      <dc:creator>Vanthex</dc:creator>
      <guid isPermaLink="false">22907@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,
So I know in processing there is a function called mouseClicked() that will execute the code inside it when the mouse is clicked. However the more objects I have in my program, the laggier and slower the mouse click detection becomes. Sometimes nothing happens when I click. How do i fix this? (I'm using eclipse IDE) Here is my code:</p>

<pre><code>public void mouseClicked() {
        if (room.equals("game")) {
            for (Group group : discoveredGroups) {
                group.groupClicked();
            }
            for (Group groupSelected : groupSelectedList) {
                if (groupSelected != null) {
                    groupSelected.groupClicked();
                }
            }
            for (Button button : buttons) {
                button.buttonClicked();
            }
            for (Arrow arrow : arrows) {
                arrow.arrowClicked();
            }
            for (Pane pane : panes) {
                pane.paneClicked();
            }
            // avoid concurrent modification error
            if (elementClickPause == false) {
                for (Element element : elementListA) {
                    if (element != null) {
                        element.elementClicked();
                    }
                }
                for (Element element : elementListB) {
                    if (element != null) {
                        element.elementClicked();
                    }
                }
            }
        } else if (room.equals("menu")) {
            for (Button button : buttons) {
                button.buttonClicked();
            }
            if (drawPackList == true) {
                for (Pack pack : packObjects) {
                    pack.packClicked();
                }
            }
            for (Arrow arrow : arrows) {
                arrow.draw();
            }
            for (Pane pane : panes) {
                pane.paneClicked();
            }
        } else {
            for (Button button : buttons) {
                button.buttonClicked();
            }
        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Call a object's or class' function with thread()?</title>
      <link>https://forum.processing.org/two/discussion/22672/call-a-object-s-or-class-function-with-thread</link>
      <pubDate>Fri, 19 May 2017 18:59:48 +0000</pubDate>
      <dc:creator>Shoruke</dc:creator>
      <guid isPermaLink="false">22672@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to use threading to make it so I can display a "loading screen" while something is loading. The main class will draw the loading icon and start a thread to have the Menu Screen start initializing all the images it needs, and when the Menu Screen is done loading everything, it sets a global Done Loading variable to true, and the main class starts drawing it.</p>

<p>But how do I call MenuScreen.initialize() with thread()? It gives me an error in the console that says "There is no public MenuScreen.initialize() method in the class MainClass".</p>

<p>Here's a trimmed version of what I have so far. The main class:</p>

<pre><code>import gifAnimation.*; // used for the loading icon

Screen curScreen;
boolean doneLoading;
Sprite loadingGif;

void setup()
{
  size(600, 600);
  frameRate(30);
  loadingGif = new Sprite(this, "loading flower.gif");
  doneLoading = false;
  curScreen = new MenuScreen();
  thread("MenuScreen.initialize");
}

void draw()
{
  background(50);
  if(doneLoading) curScreen.screenDraw();
  else loadingGif.drawThis(width - 60, height - 60);
}
</code></pre>

<p>And the MenuScreen class, which implements a very simple Screen interface that stipulates its initialize() and screenDraw() methods:</p>

<pre><code>class MenuScreen implements Screen
{
  int curSelection; // which selection item the cursor is on right now: new game, load game, etc.
  PImage backgroundImg;
  PImage cursorImg;

  MenuScreen()
  {
  }

  void initialize()
  {
    backgroundImg = loadImage("WelcomeBackground.png");
    cursorImg = loadImage("WelcomeCursor.png");
    doneLoading = true;
  }

  void screenDraw()
  {
    image(backgroundImg, 0, 0, width, height);
    text("Herro wuorld", 50, 50, 200, 200);
  }
}
</code></pre>

<p>I've also tried using thread("initialize") in MenuScreen's constructor, but that tries to look for an initialize function in the main class, too. I suppose I could just make the Initialize function a global function, but that doesn't seem like optimal coding standards when all I should need is a proper String for my call to thread()...</p>
]]></description>
   </item>
   <item>
      <title>GL video 1.2.1</title>
      <link>https://forum.processing.org/two/discussion/21587/gl-video-1-2-1</link>
      <pubDate>Fri, 24 Mar 2017 17:21:04 +0000</pubDate>
      <dc:creator>RaulF</dc:creator>
      <guid isPermaLink="false">21587@/two/discussions</guid>
      <description><![CDATA[<p>Hi there!</p>

<p>I have installed the last GL video version, to see if I can solve my "jump" problems (<a href="https://forum.processing.org/two/discussion/13673/jump-in-videolibrary-causes-java-error#latest" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/13673/jump-in-videolibrary-causes-java-error#latest</a>).</p>

<p>But, with version 1.2.1 playing the videos the image freezes constantly.</p>

<p>I'm testing it in 5 different Raspberry at the same time, with the same results (253% CPU!). All software updated.</p>

<pre><code>PID USER      PR  NI    VIRT    RES       SHR S    %CPU  %MEM     TIME+ COMMAND                 
1033 pi        20   0  457288  91032  13084 S 253.2 23.2 351:44.38 java 
</code></pre>

<p>I'm also playing the same video file in 8 Raspberry, same hardware and software, but with GL video 1.2. Better performance:</p>

<pre><code>PID USER      PR  NI    VIRT    RES        SHR S      %CPU   %MEM   TIME+ COMMAND                 
1069 pi         0 -20  371956  58540  12232 S  48.3 14.9 136:07.68 java   
</code></pre>

<p>Video file:</p>

<p>Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 800x480, 9462 kb/s, SAR 1:1 DAR 5:3, 60 fps, 60 tbr, 60 tbn, 120 tbc (default)<br />
Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, 1 channels, s16, 768 kb/s (default)</p>

<p>Any help is welcome!</p>

<p>Best.</p>
]]></description>
   </item>
   <item>
      <title>Is there a way to check loadXML periodically?</title>
      <link>https://forum.processing.org/two/discussion/22521/is-there-a-way-to-check-loadxml-periodically</link>
      <pubDate>Thu, 11 May 2017 12:08:45 +0000</pubDate>
      <dc:creator>Zelda</dc:creator>
      <guid isPermaLink="false">22521@/two/discussions</guid>
      <description><![CDATA[<p>It seems like you can only define the content from the XML at the certain time in void setup.</p>

<p>I am trying to load headlines from say for example bbc.co.uk. My code loads the XML, and then in void draw, it displays the headline by scrolling from right to left. That works all good.</p>

<p>But if my first paragraph is true, that means that in void draw, it will run out of headlines to print, and it will just repeat the content due to loadXML being load only once. Is that right?</p>

<p>Is there anyway to check it from time to time?</p>

<pre><code>// Example 17-3: Scrolling headlines 

// An array of news headlines
String[] titles; /*= {
  "Processing downloads break downloading record." , //   Multiple Strings are stored in an array.
  "New study shows computer programming lowers cholesterol." ,
};*/
PFont f; // Global font variable
float x; // Horizontal location
int index = 0;

void setup() {
  size(400,200);
  f = createFont( "Arial" ,16,true);
  // Initialize headline offscreen
  x = width;


    String url = "<a href="http://www.worldpress.org/feeds/topstories.xml" target="_blank" rel="nofollow">http://www.worldpress.org/feeds/topstories.xml</a>"; 

  XML rss = loadXML(url);
  // Get title of each element
  XML[] titleXMLElements = rss.getChildren("channel/item/title");
  titles = new String[titleXMLElements.length];
  for (int i = 0; i &lt; titleXMLElements.length; i++) {
    String title = titleXMLElements[i].getContent();
    // Store title in array for later use
    titles[i] = title;
  }
}

void draw() {

  background(255);
  fill (0);
  // Display headline at x location
  textFont(f,16);
  textAlign (LEFT);
  text(titles[index],x, 20); // A specific String from the array is displayed according to the value of the “index” variable.
  // Decrement x
  x = x - 1;
  // If x is less than the negative width,
  // then it is off the screen
  float w = textWidth(titles[index]); // textWidth() is used to calculate the width of the current String.
  if (x &lt; -w) {
    x = width;
    index = (index + 1) % titles.length; // “index"is incremented when the current String has left the screen in order to display a new String.
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Calling draw() from a function doesn't update the screen</title>
      <link>https://forum.processing.org/two/discussion/22421/calling-draw-from-a-function-doesn-t-update-the-screen</link>
      <pubDate>Sat, 06 May 2017 19:09:24 +0000</pubDate>
      <dc:creator>VladShev</dc:creator>
      <guid isPermaLink="false">22421@/two/discussions</guid>
      <description><![CDATA[<p>I'm experimenting with how to process some data in one function while displaying a loading bar on the screen. For an example, I'm adding a bunch of values to an array - a process that takes about 5 seconds on my computer. I have the following code:</p>

<pre><code>ArrayList&lt;String&gt; strs = new ArrayList&lt;String&gt;();
String state;
float counter;

void setup() {
  size(640, 480);
  state = "load";
  noStroke();
}

void draw() {
  if (state.equals("load")) {
    load();
  } else if (state.equals("loading")) {
    background(255);
    fill(255, 0, 0);
    rect(0, height/2-25, map(counter, 0, 10000000, 0, width), 50);
  } else if (state.equals("play")) {
    background(0, 255, 0);
  }
}

void load() {
  state = "loading";
  for (int i = 0; i &lt; 10000000; i++) {
    strs.add(str(pow(i, 2)));

    if (i % 1000 == 0) {
      counter = i;
      draw();
    }
  }
  state = "play";
}
</code></pre>

<p>But I just get a grey screen (indicating that background(255) has never been called) for about 5 seconds until I get a green screen. I could, of course, replace the code with something like:</p>

<pre><code>ArrayList&lt;String&gt; strs = new ArrayList&lt;String&gt;();
String state;
int counter;

void setup() {
  size(640, 480);
  state = "load";
  noStroke();
  counter = 0;
}

void draw() {
  if (state.equals("load")) {
    float theMillis = millis();
    while (millis()-theMillis &lt; 1000.0/frameRate &amp;&amp; counter &lt; 10000000) {
      strs.add(str(pow(counter, 2)));
      counter++;
    }
    if (counter &gt;= 10000000) {
      state = "play";
    }

    background(255);
    fill(255, 0, 0);
    rect(0, height/2-25, map(counter, 0, 10000000, 0, width), 50);
  } else if (state.equals("play")) {
    background(0, 255, 0);
  }
}
</code></pre>

<p>And that would work for this simple example, but I am trying to get draw() to work when called from a function explicitly as depending on the complexity of load() (the one I'm actually trying to get to work in my project is 250+ lines long of opening and uncompressing files, processing JSONArrays and ArrayLists, etc.) splitting the load function into chunks inside draw() could be a nightmare. So is there anyway to update the screen from inside a function?</p>

<p>Thanks in advance for all your help :)</p>
]]></description>
   </item>
   <item>
      <title>Updating outside of draw()</title>
      <link>https://forum.processing.org/two/discussion/21696/updating-outside-of-draw</link>
      <pubDate>Thu, 30 Mar 2017 04:03:31 +0000</pubDate>
      <dc:creator>isaac328</dc:creator>
      <guid isPermaLink="false">21696@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to make visualizations of common sorting algorithms using processing. I would like to be able to call the draw function after every step the algorithm takes, so that you can see everything as it happens. Here is an example of what i am trying to do with Insertion sort:</p>

<pre><code> public void insertionSort()
 {
    for(int i = 0; i &lt; arr.length; i++)
    {
        while(j &gt; 0 &amp;&amp; arr[j-1] &gt; arr[j])
        {
            swap(arr, j, j-1);
            j--;
            draw();
        }
        j = i;
    }
  }

 public void draw()
 {
     (draw everything)
 }
</code></pre>

<p>I know for simpler sorts like selection and insertion sort you could make the sort work within the draw function itself, which i have done, but that wont work for sorts that use recursion like quick sort and merge sort (at least i cant think of how to get them to work). So basically, my question is is there any way to choose when the draw function executes so i can call it and have it update when i want? I have tried the redraw() function but that doesn't seem to be fast enough, and simply calling draw doesn't do anything either. I also tried running the sort in a separate thread, which sort of works but has some bad side effects with the screen glitching out.</p>
]]></description>
   </item>
   <item>
      <title>Multi-threading/parallel computation?</title>
      <link>https://forum.processing.org/two/discussion/21484/multi-threading-parallel-computation</link>
      <pubDate>Sun, 19 Mar 2017 22:56:10 +0000</pubDate>
      <dc:creator>tomricci</dc:creator>
      <guid isPermaLink="false">21484@/two/discussions</guid>
      <description><![CDATA[<p>Does anyone know if Processing is by default limited to CPU/RAM usage defaults? I'm integrating it into a facility at my university on a ridiculously powerful system (24 cores, 36GB in graphics power and a stupid amount of RAM). Yet, some sketches run at a poor frame rate (10-20 per second), which isn't much better than my MacBook Pro, so I feel there's something wrong. I've tried multiple renderers as well. For example, the flocking example that comes with Processing couldn't handle more than a few hundred objects (which wasn't much more than any other computer could), or with 3D scenes only a few hundred boxes causes a very laggy navigating experience. OPEN GL rendering didn't seem to make a big difference.</p>

<p>Does anyone know what this might be? It's been hard searching for "processing performance" in relation to the actual program "Processing". Thanks!</p>
]]></description>
   </item>
   <item>
      <title>using open()</title>
      <link>https://forum.processing.org/two/discussion/16142/using-open</link>
      <pubDate>Wed, 20 Apr 2016 20:51:01 +0000</pubDate>
      <dc:creator>jeffmarc</dc:creator>
      <guid isPermaLink="false">16142@/two/discussions</guid>
      <description><![CDATA[<p>I start an external .exe with open()
but starts an external flat bed scanner scan that takes about 20 seconds</p>

<p>The program continues and before the scan finishes and puts a file in the directory
I use to put up image, it gets to the load file statement and can't find it , it's not there yet.</p>

<p>I am trying to use this code to test the file exists before letting the program continue
but it complains "unexpected token boolean"</p>

<p>boolean fileExists(String "test.png")</p>

<p>File file = new File("test.png");</p>

<p>while(!file.exists());</p>

<p>Am I on the right tract?</p>
]]></description>
   </item>
   <item>
      <title>redraw question</title>
      <link>https://forum.processing.org/two/discussion/20995/redraw-question</link>
      <pubDate>Fri, 24 Feb 2017 20:39:21 +0000</pubDate>
      <dc:creator>blast664</dc:creator>
      <guid isPermaLink="false">20995@/two/discussions</guid>
      <description><![CDATA[<p>Simple question: In the code below calling drawsomething() draws a rectangle every 500 ms. Using redraw instead does not work. Why? Am I missing something?</p>

<pre><code>int i = 0;
float time = 0;

void setup() {
  size (300, 300);
  noLoop();

  while (time &lt; 3000) {
    time = millis();
    if (time &gt; i*500) {  
      drawsomething();
      //redraw();
      print(i);
      i++;
    }
  }
}

void drawsomething() {
  background(0);
  fill(255);
  rect(10, 10, 20, 20);
}

void draw() {
  background(0);
  fill(255);
  rect(10, 10, 20, 20);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>oscmessaging speed</title>
      <link>https://forum.processing.org/two/discussion/20042/oscmessaging-speed</link>
      <pubDate>Mon, 02 Jan 2017 22:34:43 +0000</pubDate>
      <dc:creator>dfamil</dc:creator>
      <guid isPermaLink="false">20042@/two/discussions</guid>
      <description><![CDATA[<p>hi
i need to send an oscmessage to another program. I need to have it go faster than a loop in the draw method. but if i do it in the normal way it is too fast. Since i am using controlP5 i cant use delay()  in the loop. I can't find anyway to slow down a loop without using draw and millis().</p>
]]></description>
   </item>
   <item>
      <title>Timing for draw loop</title>
      <link>https://forum.processing.org/two/discussion/18517/timing-for-draw-loop</link>
      <pubDate>Wed, 12 Oct 2016 11:46:25 +0000</pubDate>
      <dc:creator>leclerke</dc:creator>
      <guid isPermaLink="false">18517@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I have to sychronize an animation to 1 frame per second.</p>

<p>Until now I used the millis() function for the timing. But annoyingly the time is running away. The Code is like:</p>

<pre><code>draw(){
  while ((millis () &gt;= time + timeStep)){
    println(time);
    ...
  }
  time = millis();
</code></pre>

<p>With timeStep = 500 I get time codes like:</p>

<pre><code>8165,
8768,
9305,
9818
</code></pre>

<p>What I want is:</p>

<pre><code>8000,
8500,
9000,
9500
</code></pre>

<p>How do I reallize this?</p>
]]></description>
   </item>
   <item>
      <title>Show running time at the end of process</title>
      <link>https://forum.processing.org/two/discussion/18073/show-running-time-at-the-end-of-process</link>
      <pubDate>Mon, 05 Sep 2016 01:38:41 +0000</pubDate>
      <dc:creator>siminan87</dc:creator>
      <guid isPermaLink="false">18073@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys I need some help. I want to display the time an application has been running for at the end of a process how do I do this. Thank you in advance.</p>
]]></description>
   </item>
   <item>
      <title>How to call thread("functionName") in draw()</title>
      <link>https://forum.processing.org/two/discussion/18591/how-to-call-thread-functionname-in-draw</link>
      <pubDate>Mon, 17 Oct 2016 10:25:03 +0000</pubDate>
      <dc:creator>Julo</dc:creator>
      <guid isPermaLink="false">18591@/two/discussions</guid>
      <description><![CDATA[<p>How to call thread("functionName") in draw() with when the function is in a class in other tab?
if I put the function in the main class, it has no problem.
If I put them in a class in other tab, I get
"There is no public functionName() method in the class xxxxxx" msg.</p>
]]></description>
   </item>
   <item>
      <title>RaspberryPi Processing 3 Performance Issues for Loading images on runtime</title>
      <link>https://forum.processing.org/two/discussion/18287/raspberrypi-processing-3-performance-issues-for-loading-images-on-runtime</link>
      <pubDate>Sun, 25 Sep 2016 10:02:24 +0000</pubDate>
      <dc:creator>Bhargav</dc:creator>
      <guid isPermaLink="false">18287@/two/discussions</guid>
      <description><![CDATA[<p>I am using processing 3.2.1 on RasbperryPi 3</p>

<p>In one of my programs I am loading three images on runtime from set of images in a folder.  The images are changing runtime. Raspberrypi is fast enough to run the code and atleast load three images of each less then 150kb and of resolution 1260x760.</p>

<p>But my output becomes extremely slow while loading these images together. Loading one image runs smooth, two slower and three super slow. I have no guess about why is processing not able to run fast when Raspberypi is capable to running the code.  The same code runs with perfect speed on my laptop in windows.</p>

<p>Part of the code is as under :</p>

<pre><code>  //Load Images
  imgA = loadImage(path+ displayuserid +"/"+ displayobjectid +"/" + (imageno)%36 +  ".jpg");
  imgB = loadImage(path+ displayuserid +"/"+ displayobjectid +"/" + (imageno+1)%36 +  ".jpg");
  imgC = loadImage(path+ displayuserid +"/"+ displayobjectid +"/" + (imageno+2)%36 +  ".jpg");     


    //Display Images
    imgA.resize(0,250);
    image(imgA, width/2 - imgA.width/2, height/2 + height/2 - imgA.height);      


     pushMatrix();
     translate(width/2,height/2);
     rotate(90*TWO_PI/360);
     imgB.resize(0,250);
     image(imgB, -imgB.width/2, height/2-imgB.height);
     popMatrix();

     pushMatrix();
     translate(width/2,height/2);
     rotate(-90*TWO_PI/360);
     imgC.resize(0,250);
     image(imgC, -imgC.width/2, height/2-imgC.height);
     popMatrix();  
</code></pre>
]]></description>
   </item>
   <item>
      <title>run object method in parallel thread</title>
      <link>https://forum.processing.org/two/discussion/17767/run-object-method-in-parallel-thread</link>
      <pubDate>Sat, 06 Aug 2016 13:41:18 +0000</pubDate>
      <dc:creator>secondsky</dc:creator>
      <guid isPermaLink="false">17767@/two/discussions</guid>
      <description><![CDATA[<p>Hi everybody, i know how to run a function in a parallel thread (easy, just passing the name in "thread()"), but is there a way to run an object method in a parallel thread?
Thanks</p>
]]></description>
   </item>
   <item>
      <title>Simultaneous Calculations</title>
      <link>https://forum.processing.org/two/discussion/17139/simultaneous-calculations</link>
      <pubDate>Tue, 14 Jun 2016 13:02:48 +0000</pubDate>
      <dc:creator>Alex_Pr</dc:creator>
      <guid isPermaLink="false">17139@/two/discussions</guid>
      <description><![CDATA[<p>Is it possible to make simultaneous calculations through an array?
For example, lets assume we have a 2d array of floats and want to know the sum of all elements in a column for all columns.  Is there a way to calculate these sums simultaneously for all columns and not one by one?</p>

<p>One way I can think of for doing this is using the GPU multicore architecture to parallelize the calculations but is this feasible with processing?</p>
]]></description>
   </item>
   <item>
      <title>Make a "timer" in Processing</title>
      <link>https://forum.processing.org/two/discussion/17075/make-a-timer-in-processing</link>
      <pubDate>Thu, 09 Jun 2016 21:10:55 +0000</pubDate>
      <dc:creator>2002kevinhuang</dc:creator>
      <guid isPermaLink="false">17075@/two/discussions</guid>
      <description><![CDATA[<p>So basically I have a shape, and I want to make it so, every 2 seconds, the shape randomly changes color. I already know how to have the shape randomly change color, but I don't know how to make it happen every 2 seconds. Can someone answer ASAP? Thanks.</p>
]]></description>
   </item>
   <item>
      <title>dynamically show videos added to a folder</title>
      <link>https://forum.processing.org/two/discussion/10738/dynamically-show-videos-added-to-a-folder</link>
      <pubDate>Sun, 10 May 2015 17:56:05 +0000</pubDate>
      <dc:creator>stankugo</dc:creator>
      <guid isPermaLink="false">10738@/two/discussions</guid>
      <description><![CDATA[<p>hej –</p>

<p>i know how to play/loop an existing video. but what if i have a folder in which videos will be copied (from an external source – in my case a raspberry pi that uploads captured video clips) dynamically?</p>

<p>can i add videos to my canvas on runtime? there is a function to list folder contents – but i don't know HOW TO dynamically add video sources to a running project.</p>

<p>is there any help? or a definitive "NO" …?
thanks anyways!</p>

<p>– stephan</p>
]]></description>
   </item>
   </channel>
</rss>