<?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 delay() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=delay%28%29</link>
      <pubDate>Sun, 08 Aug 2021 18:59:49 +0000</pubDate>
         <description>Tagged with delay() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggeddelay%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <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>Connect PIR sensor to launch a webcam and a sound</title>
      <link>https://forum.processing.org/two/discussion/26474/connect-pir-sensor-to-launch-a-webcam-and-a-sound</link>
      <pubDate>Wed, 21 Feb 2018 23:46:34 +0000</pubDate>
      <dc:creator>braisremeseiro</dc:creator>
      <guid isPermaLink="false">26474@/two/discussions</guid>
      <description><![CDATA[<p>Hi again,</p>

<p>I am trying to connect Arduino with Processing using a PIR Sensor. The code in Arduino is alright, however I can not synchronize both to detect the movement and open the webcam and the sound. Please, Can you help me?.</p>

<p>Arduino:</p>

<pre><code>//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;       

//the time when the sensor outputs a low impulse
long unsigned int lowIn;        

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000; 

boolean lockLow = true;
boolean takeLowTime; 

int pirPin = 3;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;


/////////////////////////////
//SETUP
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pirPin, LOW);

//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i &lt; calibrationTime; i++){
  Serial.print(".");
  delay(1000);
  }
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}

 ////////////////////////////
 //LOOP
 void loop(){

 if(digitalRead(pirPin) == HIGH){
   digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
   if(lockLow){ 
     //makes sure we wait for a transition to LOW before any further output is made:
     lockLow = false;           
     Serial.println("---");
     Serial.print("motion detected at ");
     Serial.print(millis()/1000);
     Serial.println(" sec");
     delay(50);
     }        
     takeLowTime = true;
    }

   if(digitalRead(pirPin) == LOW){      
   digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

   if(takeLowTime){
    lowIn = millis();          //save the time of the transition from high to LOW
    takeLowTime = false;       //make sure this is only done at the start of a LOW phase
    }
   //if the sensor is low for more than the given pause,
   //we assume that no more motion is going to happen
   if(!lockLow &amp;&amp; millis() - lowIn &gt; pause){ 
       //makes sure this block of code is only executed again after
       //a new motion sequence has been detected
       lockLow = true;                       
       Serial.print("motion ended at ");      //output
       Serial.print((millis() - pause)/1000);
       Serial.println(" sec");
       delay(50);
       }
     }
     }
</code></pre>

<p>Processing:</p>

<pre><code>import processing.serial.*;
import processing.video.*;
import ddf.minim.*;
import ddf.minim.AudioPlayer;

// Size of each cell in the grid
int cellSize = 20;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture inputCam01;
Movie topLayer;
Minim minim;
AudioPlayer song;
Serial myPort;

void setup() 
{
size(1280, 720);
frameRate(30);
cols = width / cellSize;
rows = height / cellSize;
colorMode(RGB, 255, 255, 255, 100);

// This the default video input, see the GettingStartedCapture 
// example if it creates an error
inputCam01 = new Capture(this, width, height);

// Start capturing the images from the camera
inputCam01.start();  
background(0);

// we pass this to Minim so that it can load files from the data directory
minim = new Minim(this);

// loadFile will look in all the same places as loadImage does.
// this means you can find files that are in the data folder and the 
// sketch folder. you can also pass an absolute path, or a URL.
song = minim.loadFile("data/untitled.wav");
song.play();
song.loop();
}
{
// I know that the first port in the serial list on my mac
// is Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
 String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
 myPort = new Serial(this, portName, 9600);
}
void movieEvent(Movie topLayer)  
{  
topLayer.read();
}


void draw() 
{ 
if (inputCam01.available()) {
inputCam01.read();
inputCam01.loadPixels();
image(inputCam01, 0, 0);

// Begin loop for columns
for (int i = 0; i &lt; cols; i++) {
  // Begin loop for rows
  for (int j = 0; j &lt; rows; j++) {
    // Where are we, pixel-wise?
    int x = i*cellSize;
    int y = j*cellSize;
    int loc = (inputCam01.width - x - 1) + y*inputCam01.width; // Reversing x to mirror       the image

    float r = red(inputCam01.pixels[loc]);
    // Make a new color with an alpha component
    color c = color(r, 50, 50, 75);

    // Code for drawing a single rect
    // Using translate in order for rotation to work properly
    pushMatrix();
    translate(x+cellSize/2, y+cellSize/2);
    // Rotation formula based on brightness
    rotate((2 * PI * brightness(c) / 255.0));
    rectMode(CENTER);
    fill(c);
    noStroke();
    // Rects are larger than the cell for some overlap
    rect(0, 0, cellSize+6, cellSize+6);
    popMatrix();
}
}
}
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Understanding Callback with respect to selectInput()</title>
      <link>https://forum.processing.org/two/discussion/26196/understanding-callback-with-respect-to-selectinput</link>
      <pubDate>Wed, 31 Jan 2018 14:53:17 +0000</pubDate>
      <dc:creator>GregN</dc:creator>
      <guid isPermaLink="false">26196@/two/discussions</guid>
      <description><![CDATA[<p>Hello all.  I'm new to this, but not so new to basic coding, but it has been a long time since I've done any serious coding...</p>

<p>Here's my issue -- I have a Processing script that loads in a text file, parses it out and sends some info to an Arduino board.  It works great, but I'd like to present the operator with the option of selecting a file, but I'm having trouble getting my head around the concept of "callback" stuff and in specific how to use it with the selectInput() function.</p>

<p>For the purposes of this, I have stripped out all the other stuff and just have the file load bits...</p>

<pre><code>String[] protocol;
String[] fname;
int flag=0;

void setup() {
  selectInput("Select a file to process:", "fileSelected");
  while(flag==0){
    if(protocol!=null){
      flag=1;
    }
  }
  println(protocol[0]);  
}

void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
    protocol = loadStrings(selection.getAbsolutePath());
  }
}
</code></pre>

<p>My idea is that by putting the while loop it should hold the code until the variable protocol has something other than null.  I have a feeling that I'm barking up the wrong tree with this and that null is the wrong thing to be checking for?</p>

<p>Any ideas or links to some tutorials or whatever would be greatly appreciated!!</p>

<p>Greg</p>
]]></description>
   </item>
   <item>
      <title>How to draw a rect() in a Thread</title>
      <link>https://forum.processing.org/two/discussion/25799/how-to-draw-a-rect-in-a-thread</link>
      <pubDate>Wed, 03 Jan 2018 11:41:45 +0000</pubDate>
      <dc:creator>Geist5000</dc:creator>
      <guid isPermaLink="false">25799@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I am trying to draw a rectangle in the window from a Thread.</p>

<p><code>void setup(){
  size(100,100);
  T thread = new T();
  thread.start();
}
class T extends Thread{
  void run(){
    rect(10,10,10,10);
  }
}</code></p>

<p>But this didn't work. I hobe someone can help me?</p>

<p>Thank you!</p>
]]></description>
   </item>
   <item>
      <title>SelectOutput doesn't have any effect</title>
      <link>https://forum.processing.org/two/discussion/24629/selectoutput-doesn-t-have-any-effect</link>
      <pubDate>Wed, 18 Oct 2017 20:54:36 +0000</pubDate>
      <dc:creator>Karli</dc:creator>
      <guid isPermaLink="false">24629@/two/discussions</guid>
      <description><![CDATA[<p>I have modified a sketch which records sound and saves it on harddrive. 
In the setup-function, i call the selectOutput function.  When i run the sketch, i can choose an output-file, but the data get saved in the default-output-file, which i have specified above the setup-function. 
Why does selectOutput have no effect on the output-file?</p>

<p>Here is the complete code:</p>

<pre><code> import ddf.minim.*;

    Minim minim;
    AudioInput in;
    AudioRecorder recorder;
    String absoluterPfad = "/home/karl-alfred/Schreibtisch/myrecording.wav";

    void setup()
    {
      size(512, 200, P3D);

      minim = new Minim(this);

      in = minim.getLineIn();
      // create a recorder that will record from the input to the filename specified
      // the file will be located in the sketch's root folder.
      selectOutput("Select a file to process:", "fileSelected");
      recorder = minim.createRecorder(in, absoluterPfad);
      textFont(createFont("Arial", 12));
    }

     void fileSelected(File selection) {
      if (selection == null) {
        println("Window was closed or the user hit cancel.");
      } else {
        println("User selected " + selection.getAbsolutePath());
       absoluterPfad = selection.getAbsolutePath();
       println ("Absoluter Pfad: " + absoluterPfad);
      }
    }


    void draw()
    {
      background(0); 
      stroke(255);
      // draw the waveforms
      // the values returned by left.get() and right.get() will be between -1 and 1,
      // so we need to scale them up to see the waveform
      for(int i = 0; i &lt; in.bufferSize() - 1; i++)
      {
        line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
        line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
      }

      if ( recorder.isRecording() )
      {
        text("Currently recording...", 5, 15);
      }
      else
      {
        text("Not recording.", 5, 15);
      }
    }

    void keyReleased()
    {
      if ( key == 'r' ) 
      {
        // to indicate that you want to start or stop capturing audio data, you must call
        // beginRecord() and endRecord() on the AudioRecorder object. You can start and stop
        // as many times as you like, the audio data will be appended to the end of whatever 
        // has been recorded so far.
        if ( recorder.isRecording() ) 
        {
          recorder.endRecord();
        }
        else 
        {
          recorder.beginRecord();
        }
      }
      if ( key == 's' )
      {
        // we've filled the file out buffer, 
        // now write it to the file we specified in createRecorder
        // the method returns the recorded audio as an AudioRecording, 
        // see the example  AudioRecorder &gt;&gt; RecordAndPlayback for more about that
        recorder.save();
        println("Done saving.");
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Any precedence of built-in functions? (text(), delay()...etc...)</title>
      <link>https://forum.processing.org/two/discussion/24498/any-precedence-of-built-in-functions-text-delay-etc</link>
      <pubDate>Wed, 11 Oct 2017 20:50:53 +0000</pubDate>
      <dc:creator>lowbpro</dc:creator>
      <guid isPermaLink="false">24498@/two/discussions</guid>
      <description><![CDATA[<p>Hi friends,</p>

<p>I am just wondering below code, a simple one:</p>

<pre><code>void setup() {
  size(200,200);
  background(0);
}

void draw() {
  fill(255);
  text("hi",80,80);
  delay(1000);
  text("hi2",80,80);
  background(0);
  text("hi3",80,80);
}
</code></pre>

<p>My thought is that the window will show "hi", then wait for 1 second, show "hi2", clean up, then "hi3".
However, what i see is: keep showing "hi3".
What's more strange is that, when i go into debugger mode step by step, I find "hi" is not showing up at all! So i get confused if, within the draw() loop, there is precedence of these regular functions?
Thanks to all!</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>What happened to delay</title>
      <link>https://forum.processing.org/two/discussion/23906/what-happened-to-delay</link>
      <pubDate>Wed, 23 Aug 2017 20:59:44 +0000</pubDate>
      <dc:creator>StereoFrog</dc:creator>
      <guid isPermaLink="false">23906@/two/discussions</guid>
      <description><![CDATA[<p><img src="https://forum.processing.org/two/uploads/imageupload/709/UOG6IJGQM55A.png" alt="uwt" title="uwt" /></p>

<p>My head just hurts. If you do this it doesn't work right it just stuck until all letters are displayed and if you remove "while" it still doesn't work also x=1; is done so to test if in second draw re-run it works. You can actually fix this if you like moving entire app to side cuz when mouse holding app touches side of screen app works for that moment and it can't be still.</p>
]]></description>
   </item>
   <item>
      <title>How to make a shape appear progressively in Processing</title>
      <link>https://forum.processing.org/two/discussion/23718/how-to-make-a-shape-appear-progressively-in-processing</link>
      <pubDate>Sat, 05 Aug 2017 10:19:30 +0000</pubDate>
      <dc:creator>corinnev</dc:creator>
      <guid isPermaLink="false">23718@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I am beginner - discovered Processing code 2 weeks ago -.
I drawn some lines and should like to let them appear progressively. I tried with stroke(#FFFFFF,0) (0 as alpha and it doesn't appear), and stroke(#FFFFFF,500) and it is perfectly white. But I can't do it progressively. Here the code. Thanks for your help.</p>

<p>int i;</p>

<p>void setup() {
  size(1000, 800);
  background(0);
}</p>

<p>void draw() { 
    strokeWeight(6);
    for (int i = 0; i &lt; 1000; i = i+1) {
    stroke(#FFFFFF,i);
}
  line(422,0,564,213);
  line(564,217,570,647);
  line(640,653,617,288);
  line(619,290,809,575);
  line(809,575,819,648);
  line(902,648,553,1);
}</p>
]]></description>
   </item>
   <item>
      <title>Can't see how delay works.</title>
      <link>https://forum.processing.org/two/discussion/23642/can-t-see-how-delay-works</link>
      <pubDate>Sun, 30 Jul 2017 17:48:58 +0000</pubDate>
      <dc:creator>2000mater</dc:creator>
      <guid isPermaLink="false">23642@/two/discussions</guid>
      <description><![CDATA[<p>Script looks like the following, but "other" and "stuff" appear at the same time after the delay. I want them to have delay between each other and I also want to start "void stuff" only from "void other", so what should I do?</p>

<pre><code>PFont allfont;

void setup() {
  size(1280,720);
  allfont = createFont("8bitoperator_jve.ttf",100);
  textFont(allfont);
  textAlign(CENTER,CENTER);
  other();
}

void other() {
  text("other",width/2,height/2);
  stuff();
}

void stuff() {
  delay(1000);
  text("stuff",width/2 + 250,height/2);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Blocking version of selectFolder()</title>
      <link>https://forum.processing.org/two/discussion/23385/blocking-version-of-selectfolder</link>
      <pubDate>Mon, 10 Jul 2017 04:40:44 +0000</pubDate>
      <dc:creator>paulbourke</dc:creator>
      <guid isPermaLink="false">23385@/two/discussions</guid>
      <description><![CDATA[<p>As per the subject, is there a way to create a blocking version of selectFolder()?
I want to ask for the folder of images in setup(), it doesn't make sense to proceed without that directory.</p>
]]></description>
   </item>
   <item>
      <title>Resizing a Movie - Possible Bug?</title>
      <link>https://forum.processing.org/two/discussion/23389/resizing-a-movie-possible-bug</link>
      <pubDate>Mon, 10 Jul 2017 14:14:46 +0000</pubDate>
      <dc:creator>danlj</dc:creator>
      <guid isPermaLink="false">23389@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm getting some inconsistent behaviour with PImage.width, PImage.height, and PImage.resize() when working with Movie files. Width and height will almost always return 0, though will occasionally return the correct dimensions. PImage.resize() will sometimes throw an error: "Width(0) and Height(0) cannot be &lt;= 0" - even when the dimensions are hardcoded in. I'm posting this here because I'm not sure whether this is a bug or I'm just doing something silly with the code:</p>

<p>macOS 10.12.5; Quicktime 10.4; P3.3.5</p>

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

Movie m;
PImage mS;
int vScale = 4;
int mW;
int mH;

void setup() {
  size(480, 270);
  m = new Movie(this, "test.mov"); // original dim: 1920 1080
  m.loop();
  mW = m.width; 
  mH = m.height;

  // Almost always returns 0 for both values, but occasionally returns the correct dimensions.  
  println("width: " + mW +" " + "Height: " + mH); 
}

void draw() {
  mS = m.get();

  //This almost never works
  //mS.resize(mW/vScale, mH/vScale); 

  //This works most of the time, but not always!
  //mS.resize(1920/vScale, 1080/vScale); 

  //Again works most of the time, but not always...
  mS.resize(480, 270);


  image(mS, 0, 0);
}

void movieEvent(Movie m) {
 m.read(); 
}
</code></pre>
]]></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>Dare I ask about the 'delay' function!?</title>
      <link>https://forum.processing.org/two/discussion/22364/dare-i-ask-about-the-delay-function</link>
      <pubDate>Wed, 03 May 2017 12:17:44 +0000</pubDate>
      <dc:creator>Martin1209</dc:creator>
      <guid isPermaLink="false">22364@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I am trying to complete a very simple operation. From a quick google I know that the 'delay' function is something that is to generally be avoided, but my scenario is so simple, but I don't get why it isn't working.
(All within draw function)</p>

<pre><code>          if (//goal event occurs)
           {
             reset();
             Score ++;
             text("goal",500,500);
             delay(2000);     
           }
</code></pre>

<p>As you can see, all I want is for the word 'goal' to flash up for 2s prior to the game resetting. However, running it this way(or with reset() after the delay, seems to just get it stuck displaying goal for eternity. Could anyone suggest an easy fix?</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>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>accessing a variable in a thread, coming from a variable inside another thread</title>
      <link>https://forum.processing.org/two/discussion/20991/accessing-a-variable-in-a-thread-coming-from-a-variable-inside-another-thread</link>
      <pubDate>Fri, 24 Feb 2017 19:04:54 +0000</pubDate>
      <dc:creator>secondsky</dc:creator>
      <guid isPermaLink="false">20991@/two/discussions</guid>
      <description><![CDATA[<p>Hi all, is some days i'm doing experiments on running threads in parallel.
Except the fact that probably this is not the best way to do this, since would be possible to point some external variable, i really don't understand why, if i try to access a variable inside a runnable implementation it works, but it don't if this implementation is trying to do the same:</p>

<pre><code>class0 c0;

void setup() {
  size(200, 200);

  c0 = new class0();
  new Thread(c0).start();
}

void draw() {

  background(200);
  text(c0.dataToAccess, 30, 30);
}

class class0 implements Runnable {
  public int dataToAccess;
  public int interations = 0;

  class1 c1;

  class0() {
    c1 = new class1();
    new Thread(c1).start();
  }

  //@Override
    public void run() {
    while (!c1.done) {
      this.dataToAccess =c1.dataToAccess;
    //  println("iteration n" + interations++);
    }
  }
}

class class1 implements Runnable {
  public int dataToAccess;
  public boolean done = false;

  //@Override
    public void run() {
    for (int i = 0; i&lt;=100; i++)
    {
      dataToAccess++;
      delay(500);
       println("iteration n° " + i);
    }
    done = true;
  }
}
</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>Pause draw()</title>
      <link>https://forum.processing.org/two/discussion/19514/pause-draw</link>
      <pubDate>Sun, 04 Dec 2016 21:46:44 +0000</pubDate>
      <dc:creator>ppardozz</dc:creator>
      <guid isPermaLink="false">19514@/two/discussions</guid>
      <description><![CDATA[<p>I know that is not a good practice using delay() but i'm trying different ways to pause a sketch and I can't.</p>

<p>I'm trying to run a simple program, with minim, when line in reaches X volume, a trigger is shot, and the program shows and image for two seconds. Then, the program continues listening to. I load the image outside the bounds of the canvas (x and y = 3000) and when the volume reaches 100, x and y is changed to 0 0, so, the image appears in the screen.</p>

<p>For now all works but the delay.
How could I make the program pause for two seconds while is showing the image?
I can make the delay when I want, but the image appears AFTER it, not before.</p>

<p>Thanks!</p>

<p>This is my code:</p>

<pre><code>import ddf.minim.*;

Minim minim;
AudioInput in;
PImage img;
PFont font;

float maxValue;
float minValue;
int frameValue;
  int posX =3000;
  int posY = 3000;

void setup()
{
  size(800, 600, P3D);
 img = loadImage("/Users/pablo/Downloads/vamo.jpg");
frameValue=200;
  minim = new Minim(this);
  minim.debugOn();
  // use the getLineIn method of the Minim object to get an AudioInput
  in = minim.getLineIn(Minim.STEREO, 512);
  font = createFont ("Arial", 60);

   posX =3000;
   posY = 3000;
}

void draw()
{

  background(0);
  stroke(255);
  image(img, posX, posY);
  //actual
  text("Actual: "+in.right.level()*100, 10, height/2);

   if(in.right.level()*100&gt;10){   //if the volume reaches 10
     println("im in");
      posX=30;
      posY=30;
      //delay(3000);
      //frameRate(10);
  }else{
      posX=3000;
      posY=3000;
  }

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can I start processing without opening a window?</title>
      <link>https://forum.processing.org/two/discussion/18794/can-i-start-processing-without-opening-a-window</link>
      <pubDate>Sun, 30 Oct 2016 17:11:50 +0000</pubDate>
      <dc:creator>Matei</dc:creator>
      <guid isPermaLink="false">18794@/two/discussions</guid>
      <description><![CDATA[<p>So it's something very basic, but I really wonder if there is a way to do it, as I searched for a while without success. My purpose is to manipulate image files. So, I don't need anything to be displayed until I choose a file. Once done, I want the image to be displayed with the proper dimensions. Here is the very simple code for that, <strong>but I can't get rid of the first window of 600x600 pixels</strong>, so maybe you know a way to do that?</p>

<pre><code>PImage loadedImgage;
String selectedPath = "";

void fileSelected(File selection) {
  selectedPath = selection.getAbsolutePath();
}

void setup() {
  size(600, 600);
  selectInput("Select a file to process:", "fileSelected");
}

void draw() {  
  if(selectedPath != ""){
    loadedImgage = loadImage(selectedPath);
    image(loadedImgage, 0, 0);
  }
}
</code></pre>
]]></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>opencv problem with bootcamp</title>
      <link>https://forum.processing.org/two/discussion/18536/opencv-problem-with-bootcamp</link>
      <pubDate>Thu, 13 Oct 2016 22:27:38 +0000</pubDate>
      <dc:creator>jayson</dc:creator>
      <guid isPermaLink="false">18536@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to do face detection on a video with opencv on bootcamp (windows 10) and processing 2.2.1</p>

<blockquote class="Quote">
  <p>import processing.video.*;</p>
  
  <p>Movie video;
  import gab.opencv.*;
  import java.awt.Rectangle;</p>
  
  <p>OpenCV opencv;
  Rectangle[] faces;</p>
  
  <p>void setup()
  {
    size(640,360);</p>
  
  <p>video = new Movie(this, "people.mp4");
    video.play();
    video.loop();
  <br />
     opencv = new OpenCV(this, video.width, video.height);
     opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
  }</p>
  
  <p>void draw()
  {
    background(0);
    fill(255);
  <br />
    image(video,0,0);
  <br />
    opencv.loadImage(video);
    faces = opencv.detect();
  <br />
  }</p>
  
  <p>void movieEvent(Movie m)
  {
      m.read();
  <br />
  }</p>
</blockquote>

<p>It crashes at the line: 
  opencv.loadImage(video);</p>

<p>With the message: IndexOutOfBoundsException: Index 3: Size 0</p>

<p>Any ideas? This works fine on mac osx with the same version of processing.</p>
]]></description>
   </item>
   <item>
      <title>partially delaying</title>
      <link>https://forum.processing.org/two/discussion/18182/partially-delaying</link>
      <pubDate>Thu, 15 Sep 2016 22:25:24 +0000</pubDate>
      <dc:creator>juicy</dc:creator>
      <guid isPermaLink="false">18182@/two/discussions</guid>
      <description><![CDATA[<p>Hello Forum!</p>

<p>First off: i'm new to processing, coding and everything around it, so excuse my ignorance :)
I created a WASD moveable rectangle on the screen, which doubles it size when you hit the spacebar.</p>

<p>After that, it transforms to its original state.
In between the transformation (when it's doubled), i want a delay (no specific time).
I tried using time.sleep and delay, but everything seems to freeze the entire program (including the movement controls.
How will I be able to only delay only the one statement?</p>

<p>Thanks in advance!</p>

<pre><code>if space_pressed == True:
    rectSize += 2 
if rectSize == 200:
    space_pressed = False
    delay (5000)    
if rectSize &gt;= 100 and space_pressed == False: 
    rectSize += -2 
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to set processing to automatically detect an image size and set it as a background?</title>
      <link>https://forum.processing.org/two/discussion/18033/how-to-set-processing-to-automatically-detect-an-image-size-and-set-it-as-a-background</link>
      <pubDate>Thu, 01 Sep 2016 14:42:54 +0000</pubDate>
      <dc:creator>testnia</dc:creator>
      <guid isPermaLink="false">18033@/two/discussions</guid>
      <description><![CDATA[<p>From my understanding, setting a background image in processing requires the size of the window to match the dimension of the image.</p>

<pre><code>PImage img = loadImage("background.jpg"); //a 100x100 background image.
size(100,100);
background(img);
</code></pre>

<p>However, since size() does not take in variables, how are we suppose to define a background with variable dimensions?</p>

<p>I have tested with the surface.setSize() function but it does not see to work.</p>

<p>Example:</p>

<pre><code>PImage img = loadImage("background.jpg"); //a 100x100 background image.
surface.setSize(img.width,img.height);
background(img);
</code></pre>
]]></description>
   </item>
   <item>
      <title>Wait and then do some action.</title>
      <link>https://forum.processing.org/two/discussion/17186/wait-and-then-do-some-action</link>
      <pubDate>Fri, 17 Jun 2016 13:51:13 +0000</pubDate>
      <dc:creator>Shoxy</dc:creator>
      <guid isPermaLink="false">17186@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone.
I'm making a FPS game and I need help. I have a gun with magazine and I want to do some delay between reloading. I mean I have count of bullet I'm shooting, then I want to reload my gun so a press 'r' key on keyboard.
I have this for reload but i want do some delay:</p>

<p><code>void keyPressed(KeyEvent e) {
if (key == 'r') {
    if (p.magazine!=p.bullets) { 
      // Here I would like , for example, a 2 seconds delay. ( after 2 second reload the gun. )
      p.magazine= p.bullets;  // This is for reload.
    }
  }
}</code>
When i try just <code>delay(2000);</code>. It stops the whole game, but i don't want stop game but just wait 2 seconds and then reload without <code>noLoop();</code>
Thanks for you advice.</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>null pointer exception when loading image in settings P3.1.1</title>
      <link>https://forum.processing.org/two/discussion/16705/null-pointer-exception-when-loading-image-in-settings-p3-1-1</link>
      <pubDate>Thu, 19 May 2016 17:22:47 +0000</pubDate>
      <dc:creator>x13420x</dc:creator>
      <guid isPermaLink="false">16705@/two/discussions</guid>
      <description><![CDATA[<pre><code>PImage canvas;PImage paint;
void settings(){
selectInput("Please select canvas:", "selectImage");
interrupt();
println("dog",input,"dog");
canvas = loadImage(input);
size(canvas.width, canvas.height);
noSmooth();} 
</code></pre>

<p>Posted this as a bug they are saying that I am doing it wrong.....but works fine in 3.1
<a href="https://github.com/processing/processing-docs/issues/436" target="_blank" rel="nofollow">https://github.com/processing/processing-docs/issues/436</a></p>

<p>If there a better way of doing this???image is loaded....github seems  very chaotic...like fixing one thing often messes up other stuff.</p>
]]></description>
   </item>
   <item>
      <title>Screen not refreshing</title>
      <link>https://forum.processing.org/two/discussion/16059/screen-not-refreshing</link>
      <pubDate>Sun, 17 Apr 2016 14:33:22 +0000</pubDate>
      <dc:creator>mfuster</dc:creator>
      <guid isPermaLink="false">16059@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to load variables from a table into text on Processing but at the moment the code just seems to write the variables on top of themselves. I would like these variables to change per second (hence the delay at the end of void draw()).
The results (text) also seem to take a very long time to show up on the screen. I have tried various ways but I do not know what it is that I'm doing wrong.
This is the code:</p>

<p>Table table;
TableRow row;
int fData;</p>

<p>void setup() {
  size(800, 500);
  background(255);
  table = loadTable("test2.csv", "header");</p>

<p>println(table.getColumnCount() + " columns in table"); 
  println(table.getRowCount() + " rows in table"); 
  println("Date: " + table.getString(1, 0)); 
  println("Start time: " + table.getString(0, 1));
  println("Duration: " + (table.getRowCount()/60) + " minutes");</p>

<p>}</p>

<p>void draw () {
  background(255,255,255);
  text("Date: "+table.getString(0,0), 30,400);
  fill(0,0,0);</p>

<p>for (int i = 0; i &lt; 23; i = i+1) {</p>

<p>fData=((table.getInt(i,2))/1000);
  text("Time: "+table.getString(i,1), 30, 420); 
  text("Frequency: "+table.getInt(i,2), 30, 440); 
  text(("Frequency to alpha: "+fData), 30, 460);</p>

<p>delay(1000);<br />
  }</p>

<p>}</p>
]]></description>
   </item>
   </channel>
</rss>