<?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 substring() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=substring%28%29</link>
      <pubDate>Sun, 08 Aug 2021 18:43:29 +0000</pubDate>
         <description>Tagged with substring() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedsubstring%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Error, disabling serialEvent()</title>
      <link>https://forum.processing.org/two/discussion/28124/error-disabling-serialevent</link>
      <pubDate>Sat, 22 Sep 2018 19:34:23 +0000</pubDate>
      <dc:creator>laptophead</dc:creator>
      <guid isPermaLink="false">28124@/two/discussions</guid>
      <description><![CDATA[<p>The full message I am getting is: Error, disabling serialEvent() for /dev/cu.usbmodem2574541
null</p>

<p>The sketch will get the data one time than it hangs on this message.</p>

<p>Here is my code;   I am getting the data from an arduino teensy 3.5
Please help.</p>

<p>Thanks</p>

<p>import processing.serial.*;
Serial port;
int BaseEncGlobal;
int ElbowEncGlobal;
int ShoEncGlobal;
int VertRotEnc;
int HorRotEnc;
int GripEncGlobal;</p>

<p>double X_axis;
double Y_axis;
double Z_axis;
double GripAngle;</p>

<p>String data;
boolean newData = false;</p>

<p>PFont font;</p>

<p>void setup()
{
  size(1280,800);
  //port =  new Serial(this, "/dev/cu.usbserial-A50285BI", 115200);
  port =  new Serial(this, "/dev/cu.usbmodem2574541", 115200);
  port.bufferUntil('\n'); 
  font = loadFont("AgencyFB-Bold-200.vlw");
  textFont(font, 40);
}</p>

<p>void draw()</p>

<p>{ if (newData == true) {</p>

<p>int spaceDown = 55;
  background(0,0,0);
  fill(46, 209, 2);
  text(BaseEncGlobal, 70, spaceDown);
  fill(0, 102, 153);
  text(ShoEncGlobal, 70, spaceDown<em>2);
  fill(0, 102, 153);
 text(ElbowEncGlobal, 70, spaceDown</em>3);
  fill(0, 102, 153);
 text(VertRotEnc, 70, spaceDown<em>4);
  fill(0, 102, 153);
text(HorRotEnc, 70, spaceDown</em>5);
  fill(0, 102, 153);
  text( GripEncGlobal, 70, spaceDown*6);</p>

<p>text(Double.toString(X_axis/10), 270, spaceDown );
newData =false;
}</p>

<p>}</p>

<p>void serialEvent (Serial port)
{</p>

<p>data = port.readStringUntil('\n');
 if (data != null)
 {
 data = trim(data);</p>

<p>int[] nums = int(split(data, ','));
 BaseEncGlobal =  nums [1];
 ShoEncGlobal  =  nums [2];
 ElbowEncGlobal =  nums [3];
 VertRotEnc    =  nums [4];
 HorRotEnc     =  nums [5];
 GripEncGlobal =  nums [6];
 X_axis =  nums [7];
  Y_axis =  nums [8];
   Z_axis =  nums [9];
    GripAngle =  nums [10];
 //println(Double.toString(X_axis/10));</p>

<p>println(data);</p>

<p>newData = true;
 }</p>

<p>}</p>

<p>/*</p>

<p>void serialEvent (Serial port)
{
  data = port.readStringUntil('.');
  data = data.substring(0, data.length() - 1);</p>

<p>// look for the comma between Celcius and Farenheit
  index = data.indexOf(",");
  // fetch the C Temp
  temp_c = data.substring(0, index);
  // fetch the F Temp
  //temp_f = data.substring(index+1, index);
  temp_f = data.substring(1, data.length());</p>

<pre><code>ElbowEncGlobal =  getValue(data, ',', 2);
</code></pre>

<p>}
*/</p>
]]></description>
   </item>
   <item>
      <title>make text appear letter by letter</title>
      <link>https://forum.processing.org/two/discussion/28090/make-text-appear-letter-by-letter</link>
      <pubDate>Thu, 02 Aug 2018 21:39:17 +0000</pubDate>
      <dc:creator>Birckk</dc:creator>
      <guid isPermaLink="false">28090@/two/discussions</guid>
      <description><![CDATA[<p>I've made this code thingy but can't find any other way than the one shown down below to make the letters appear one by one :) hope someone can help.</p>

<pre><code>boolean begin = false;
int time;
int elapsedTime;

void setup() { 
  size (600, 600, JAVA2D);
}


void draw() { 
  String start = "This is a quickstory...";
  String story= "";

  background(0,0,0);

  if (elapsedTime&gt;=1500){  start = start+" and it's a fun one :).."; }
  if (elapsedTime&gt;=3000){  start = start+" but it can quickly get a little hectic!!!"; }

  if (elapsedTime&gt;=5000){story = story+"I";}
  if (elapsedTime&gt;=5100){story = story+" ";}
  if (elapsedTime&gt;=5200){story = story+"o";}
  if (elapsedTime&gt;=5300){story = story+"n";}
  if (elapsedTime&gt;=5400){story = story+"c";}
  if (elapsedTime&gt;=5500){story = story+"e";}
  if (elapsedTime&gt;=5600){story = story+" ";}
  if (elapsedTime&gt;=5700){story = story+"t";}
  if (elapsedTime&gt;=5800){story = story+"o";}
  if (elapsedTime&gt;=5900){story = story+"o";}
  if (elapsedTime&gt;=6000){story = story+"k";}
  if (elapsedTime&gt;=6100){story = story+" ";}
  if (elapsedTime&gt;=6200){story = story+"a";}
  if (elapsedTime&gt;=6300){story = story+" ";}
  if (elapsedTime&gt;=6400){story = story+"w";}
  if (elapsedTime&gt;=6500){story = story+"a";}
  if (elapsedTime&gt;=6600){story = story+"l";}
  if (elapsedTime&gt;=6700){story = story+"k";}
  if (elapsedTime&gt;=7500){story = story+" down to the beach but ended up getting cold feet and went home again"; }

  if (begin) {

    elapsedTime = millis() - time;
    text("Press E to end", 20, 30);

    text(start, 20, 50);
    text(story, 20, 70);

  }
  else { textAlign(CENTER);text("Press S to start", 300, 300); textAlign(LEFT); }

}

void keyPressed(){ 
    if (key == 's' || key == 'S') {
    time = millis();
    // start music
    begin = true;
  }
    if (key == 'e' || key == 'E') {
    begin = false;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Unable to use substring() function within an array. (Parsing irishrail)</title>
      <link>https://forum.processing.org/two/discussion/27687/unable-to-use-substring-function-within-an-array-parsing-irishrail</link>
      <pubDate>Wed, 04 Apr 2018 01:03:33 +0000</pubDate>
      <dc:creator>Neowso</dc:creator>
      <guid isPermaLink="false">27687@/two/discussions</guid>
      <description><![CDATA[<p>I am getting an error when I attempt to use substring() as I iterate through an array. I want to extract an integer from a string of text. This works fine outside of an array:</p>

<pre><code>    String trainInfo = "E215\n17:30 - Howth to Bray (-3 mins late)\nArrived Dublin Connolly next stop Tara Street";
    int start      = trainInfo.indexOf("(" ) + 1;  // STEP 1 
    int end        = trainInfo.indexOf(" mins", start);      // STEP 2
    String status  = trainInfo.substring(start, end);    // STEP 3
    int status_no   = int(status);                    // STEP 4
    println(status_no);
</code></pre>

<p>Whereas in my case I get an error at the point of the substring():</p>

<pre><code>    void requestData() {   
      for (int i = 0; i &lt; children.length; i++) {     

        XML announcementElement = children[i].getChild("PublicMessage");
        String announcement = announcementElement.getContent(); 

        int start      = announcement.indexOf("(" ) + 1;        // STEP 1 
        int end        = announcement.indexOf(" mins", start);  // STEP 2
        String status  = announcement.substring(start, end);    // STEP 3    ***error thrown at this point***
        int status_no   = int(status);                          // STEP 4

        println(status_no);
      }
    } 
</code></pre>

<p>[edit] Though not strictly related to Processing, I found a thread in the following forum that indicates that javascript does not permit substrings within arrays. I guess the same applies to Processing?:
<a rel="nofollow" href="https://stackoverflow.com/questions/42429413/javascript-error-array-substring-is-not-a-function">https://stackoverflow.com/questions/42429413/javascript-error-array-substring-is-not-a-function</a></p>

<p>The responder recommends to "slice and then remove the commas" or to use join(''). I have tried to to slice() and join(), based on Processing documentation but it's not working out.</p>

<p>Would anyone know of a way to get around this? Many thanks :)</p>
]]></description>
   </item>
   <item>
      <title>'Typewrite' effect: typing one by one with delay on the strings?</title>
      <link>https://forum.processing.org/two/discussion/1823/typewrite-effect-typing-one-by-one-with-delay-on-the-strings</link>
      <pubDate>Tue, 03 Dec 2013 23:15:51 +0000</pubDate>
      <dc:creator>yunii</dc:creator>
      <guid isPermaLink="false">1823@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,</p>

<p>I am pretty new to processing and would like to know how I would approach the coding of a method to making some feedback messages look like it's being typed. 
I would think that you need to access the number of the letter in the string and make it delay one after another??</p>

<p>I searched around on OpenProcessing and fiddled with one example, although it goes backwards and I dont understand how the substring + text.length() work.</p>

<p>If I tried text.length() + 1 it gives a whole bunch of random letters where as I just want the letters of the string I declared to display.</p>

<p>Thank you very much in advanced for your attempts and assistance.</p>

<pre><code>//----------

String text1 = "Hello, Make this a typewriter ";
PFont font;

void setup() {
  size(400, 400);
  smooth();
  font = loadFont("Arial-Black-48.vlw");
  textFont(font, 20);
}

void draw() {

  background(150);
  fill(255);
  text(text1, 0, 40, width, height);
 typewriteText();

}

void typewriteText(){
    if(text1.length() &gt; 0) {
      text1 = text1.substring(0, text1.length() -1);
    }

}

//----------
</code></pre>
]]></description>
   </item>
   <item>
      <title>Array index and item as drawn text</title>
      <link>https://forum.processing.org/two/discussion/26675/array-index-and-item-as-drawn-text</link>
      <pubDate>Tue, 06 Mar 2018 15:50:50 +0000</pubDate>
      <dc:creator>Leo_Aguiar</dc:creator>
      <guid isPermaLink="false">26675@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,</p>

<p>Is there a way to have an array's indexes and items be drawn as text? I couldn't find anything specific on this and I'm a beginner to intermediate coder.</p>

<p>I've tried something like the following in the draw function: text("myArray indexes and items:" + myArray_name, 25, 25);</p>

<p>But the text that is drawn isn't anything I can understand. It seems like it's a hexadecimal number and not the familiar [0] item0 , [1] item1, [2] item2, [n] itemn format.</p>

<p>Do I need to do some sort of conversion where the array is transformed in to a String before it goes into the text()?</p>

<p>Thanks for the help!</p>
]]></description>
   </item>
   <item>
      <title>Why doesn't this function run in processing.js?</title>
      <link>https://forum.processing.org/two/discussion/26145/why-doesn-t-this-function-run-in-processing-js</link>
      <pubDate>Sat, 27 Jan 2018 23:10:41 +0000</pubDate>
      <dc:creator>FH79</dc:creator>
      <guid isPermaLink="false">26145@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I have written the following function, which formats text stored in a field of Strings (Textfeld) and stores the result in a new field (Textzeilen). It works fine in Processing, but once I try to execute it in a browser (using processing.js), it crashes with the error message "SyntaxError: missing ) after argument list".</p>

<pre><code>void ladeText(String datei)
{
  Textfeld = loadStrings(datei);

  Textzeilen = new String[2000];

  int i = 0, j = 0, k = 0;
  int breite = (int)(xt2-xt1-50);
  textFont(atari, 18);
  Textzeilen[0] = new String();
  textAnzMax = 0;
  do
  {
    char c = Textfeld[i].charAt(j);

    if(textWidth(Textzeilen[k] + c) &lt; breite)
    {
      Textzeilen[k] += c;
      j++;
    }
    else
    {
      int l = 0;
      while((int)Textfeld[i].charAt(j) != (int)' ') {j--; l++;}
      Textzeilen[k] = Textzeilen[k].substring(0, Textzeilen[k].length() - l);
      j++;
      k++;
      Textzeilen[k] = new String();
      textAnzMax++;
    }

    if(j==Textfeld[i].length()) 
    {
      if(i&gt;=Textfeld.length-1) break;
      j = 0;
      do
      {
        i++;
      }
      while(Textfeld[i].length() == 0);

      k++;
      Textzeilen[k] = new String();
      k++;
      Textzeilen[k] = new String();
      textAnzMax+=2;
    }
    //if(k&gt;=Textzeilen.length) Textzeilen = (String[])expand(Textzeilen);
  }
  while(true);

}
</code></pre>

<p>I strongly suspect it has something to do with the "char" datatype which doesn't exist in JS.</p>
]]></description>
   </item>
   <item>
      <title>How to save text into new txt everytime you save it</title>
      <link>https://forum.processing.org/two/discussion/25541/how-to-save-text-into-new-txt-everytime-you-save-it</link>
      <pubDate>Tue, 12 Dec 2017 20:24:57 +0000</pubDate>
      <dc:creator>Caseguy</dc:creator>
      <guid isPermaLink="false">25541@/two/discussions</guid>
      <description><![CDATA[<p>This is the code, this code saves the written text into a txt, but it always saves it into the same one, so the older text written in the txt file gets deleted. I would like it to save it into a new txt everytime the program saves it . How do i do so.</p>

<p>and another thing: how do i load the text in txt into the document, by clicking on another button :)</p>

<p>thanks in advance :)</p>

<pre><code>String str = "";

void setup(){
  size(400,400);
}

void draw(){
  background(0);
  fill(255);
  text(str,20,20,100,height-20);
  fill(128);
  if( over() ){
    fill(196);
  }
  rect(width-20,height-20,20,20);
}

boolean over(){
  return( mouseX&gt;width-20 &amp;&amp; mouseY &gt; height-20 );
}

void keyPressed(){
  if( keyCode == DELETE || keyCode == BACKSPACE ){
    if( str.length() &gt; 0 ){
      str = str.substring(0, str.length()-1);
    }
  } else {
    if( key != CODED ){
      str += key;
    }
  }
}

void mousePressed(){
  if( over() ){
    saveIt();
  }
}

void saveIt(){
  String[] strs = { str };
  saveStrings( "text.txt", strs );
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How can i make it possible to write freely and save it in processing.</title>
      <link>https://forum.processing.org/two/discussion/25531/how-can-i-make-it-possible-to-write-freely-and-save-it-in-processing</link>
      <pubDate>Tue, 12 Dec 2017 07:03:17 +0000</pubDate>
      <dc:creator>Caseguy</dc:creator>
      <guid isPermaLink="false">25531@/two/discussions</guid>
      <description><![CDATA[<p>The thing that i would like is to make a program that would let me type anthing that i want, and then when I click on a button the text that i have written in the program will be saved into a txt file.</p>
]]></description>
   </item>
   <item>
      <title>How do I get the sound files in my sketch to loop? The sound only plays once</title>
      <link>https://forum.processing.org/two/discussion/25542/how-do-i-get-the-sound-files-in-my-sketch-to-loop-the-sound-only-plays-once</link>
      <pubDate>Tue, 12 Dec 2017 22:00:03 +0000</pubDate>
      <dc:creator>adefelice</dc:creator>
      <guid isPermaLink="false">25542@/two/discussions</guid>
      <description><![CDATA[<p>Hi forums, I'm needing a little guidance with a simple thing here. Not sure if it's a code problem or some of the problems I've been reading about sound files not looping. I have the most up to date sound library and I'm on Processing 3.3.6. The sound files are mp3's. I'm also unsure of the if statements and where I currently have the loop function entered. I basically want this sketch to display the letter that is pressed, and play the sound file associated to it - but loop that sound until another key is pressed, playing another sound file.</p>

<p>Pasting the code here:</p>

<pre><code>import processing.sound.*;
import punktiert.math.Vec;
import punktiert.physics.*;

int x;
int y;
String typedWord = "";
//String[] sounds = {"a"," b", "c"}; 
SoundFile soundA,soundB,soundC,soundD,soundE,soundF,soundG,soundH,
soundI,soundJ,soundK,soundL,soundM,soundN,soundO,soundP,soundQ,soundR,soundS,soundT;

void setup() {
  size(1080 ,720);
  soundA = new SoundFile (this, "a.mp3");
  soundB = new SoundFile (this, "b.mp3");
  soundC = new SoundFile (this, "c.mp3");

}

void draw() {
  textSize(100);
  background (0);
  fill (random (255),random (255),random (255));
  text(typedWord, 250, height/2);

}

void keyPressed() {
  //println(key);
  if (key != 65535) {
    if (keyCode == BACKSPACE) {
  if (typedWord.length() &gt; 0) {
    typedWord = typedWord.substring(0, typedWord.length()-1); //erases the last character
  }
    }
    else {
  typedWord += key; //add the key to the word
  }
  }
     }


void keyReleased() {
     if ((key == 'a') || (key == 'A')) {
       soundA.loop();
     }
     if ((key == 'b') || (key == 'B')) {
       soundB.loop();
     }
      if ((key == 'c') || (key == 'C')) {
       soundC.loop();
      }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Trying to extrude a paragraph from text</title>
      <link>https://forum.processing.org/two/discussion/24925/trying-to-extrude-a-paragraph-from-text</link>
      <pubDate>Thu, 09 Nov 2017 10:06:31 +0000</pubDate>
      <dc:creator>Qode</dc:creator>
      <guid isPermaLink="false">24925@/two/discussions</guid>
      <description><![CDATA[<p>Hello!</p>

<p>I'm trying to extrude a paragraph of text from a large text file, on a scene-by-scene basis. The formatting of the text is done like this:</p>

<p>1 Johanna is een arm meisje van tien jaar oud. Haar vader heeft ze nooit gekend, hij was al weg nog voordat ze geen jaar oud was. Haar moeder was prostituee en is overleden tijdens haar geboorte. Sindsdien is ze ingetrokken bij een rijke familie waar ze voor in het huishouden werkt.<br />
2 Johanna loopt al zolang als ze kan herinneren met een verwondering voor wat zich achter de stadsmuren afspeelt. Ze heeft wel vaker over de muur of door de poorten de graslanden en de horizon gezien maar heeft nog nooit de stad verlaten. Dat de wereld zoveel groter is dan haar thuis plaats houdt haar vrijwel constant bezig.<br />
3 In het huishouden is ze een van manusje van alles, zo moet ze ook vaker boodschapjes doen en de rest van de staf te ondersteunen. Een oude butler van de familie genaamd "Gerardus" heeft een bijzondere band met de kleine Johanna, hij is haar beste vriend en het enige aanspreekpunt voor haar problemen.<br />
4 Op een dag moet ze samen met Gerardus een aantal boodschappen doen in de stad. Tijdens de boodschappen komen ze langs een van de de stadspoorten, ze blijft even staan en kijkt zoals altijd een momentje naar de horizon.<br />
5 "Wat moeten we gaan doen, Ger?" vraagt Johanna, "We moeten nog even bericht brengen aan iemand over adele, edele en redelijke zaken." Johanna heeft het altijd grappig gevonden hoe Gerardus de taken omschreef. "Wacht jij even hier Johanna? Ik moet even gauw naar binnen." "Tuurlijk, ik wacht wel" antwoord Johanna.<br />
6</p>

<p>With every paragraph clearly separated by a number in front. I've written 4 individual functions to help me do this:</p>

<pre><code>boolean isNumeric(char a){

      if(a &gt;=48 &amp;&amp; a &lt;= 57){
        println("isNumeric says yes.");
        return true;
      } else {
        return false;
      }
    }
</code></pre>

<p>IsNumeric will tell me whether a character is numeric or not and return true or false depending on the outcome.</p>

<pre><code>    int convertToNumeric(char a){
      int i = 0;
      if(isNumeric(a)){
        i = int(a)-48;
        println("convertToNumeric has converted "+a+" to "+i);
      } else if(isNumeric(a) != true){
        i = -1;
      }
      return i;
    }
</code></pre>

<p>convertToNumeric will then use IsNumeric to convert the character to a numeric value. If the character isn't a numeric value it will return a value of -1.</p>

<pre><code>    int largeNumberCheck(String message, int p){
      int num = 0;

      int a = convertToNumeric(message.charAt(p));
      int b = convertToNumeric(message.charAt(p+1));

      if (a == -1 &amp;&amp; b &gt; 0){
        num = b;
      }else if(b == -1 &amp;&amp; a &gt; 0){
        num = a;
      } else if(a &gt; 0 &amp;&amp; b &gt;0){
        num = (a*10) + b;
      }
      println("num set to "+num);
      return num;
    }
</code></pre>

<p>The largeNumberCheck will check the text I give it for large numbers, or numbers with two digits, it saves that in an integer and returns it. If it finds no large numbers it will just return the smaller one-digit number instead.</p>

<pre><code>    String extrudeParagraph(String message, int scene){
      String paragraph;
      int start = 0;
      int end = 0;

      for (int i = 0; i &lt; message.length(); i++) { 

        if (largeNumberCheck(message, i)==scene){
          println("start is set to "+i);
          start = i;
        }

      }

      for (int i = 0; i &lt; message.length(); i++) {

        if (largeNumberCheck(message, i)==scene+1){
          println("end is set to "+i);
          end= i;
        }

      }

      paragraph = message.substring(start,end);
      return paragraph;
    }
</code></pre>

<p>Last but not least is the extrude paragraph function itself, where it checks the text for a number indicating a paragraph, matches it to the current scene (so for scene 1 I would need paragraph 1) and then checks that text further for a number indicating the next paragraph's starting character. It saves the positions of both characters in two integers called start and end and will use that to create a substring from the total text.</p>

<p>Somewhere in here it goes wrong.</p>

<p>Check this image to see what processing writes to the console and what errors it gives me: <a href="https://www.dropbox.com/s/ydc2uunn6d4ph82/help.JPG?dl=0" target="_blank" rel="nofollow">https://www.dropbox.com/s/ydc2uunn6d4ph82/help.JPG?dl=0</a></p>

<p>I hope you guys can help me...</p>

<p>For anyone interested, I've linked the entire project here: <a href="https://www.dropbox.com/sh/uy3jtdov9s153wd/AACEYyk8QT7YdqNe8QpRGU-Ea?dl=0" target="_blank" rel="nofollow">https://www.dropbox.com/sh/uy3jtdov9s153wd/AACEYyk8QT7YdqNe8QpRGU-Ea?dl=0</a></p>

<p>Tinker with it all you want.</p>
]]></description>
   </item>
   <item>
      <title>Cut a String to a shorter String</title>
      <link>https://forum.processing.org/two/discussion/23583/cut-a-string-to-a-shorter-string</link>
      <pubDate>Tue, 25 Jul 2017 23:32:34 +0000</pubDate>
      <dc:creator>albobz</dc:creator>
      <guid isPermaLink="false">23583@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to write a function such that it takes an inputted String and creates a new String 'count' characters long. I have this so far:</p>

<pre><code>String stringFront(String s, int count)
{
  for (int l=0; l&lt;count; l++)
  {

  }
}
</code></pre>

<p>For example, String stringFront("this is the example", 7) would result in "this is".</p>
]]></description>
   </item>
   <item>
      <title>Multiplayer TCP/IP server &amp; client via Processing and Java</title>
      <link>https://forum.processing.org/two/discussion/23159/multiplayer-tcp-ip-server-client-via-processing-and-java</link>
      <pubDate>Wed, 21 Jun 2017 18:20:13 +0000</pubDate>
      <dc:creator>GeorgeJava</dc:creator>
      <guid isPermaLink="false">23159@/two/discussions</guid>
      <description><![CDATA[<p>i have problem with this...</p>

<p>input = input.substring(2, input.indexOf("\n")); // &lt;-- ??? what is number: 2 ?</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/715/MFFVH7SV4CES.png" alt="error" title="error" /></p>
]]></description>
   </item>
   <item>
      <title>Strange behavoure with text(..)</title>
      <link>https://forum.processing.org/two/discussion/22289/strange-behavoure-with-text</link>
      <pubDate>Sat, 29 Apr 2017 17:48:39 +0000</pubDate>
      <dc:creator>dreezy</dc:creator>
      <guid isPermaLink="false">22289@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>i'm new here, but i cannot find the answer about my question.</p>

<p>I've writen a program with some text-entries.
The coordinates of the text are calculated by a for-loop</p>

<pre><code>for (i=0;i&lt;14;i++){
   StrStart=tijdStart[i].substring(0,IntstrTemp);  
     IntstrTemp=tijdStop[i].indexOf(":");
     StrStop=tijdStop[i].substring(0,IntstrTemp);
     text(StrStart+" t/m "+StrStop+" u",(i*85)+10,215+yTranspose);
     WeatherPicture = loadImage("http://" + "openweathermap.org/img/w/" + code[i] + ".png");
     image(WeatherPicture,(i*85)+10,210+yTranspose,60,60);
     text("vocht: "+vochtigheid[i]+"%",(i*85)+10,270+yTranspose);

etc
</code></pre>

<p>The first time the program runs, everything is at the right place, but after a minute, the program gets an update from openweathermap.org and prints the info again.</p>

<p>The info is now placed to the left.. Everything is out of order...</p>

<p>1st picture is the right alignment, second picture is after 1 minute....</p>

<p><img src="http://i1373.photobucket.com/albums/ag387/dreezy100/1_zpsp4cyvk7c.png" alt="" /></p>

<p><img src="http://i1373.photobucket.com/albums/ag387/dreezy100/2_zps7qfwqj7r.png" alt="" /></p>

<p>I hope you can give me some answer what to do.</p>

<p>Thanx</p>
]]></description>
   </item>
   <item>
      <title>[ControlP5 + Serial] Serial input to textfield controller</title>
      <link>https://forum.processing.org/two/discussion/22224/controlp5-serial-serial-input-to-textfield-controller</link>
      <pubDate>Wed, 26 Apr 2017 13:50:03 +0000</pubDate>
      <dc:creator>Blad2021</dc:creator>
      <guid isPermaLink="false">22224@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>So going to do my best to describe this, it might sound a bit more complicated then intended.  I'm trying to set the value of a textfield controller (using ControlP5 library) with input from the Serial.  I could do this now by using a bunch of if statements but thats not very attractive therefore I want a function.  I have everything setup on my serial to ouput the following:</p>

<p>SEN.x.y</p>

<p>"SEN" being what it reads for to determine the function.<br />
(x) - The textfield ID to change
(y) - The value to change the textfield to.</p>

<p>My code so far:</p>

<pre><code>import processing.serial.*;
import controlP5.*;

Serial myPort;  // Create object from Serial class**
String inByte;**
String s;**
ControlP5 cp5;
String temp;
String endchar = "\n";
Textarea consoletext;
Textfield Timer1;
Println console;
//Variables
boolean firstContact = false;
boolean globalState [] = {false, false, false, false, false, false, false, false};
int pin [] = {22, 24, 26, 28, 30, 32, 34, 36};

void setup() 
{  
  size(800,500);
  cp5 = new ControlP5(this);
  cp5.enableShortcuts();

  cp5.addTextfield("console")
    .setSize(360,35)
    .setCaptionLabel("Console Injection Module")
    .setPosition(20,430)
    .setFont(createFont("arial",14))
    .setAutoClear(true)
    ;

  cp5.addTextfield("Timer1")
    .setId(1)
    .setPosition(20,70)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(true)
    .setCaptionLabel("EEPROM: Timer 1")
    ;
  cp5.addTextfield("Timer2")
    .setId(2)
    .setPosition(20,130)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(true)
    .setCaptionLabel("EEPROM: Timer 2")
    ;
  cp5.addTextfield("Timer3")
    .setId(3)
    .setPosition(20,190)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(true)
    .setCaptionLabel("EEPROM: Timer 3")
    ;
  cp5.addTextfield("Timer4")
    .setId(4)
    .setPosition(20,250)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(false)
    .setCaptionLabel("EEPROM: Timer 4")
    ;
  cp5.addTextfield("Timer5")
    .setId(5)
    .setPosition(20,310)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(false)
    .setCaptionLabel("EEPROM: Timer 5")
    ;
  cp5.addTextfield("Timer6")
    .setId(6)
    .setPosition(20,370)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(false)
    .setCaptionLabel("EEPROM: Timer 6")
    ;
  cp5.addButton("button1")
    .setSize(60,20)
    .setCaptionLabel("LED On")
    .setPosition(235,70)
    ;
  cp5.addButton("button2")
    .setSize(60,20)
    .setCaptionLabel("LED Off")
    .setPosition(235,100)
    ;
  cp5.addButton("button4")
    .setSize(60,20)
    .setCaptionLabel("Relays On")
    .setPosition(235,130)
    ;
  cp5.addButton("button3")
    .setSize(60,20)
    .setCaptionLabel("Relays Off")
    .setPosition(235,160)
    ;
  cp5.addBang("Relay1")
     .setPosition(310,50)
     .setId(1)
     .setSize(60,30)
     .setCaptionLabel("relay1")
     ;

  cp5.addBang("Relay2")
     .setPosition(310,95)
     .setSize(60,30)
     .setId(2)
     .setCaptionLabel("Relay 2")
     ;

  cp5.addBang("Relay3")
     .setPosition(310,140)
     .setSize(60,30)
     .setId(3)
     .setCaptionLabel("Relay 3")
     ;

  cp5.addBang("Relay4")
     .setPosition(310,185)
     .setSize(60,30)
     .setId(4)
     .setCaptionLabel("Relay 4")
     ;

  cp5.addBang("Relay5")
     .setPosition(310,230)
     .setSize(60,30)
     .setId(5)
     .setCaptionLabel("Relay 5")
     ;
  cp5.addBang("Relay6")
     .setPosition(310,275)
     .setSize(60,30)
     .setId(6)
     .setCaptionLabel("Relay 6")
     ;
  cp5.addBang("Relay7")
     .setPosition(310,320)
     .setSize(60,30)
     .setId(7)
     .setCaptionLabel("Relay 7")
     ;
  cp5.addBang("Relay8")
     .setPosition(310,365)
     .setSize(60,30)
     .setId(8)
     .setCaptionLabel("Relay 8")
     ;
consoletext = cp5.addTextarea("txt")
  .setPosition(440,20)
  .setSize(350, 465)
  .setFont(createFont("", 12))
  .setLineHeight(14)
  .setColor(color(255, 255, 255, 255))
  .setColorBackground(color(100, 100))
  .setColorForeground(color(255, 100));
  ;
  cp5.addTextlabel("ctext")
    .setText("Console")
    .setPosition(436,3)
    .setColorValue(255)
    .setFont(createFont("Arial",14));
  cp5.addTextlabel("stitle")
    .setText("Machine Serial")
    .setPosition(10,10)
    .setColorValue(color(200, 17, 0, 255))
    .setFont(createFont("Arial",24));
  cp5.addTextlabel("subtitle")
    .setText("Control Panel")
    .setPosition(30,35)
    .setColorValue(200)
    .setFont(createFont("Arial",16));

  console = cp5.addConsole(consoletext);


  //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, "COM3", 9600);
  myPort.bufferUntil('\n');

}

void draw() {
  background(0);
  fill(255);
  for (int i=0;i&lt;globalState.length;i++){
    if (globalState[i] == false){
      fill(color(200, 20, 0, 255));
      rect(385, 50+i*45, 30, 30);
    }
    else{
      fill(color(123, 255, 0, 255));
      rect(385, 50+i*45, 30, 30);
    }
  }
}
void controlEvent(ControlEvent test) {
  if(test.isAssignableFrom(Textfield.class)){
    if("console".equals(test.getName())){
      temp = test.getStringValue();
      if("LED On".equals(temp)){
        myPort.write("2");
        println("Sent: LED ON");
      }else if("LED Off".equals(temp)){
        myPort.write("1");
        println("Sent: LED OFF");
      }else if("help".equals(temp)){
        println("Help:");
        println("/  Commands:");
        println("/  - Update.x.y - Updates control pin layout.");
        println("     (x) - Array location  (y) - PIN");
        println("    Starts at 0!");
        println("/  - EEPROM.x.y - Updates EEPROM address (x) with value (y)");
        println("/  - PIN.x.y - Updates PIN (x) with value of (y)"); 
        println("/    [ Value should be 0 or 1 ONLY!]");
        println("/  - Call.x - Calls current value of position (x) in array");
        println("/  - Varu.x.y - Updates the position (x) with value of (y) in array");
        println("/");
        println("/");
        println("/  Timer values should stay within value of 5100");
        println("/");
      }else {
        String result = temp.substring(0,6);
      //if(temp.contains("Update"){
        if("Update".equals(result)){
          String apple = temp.substring(7,8);
          String pear = temp.substring(9,temp.length());
          int orange = Integer.parseInt(apple);
          int grape = Integer.parseInt(pear);
          pin[orange] = grape;
        } else {
          myPort.write(temp.toUpperCase() + '\n');
          println("Sent: " +temp.toUpperCase());
        }
      }
    }
    boolean StrTest = test.getName().startsWith("Timer");

    if(StrTest == true){
      println("Sending EEPROM Update to controller");
      println("Updating Timer: " +test.getId() +" to Value: " +test.getStringValue());
      Timefunc(test.getId()-1, test.getStringValue());
    }
  }
}
public void button1(){
  println("Sent: pin.10.1");
  myPort.write("PIN.10.1" +endchar);
}
public void button2(){
  println("Sent: pin.10.0");
  myPort.write("PIN.10.0" +endchar);
}
public void button3(){
  println("SYSTEM: Relays On");
  myPort.write("PIN.22.0" +endchar);
  myPort.write("PIN.24.0" +endchar);
  myPort.write("PIN.26.0" +endchar);
  myPort.write("PIN.28.0" +endchar);
  myPort.write("PIN.30.0" +endchar);
  myPort.write("PIN.32.0" +endchar);
  myPort.write("PIN.34.0" +endchar);
  myPort.write("PIN.36.0" +endchar);
}
public void button4(){
  println("SYSTEM: Relays Off");
  myPort.write("PIN.22.1" +endchar);
  myPort.write("PIN.24.1" +endchar);
  myPort.write("PIN.26.1" +endchar);
  myPort.write("PIN.28.1" +endchar);
  myPort.write("PIN.30.1" +endchar);
  myPort.write("PIN.32.1" +endchar);
  myPort.write("PIN.34.1" +endchar);
  myPort.write("PIN.36.1" +endchar);
}
public void Relay1(){
  RelayControl(pin[0], !globalState[0]);
}
public void Relay2(){
  RelayControl(pin[1], !globalState[1]);
}
public void Relay3(){
  RelayControl(pin[2], !globalState[2]);
}
public void Relay4(){
  RelayControl(pin[3], !globalState[3]);
}
public void Relay5(){
  RelayControl(pin[4], !globalState[4]);
}
public void Relay6(){
  RelayControl(pin[5], !globalState[5]);
}
public void Relay7(){
  RelayControl(pin[6], !globalState[6]);
}
public void Relay8(){
  RelayControl(pin[7], !globalState[7]);
}
public void RelayControl(int Id, boolean Flag){
  byte status = 0;
  if(Flag == true){
    status = 1;
  } else {
    status = 0;
  }
  myPort.write("PIN." +Id +'.' +status +endchar);
}

void SensorCheck(int value){
 myPort.write("SC." +value +endchar);
}

public void Timefunc(int Id, String value){
  byte overboard = 0;
  int control = Integer.parseInt(value);
  if(control &gt; 5100){
    control=5100; 
  }
  control = control/10;
  if(control &gt;= 256){
    overboard = 1;
  }
  if(overboard == 0){
    myPort.write("EEPROM." +Id +'.' +control +endchar);
    Id++;
    myPort.write("EEPROM." +Id +'.' +"0" +endchar);
  }
  if(overboard == 1){
    control = control - 255;
    myPort.write("EEPROM." +Id +'.' +"255" +endchar);
    Id++;
    myPort.write("EEPROM." +Id +'.' +control +endchar);
  }
}

void serialEvent(Serial myPort) {
  inByte = myPort.readStringUntil('\n');
  if (inByte != null){
    inByte = trim(inByte);
    println("Recieved: " +inByte);
    if(inByte.contains("PIN.")){
      String result = inByte.substring(4,6);
      char state = inByte.charAt(7);
      boolean isOn;
      if(state == '1'){
        isOn = true;
      }
      else{
       isOn = false; 
      }
      int endresult = parseInt(result);
      for(int i = 0;i&lt;pin.length;i++){
        if (endresult == pin[i]){
          globalState[i] = isOn;
        }
      }
      delay(10);
    }//End of PIN Function
    if(inByte.contains("SEN.")){
      char firstvalue = inByte.charAt(5);
      char secondvalue = inByte.charAt(7);
      int fvresult = parseInt(firstvalue);
      int svresult = parseInt(secondvalue);
      cp5.getId(fvresult);
    }

    if (firstContact == false) {
      if (inByte.equals("&lt;Controller is ready&gt;")) {
        myPort.clear();
        firstContact = true;
        //myPort.write("A");
        println("SYSTEM: Contact Made");
        delay(100);
        println("Control ready!");
      }
    }
  }
}
</code></pre>

<p>The issue resides with this line: 
cp5.getId(fvresult);</p>

<p>How can I format this to send the information to the Textfield controller when it doesn't go thorugh the ControlEvent function?</p>

<p>edit: fixed spelling mistakes.</p>

<p>edit: I have a working example below.  Its just not a "universal" function:</p>

<pre><code>if(inByte.contains("SEN.")){
  char firstvalue = inByte.charAt(5);
  String secondvalue = inByte.substring(6,inByte.length());
  //int fvresult = Integer.parseInt(firstvalue);
  int svresult = Integer.parseInt(secondvalue);
  println(svresult);
  Timer1.setText(secondvalue);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to separate last two bits of a byte?</title>
      <link>https://forum.processing.org/two/discussion/21996/how-to-separate-last-two-bits-of-a-byte</link>
      <pubDate>Fri, 14 Apr 2017 16:27:34 +0000</pubDate>
      <dc:creator>WowStudios</dc:creator>
      <guid isPermaLink="false">21996@/two/discussions</guid>
      <description><![CDATA[<p>I am aware that there are many approcahes to removing something from a string, like</p>

<p><code>String test = "this one is simple. ("
test = test.replaceAll(" (", "");</code></p>

<p>Or something along those lines. Now, if I want to create two strings, or integers, from a single byte, with one being the last two bits, and the other one the rest, how could I do it? For example:
I have 10100110, and I want to make code to create "101001" and "10", as the output, without using code like "find 10 and split it", since I want to be able to use it for the binary values of a pixel. I hope there is a function for this.</p>

<p>Is it even possible?</p>
]]></description>
   </item>
   <item>
      <title>Deleting first character in a string- getting rid the the front $ value sign</title>
      <link>https://forum.processing.org/two/discussion/21188/deleting-first-character-in-a-string-getting-rid-the-the-front-value-sign</link>
      <pubDate>Sun, 05 Mar 2017 21:59:55 +0000</pubDate>
      <dc:creator>samuelnsweeney</dc:creator>
      <guid isPermaLink="false">21188@/two/discussions</guid>
      <description><![CDATA[<p>Hello All,</p>

<p>I know in python its as simple as the syntax     String[1:] etc.</p>

<p>But I can not seem to find as simple as a way in java. I am wanting to loop through a series of dollar values and just get rid the the dollar sign to start using the values as ints to manipulate.</p>

<p>Thanks, Sam</p>
]]></description>
   </item>
   <item>
      <title>Converting floats to short approximations</title>
      <link>https://forum.processing.org/two/discussion/20726/converting-floats-to-short-approximations</link>
      <pubDate>Wed, 08 Feb 2017 23:48:03 +0000</pubDate>
      <dc:creator>prince_polka</dc:creator>
      <guid isPermaLink="false">20726@/two/discussions</guid>
      <description><![CDATA[<p>I needed this in a project I'm working on and wrote this function which seems to work quite well, (haven't tested it extensively though)</p>

<pre><code>String nufix(float n) { // Numerical Suffix
  String a="";          // String manipulation variable
  float K = 1000.0;     // Kilo
  float M = pow(K, 2);  // Mega
  float G = pow(K, 3);  // Giga
  float T = pow(K, 4);  // Terra
  float P = pow(K, 5);  // Peta
  float E = pow(K, 6);  // Exa
  float Z = pow(K, 7);  // Zeta
  float Y = pow(K, 8);  // Yotta
  float sv=1.0;         // Suffix value
  char  sc=' ';         // Suffix char
  int neg=0; if (n&lt;0){neg=1;} // boolean as int for convenience

  if      (abs(n) &lt; 1) {return '.'+str(int(n*10));}
  else if (abs(n) &lt; K) {return str(int(n));}
  else if (abs(n) &lt; M) {sc='K'; sv=K;}
  else if (abs(n) &lt; G) {sc='M'; sv=M;}
  else if (abs(n) &lt; T) {sc='G'; sv=G;}
  else if (abs(n) &lt; P) {sc='T'; sv=T;}
  else if (abs(n) &lt; E) {sc='P'; sv=P;}
  else if (abs(n) &lt; Z) {sc='E'; sv=E;}
  else if (abs(n) &lt; Y) {sc='Z'; sv=Z;}
  else if (abs(n) &lt; Y*K) {sc='Y'; sv=Y;}
  else {return "yo mama";} // here I give up

  if (abs(n)&gt;=10.0*sv) {
  return str(int(n/sv))+sc;
  }
  else {
    a=str(n/sv);
    if (a.charAt(1+neg)=='.' &amp;&amp; a.charAt(2+neg)=='0') {
      return a.substring(0,1+neg)+sc;
      }
    else {return a.substring(0,3+neg)+sc;}
  }
}
</code></pre>

<p>Also this shorter but a little worse variant</p>

<pre><code>String nufix(float n) { 
  String scrs="KMGTPEZY";
  if      (abs(n) &lt; 1) {return '.'+str(int(n*10));}
  else if (abs(n) &lt; 1000.0) {return str(int(n));}
  for(int i=0; i&lt;scrs.length();i++)
  {
    if (abs(n) &lt; pow(1000.0,i+2)){
      return str(int(n/pow(K,i+1)))+scrs.charAt(i);
    }
  }
  return "yo mama";
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do i find the sequence of digit in a long string which is numbers only</title>
      <link>https://forum.processing.org/two/discussion/19918/how-do-i-find-the-sequence-of-digit-in-a-long-string-which-is-numbers-only</link>
      <pubDate>Sun, 25 Dec 2016 17:53:38 +0000</pubDate>
      <dc:creator>elkolorado</dc:creator>
      <guid isPermaLink="false">19918@/two/discussions</guid>
      <description><![CDATA[<p>Hi. I have this problem. How can i write code that would search for a sequence of digits in a string that is numbers only. For instance for this string
<code>123124567</code>
i want to search for n-digit sequence and if it repeats one or more time show it.</p>

<p>I'll show it on example of what i want to achive
For <code>123124567</code>
Show all 2-digit sequences (that are in a row) so output should be
<code>12 23 31 12 24 45 56 67</code>
And from it show those that repeat one or more time in this case
<code>12</code></p>

<p>Im r begginger but i would like to teach myself to to this as i am working on bigger project where i need to show every number sequences in very long string.
I tried to use the  Regular Expressions for it but then i got the results like: <code>12 31 24 56</code> and it wasnt checking every possible two digits sequence like <code>12 23 31 12 24 45 56 67</code></p>

<pre><code>var textfield;
var output;
var submit;

function setup() {
  noCanvas();
  textfield = select("#input");
  output = select('#output');
  submit = select("#submit");
  submit.mousePressed(newText);
}

function newText() {
  var s = textfield.value();

  var r = /\d\d/g; //here i would need to adjust it so to given digit length
  var matches = s.match(r);

  for (var i = 0; i &lt; matches.length; i++) {
    createP(matches[i]);
   //at this point the results are wrong not showing all possible sequences
  }

  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Backspace processing</title>
      <link>https://forum.processing.org/two/discussion/18912/backspace-processing</link>
      <pubDate>Sun, 06 Nov 2016 18:25:16 +0000</pubDate>
      <dc:creator>ginadal</dc:creator>
      <guid isPermaLink="false">18912@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I want to create a divided screen, which in the left part the user can create a typing input. I've done it, however, I have problems with the backspace as I do not know what is wrong.</p>

<pre><code>int y = 0;
int x = 0;

float viewportTwoX;
float viewportTwoY;

float viewportWidth;
float viewportHeight;

String letters = "";

void setup() {
  size(768, 768);
  viewportTwoX = width/2;
  viewportTwoY = 0;
  viewportWidth = width/2;
  viewportHeight = height;

  ima = loadImage ("a.png");
  imb = loadImage ("b.png");

}

void draw() {
  background(0);
  drawViewportOne();
  drawViewportTwo();
}

void drawViewportOne() {
  fill(0);
  noStroke();
  rect(0, 0, viewportWidth, viewportHeight);
  fill(255);
  float cursorPosition = textWidth(letters);
  line(cursorPosition, 0, cursorPosition, 100);
  text(letters, 0, 50);
}

void keyPressed() {
  if (key == BACKSPACE) {
    if (letters.length() &gt; 368) {
      letters = letters.substring(0, letters.length()-1);
    }
  } else if (textWidth(letters+key) &lt; width) {
    letters = letters + key;
  }
}
</code></pre>

<p>how can I fix it?</p>
]]></description>
   </item>
   <item>
      <title>is is possible to split() from the nth character?</title>
      <link>https://forum.processing.org/two/discussion/19184/is-is-possible-to-split-from-the-nth-character</link>
      <pubDate>Sun, 20 Nov 2016 23:08:27 +0000</pubDate>
      <dc:creator>beccarose</dc:creator>
      <guid isPermaLink="false">19184@/two/discussions</guid>
      <description><![CDATA[<p>Hey,</p>

<p>I'm using p5.js and would like to split a string I get from JSON data when it gets to a certain length. At the moment I can see that split() needs a specific character to split the string. Is there a way to split a string after say a number of characters (i.e. split the string after 40 chars) or a width (i.e. split the string after 800px).</p>

<p>I know that it is possible to do this in javascript (thanks google) but I wouldn't know how to integrate this into P5.JS.</p>

<p>help much appreciated</p>

<p>Thank you :)</p>
]]></description>
   </item>
   <item>
      <title>Text from file</title>
      <link>https://forum.processing.org/two/discussion/18488/text-from-file</link>
      <pubDate>Mon, 10 Oct 2016 18:50:22 +0000</pubDate>
      <dc:creator>cookie23</dc:creator>
      <guid isPermaLink="false">18488@/two/discussions</guid>
      <description><![CDATA[<p>I want to tjek if the first letter in the test.txt file is "t". Why does this not work?:</p>

<pre><code>String lines[] = loadStrings("test.txt");
println(lines[0]);

String letter = lines[0].substring(1, 2);
println(letter);

if(letter == "t"){
  print("first letter is t!");
}else{
  print("first letter is not t!");
}
</code></pre>

<p>The console says:</p>

<p>ttt-test<br />
t<br />
first letter is not t!</p>
]]></description>
   </item>
   <item>
      <title>Integrating Arduino and Processing - button counter</title>
      <link>https://forum.processing.org/two/discussion/17602/integrating-arduino-and-processing-button-counter</link>
      <pubDate>Wed, 20 Jul 2016 22:39:13 +0000</pubDate>
      <dc:creator>ksenia_n</dc:creator>
      <guid isPermaLink="false">17602@/two/discussions</guid>
      <description><![CDATA[<p>I am looking to integrate Arduino controls and Processing Interface. In my Arduino code, there are three buttons attached to pin a1, a0 and d0 (all digitalRead).</p>

<pre><code>int x;// assigned to A0 input
int y;// assigned to A1 input
int z; //assigned to D0 input
int votes[3]={0,0,0};

void setup() {
  // initialize the serial communication
  Serial.begin(9600);

  while(!Serial);
}

void loop() {
  // first we need to read the values from the BUTTONS

  x = digitalRead(A0);

  y = digitalRead(A1);

  z = digitalRead(0);

  if(digitalRead(A0) == HIGH) 
    {
    Serial.print("cat1 ");                  
    Serial.print(votes[0]=votes[0]+1);
    Serial.print("\n");
    }
   else if(digitalRead(A1) == HIGH)
    {
    Serial.print("cat2 ");
    Serial.print(votes[1]=votes[1]+1);
      Serial.print("\n");
    }
   else if(digitalRead(0) == HIGH) 
    {
    Serial.print("cat3 ");
    Serial.print(votes[2]=votes[2]+1);
    Serial.print("\n");
    }
    delay(200);
}
</code></pre>

<p>I would like the counter to increment every time the button is pressed and display in processing as a bar graph. Whenever the button is pressed, the bar graph goes up by some amount. In this case I want one of the three lines (associated to three buttons) to draw, if pressed.</p>

<p>The processing code is below:</p>

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

// Serial Port variables
Serial myPort;
String buff = "";
String buff1 = "";
String buff2 = "";
int index = 0;
int NEWLINE = 10;
// Store the last 256 values from the sensors so we can draw them.
int[] valuesx = new int[256];
int[] valuesy = new int[256];
int[] valuesz = new int[256];

void setup()
{ 
  // set size of the window 
  size(512, 512);
  // turn on anti-aliasing, this makes things look smoother 
  smooth();

  println(Serial.list()); // use this to determine which serial port is your Arduino
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
}

// draw() happens every frame of the sketch. This is where all the calculations are made.
// When draw() is finished executing, it executes again, over and over.
void draw() {
  // set the background to purple
  background(87, 36, 124);
  // set stroke weight(thickness of the line) to 5 pixels
  strokeWeight(5);

  for (int i = 0; i &lt; 255; i++) {

    stroke(247, i);
    // draw the line (x1, y1, x2, y2)
    line(1, valuesx[i], 1, valuesx[i + 1]);
    line(5, valuesy[i], 5, valuesy[i + 1]);
    line(10, valuesz[i], 10, valuesz[i + 1]);
  }

  // Check the Serial port for incoming data
  while (myPort.available () &gt; 0) {
    // if there is data waiting...
    // execute serialEvent() function. Look below to see how SerialEvent works.
    serialEvent(myPort.read());
  }
}

// serialEvent controls how incoming serial data from the Arduino module is handled
void serialEvent(int serial)
{
  if (serial != NEWLINE) {
    // Store all the characters on the line.
    buff += char(serial);
  } 
  else {
    // The end of each line is marked by two characters, a carriage
    // return and a newline.  We're here because we've gotten a newline,
    // but we still need to strip off the carriage return.
    buff = buff.substring(0, buff.length()-1);
    index = buff.indexOf(",");
    buff1 = buff.substring(0, index);
    buff2 = buff.substring(index+1, buff.length());

    // Parse the String into an integer.  We divide by 4 because
    // analog inputs go from 0 to 1023 while colors in Processing
    // only go from 0 to 255.
    int x = Integer.parseInt(buff1)/2;
    int y = Integer.parseInt(buff2)/2;

    // Clear the value of "buff"
    buff = "";

    // Shift over the existing values to make room for the new one.
    for (int i = 0; i &lt; 255; i++)
    {
      valuesx[i] = valuesx[i + 1];
      valuesy[i] = valuesy[i + 1];
    }

    // Add the received value to the array.
    valuesx[255] = x;
    valuesy[255] = y;
  }
}
</code></pre>

<p>Unfortunately, here's the error that I get when I press a button.
<img src="http://i.stack.imgur.com/U4WyU.jpg" alt="" /></p>
]]></description>
   </item>
   <item>
      <title>Save/Load JSON based Cameras in Proscene</title>
      <link>https://forum.processing.org/two/discussion/17036/save-load-json-based-cameras-in-proscene</link>
      <pubDate>Wed, 08 Jun 2016 02:12:02 +0000</pubDate>
      <dc:creator>sirianth</dc:creator>
      <guid isPermaLink="false">17036@/two/discussions</guid>
      <description><![CDATA[<p><a href="https://www.dropbox.com/sh/2riljmpqfywibaa/AADseXkl0ms0WOYcjPSjKow7a?dl=0" target="_blank" rel="nofollow">https://www.dropbox.com/sh/2riljmpqfywibaa/AADseXkl0ms0WOYcjPSjKow7a?dl=0</a></p>

<p>^ that's a link to my code</p>

<p>Someone else was apparently able to save/load cameras in proscene from a file:
<a href="https://forum.processing.org/one/topic/proscene-saving-loading-camera-settings-to-from-file-what-are-the-key-settings-of-a-camera.html" target="_blank" rel="nofollow">https://forum.processing.org/one/topic/proscene-saving-loading-camera-settings-to-from-file-what-are-the-key-settings-of-a-camera.html</a></p>

<p>But I'm having trouble implementing their code. I have a feeling it's a basic problem that I just don't understand. When I run this:</p>

<p>import processing.data.JSONObject;</p>

<pre><code>//this is how you save the camera, theoretically;
//save a Proscene scene current camera settings in as a JSON string in a file
void saveCamera(Scene scene, String fileName ) {
  processing.data.JSONObject json = new JSONObject();
  json.setFloat("fov", scene.camera().fieldOfView() );  
  setVector(json, "position", scene.camera().position() );
  setVector(json, "viewdirection", scene.camera().viewDirection() );
  setVector(json, "upvector", scene.camera().upVector() );
  saveJSONObject(json, fileName);
}
//Add a PVector as a string representation of a float array to a JSON object
void setVector(JSONObject json, String attributeName, Vec v) {
  json.setString( attributeName, Arrays.toString( new float[]{ v.x, v.y, v.z} ) );
}

//#####this is how you load the camera, theoretically;
void loadCamera(Scene scene, String fileName) {
  JSONObject json = loadJSONObject(fileName);
  scene.camera().setFieldOfView( json.getFloat("fov") );
  scene.camera().setUpVector( getVector(json, "upvector") );
  scene.camera().setViewDirection( getVector(json, "viewdirection") );
  scene.camera().setPosition( getVector(json, "position") );
}
//Parse a PVector from its string representation as an array of float in a JSON object
PVector getVector(JSONObject json, String attributeName) {
  String o =  json.getString(attributeName);
  String[] arr = o.substring(1, o.length()-1).split(", ");
  float[] f = new float[arr.length];
  int i = 0;
  for (String s : arr) {
    f[i] = Float.parseFloat(s);
    i++;
  }
  return new PVector(f[0], f[1], f[2]);
}
</code></pre>

<p>"Arrays" isn't pointing to anything, and I'm not sure what to do about it?</p>
]]></description>
   </item>
   <item>
      <title>Error with using OpenCV for processing in jar file.</title>
      <link>https://forum.processing.org/two/discussion/16069/error-with-using-opencv-for-processing-in-jar-file</link>
      <pubDate>Sun, 17 Apr 2016 20:18:22 +0000</pubDate>
      <dc:creator>Tomo93</dc:creator>
      <guid isPermaLink="false">16069@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone</p>

<p>When I'm running my application from eclipse I don't have any problems, but when I'm trying to run it as JAR runnable file exported form Eclipse I have following error:</p>

<p><a href="http://screenshot.sh/ofjVYNTW9VBaO" target="_blank" rel="nofollow">http://screenshot.sh/ofjVYNTW9VBaO</a></p>

<p>The problem is in this method:</p>

<pre><code>private String getLibPath() {
        URL url = this.getClass().getResource("OpenCV.class");
        if (url != null) {
          // Convert URL to string, taking care of spaces represented by the "%20"
          // string.
          String path = url.toString().replace("%20", " ");
          int n0 = path.indexOf('/');

          int n1 = -1;


          n1 = path.indexOf("opencv_processing.jar");
          if (PApplet.platform == PConstants.WINDOWS) { //platform Windows
            // In Windows, path string starts with "jar file/C:/..."
            // so the substring up to the first / is removed.
            n0++;
          }


          if ((-1 &lt; n0) &amp;&amp; (-1 &lt; n1)) {
            return path.substring(n0, n1);
          } else {
            return "";
          }
        }
        return "";
      }
</code></pre>

<p>Anyone know how to solve this problem?</p>

<p>Thanks for help</p>
]]></description>
   </item>
   <item>
      <title>Evaluating substring does not work (now with better formatted code)</title>
      <link>https://forum.processing.org/two/discussion/16047/evaluating-substring-does-not-work-now-with-better-formatted-code</link>
      <pubDate>Sat, 16 Apr 2016 17:13:26 +0000</pubDate>
      <dc:creator>Hypersim</dc:creator>
      <guid isPermaLink="false">16047@/two/discussions</guid>
      <description><![CDATA[<p>Hey everyone,</p>

<p>I have recently started using Processing and I love it! I do not have so much programming background, so I would be happy if you could help me from time to time :)</p>

<p>Right now, I have this code, which does not work as expected:</p>

<pre><code>String varText = "012345";
String varSubstring = varText.substring(2, 3);
println(varSubstring); // This prints 2. So far, so good, but
// ... this does never evaluate to TRUE:
if (varSubstring == "2") {
  println("It is 2!");
} else {
  println("Oh no, it did not work!");
}
</code></pre>

<p>Does anyone have an idea how I could make this work?</p>

<p>Thank you very much!</p>

<p>Sebastian</p>
]]></description>
   </item>
   <item>
      <title>Adding Radar sweep line to code.</title>
      <link>https://forum.processing.org/two/discussion/14452/adding-radar-sweep-line-to-code</link>
      <pubDate>Thu, 14 Jan 2016 06:32:36 +0000</pubDate>
      <dc:creator>herrmant</dc:creator>
      <guid isPermaLink="false">14452@/two/discussions</guid>
      <description><![CDATA[<p>I am building a weather radar based on Grook.nets code for an ultrasonic sensor, however, I am not using a ultrasonic sensor. I have modified the code in many ways... The radar currently can detect heavy rain/hail at about 40 mi. I would like to add a sweep line for effects on the screen. Could anyone help me out? I am attaching my code. Thank you.</p>

<pre><code>int cx; 
int cy; 
int r = 200;
int x = new int[100];
int y = new int[100];

import processing.serial.*;
Serial port;
Serial port2;
String data = "";
String Radius = "";
String Theta = "";
int index = 0;
float distance = 9000;
float angle = 10;
float pi = 22.0/7;

PImage img;



void setup() {
  size(600, 600);
  cx = width/2;
  cy = height/2;
  size(1000, 800);
  background(100);
  ellipse(500, 500, 1000, 1000);
  line(500, 0, 500, 1000);
  line(0, 500, 1000, 500);
  line(500, 500, 1000, 0);
  line(500, 500, 1, 1);
  img = loadImage("MAP3.png");
  tint(255, 1);
}
{



  port = new Serial(this, "COM3", 9600);
  port.bufferUntil('.');
}

void draw() {
  background (0);
  stroke(0, 200, 0); 
  float t = millis()/1500; 
  for (int i = 0; i &lt; 100; i++) {
    x[i] =(int) (cx+r*cos(t - i*0.01)); 
    y[i] =(int) (cy+r*sin(t - i*0.01));
    stroke(0, 200 - i * 2, 0); 
    line(cx, cy, x[i], y[i]);
  }


  image(img, 0, 0);
}

void serialEvent(Serial port)
{

  data = port.readStringUntil('.');
  data = data.substring(0, data.length() - 1);  
  index = data.indexOf(",");
  Radius = data.substring(0, index);
  Theta = data.substring (index+1, data.length());

  translate(500, 500);
  point (1, 1);

  distance = float(Radius); 
  angle = float(Theta) /180 * pi; 
  fill(10, 600, 20);
  ellipse(distance * cos(angle), -1 * distance * sin(angle), 40, 20);

  fill(98, 245, 31);


  noStroke();
  fill(8, 3); 
  rect(1000, 1, width, 1010);

  fill(98, 800, 31);
}
`
Thanks for any help. Initial code written by Grook.net. Modified by Tim Herrman.
</code></pre>

<p>Here is a link to an image showing what I want to do.</p>

<pre><code><a href="http://www.bing.com/images/search?q=Radar+Sweep&amp;view=detailv2&amp;&amp;id=22EB8F2D6B4A7022F64E3C9B07F1499647F2F8D1&amp;selectedIndex=23&amp;ccid=3s8XPcDD&amp;simid=608046625551091599&amp;thid=OIP.Mdecf173dc0c37904ea95e802d6180293o0&amp;ajaxhist=0" target="_blank" rel="nofollow">http://www.bing.com/images/search?q=Radar+Sweep&amp;view=detailv2&amp;&amp;id=22EB8F2D6B4A7022F64E3C9B07F1499647F2F8D1&amp;selectedIndex=23&amp;ccid=3s8XPcDD&amp;simid=608046625551091599&amp;thid=OIP.Mdecf173dc0c37904ea95e802d6180293o0&amp;ajaxhist=0</a>
</code></pre>
]]></description>
   </item>
   <item>
      <title>What is substring()'s equivalence in p5js?</title>
      <link>https://forum.processing.org/two/discussion/13611/what-is-substring-s-equivalence-in-p5js</link>
      <pubDate>Mon, 23 Nov 2015 10:14:13 +0000</pubDate>
      <dc:creator>kennyLiao</dc:creator>
      <guid isPermaLink="false">13611@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>How can I achieve the following pseudo code in p5js to create substring, as I couldn't find anything function which has similar effect of substring() in Processing3?</p>

<pre><code>    function setup() {
        var str = "0930";
        str.substring(0, 2);
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can I compare a user's input with a substring?</title>
      <link>https://forum.processing.org/two/discussion/13313/can-i-compare-a-user-s-input-with-a-substring</link>
      <pubDate>Thu, 29 Oct 2015 17:30:46 +0000</pubDate>
      <dc:creator>Ríbó</dc:creator>
      <guid isPermaLink="false">13313@/two/discussions</guid>
      <description><![CDATA[<p>Hi there.</p>

<p>I'm working on an App.<br />
Part of what it does, is print Strings of text to the screen, one by one, as the user clicks through.  Most users won't be fluent in the language of the App, and I'm working on a kind of help feature.
I want users to be able to type a word that they don't understand, and print the translation to the screen.</p>

<p>I've made a new sketch (based on  <a rel="nofollow" href="http://funprogramming.org/25-Typing-big-letters-that-fade-out.html">this</a> and <a rel="nofollow" href="https://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/">this</a>) to develop the mechanism:</p>

<pre><code>float txtPos= random(100, 200);
String myText = "";

void setup() {
  size(800, 600);
  background(#3355cc);
}


void draw() {
  fill(#3355cc, 40);
  rect(0, 0, width, height);
  text(myText, 0, 0, width, height);
}

void keyPressed() {

  textSize(160);
  fill(#E8B600);
  text(key, txtPos, 240);
  txtPos += 70;
  if (txtPos&gt;width) {
    txtPos-= width;
  }
  if (keyCode == BACKSPACE) {
    if (myText.length()&gt;0) {
      myText = myText.substring(0, myText.length()-1);
    }
  } else if (keyCode == DELETE) {
    myText = "";
  } else if (keyCode != SHIFT &amp;&amp; keyCode != CONTROL &amp;&amp; keyCode != ALT)
    myText = myText + key;

  if (keyCode == ENTER) {
    mousePressed();
  }
  print(key );
}

void mousePressed() {
  if (myText.equalsIgnoreCase("madra")) {
    println();
    print("Madra means dog!");
    myText = "";
    println();
  } else {
    println();
    print("Ní thuigim "+myText);
    myText = "";
    println();
  }
}
</code></pre>

<p>That works, except when ENTER is used to activate mousePressed(). I think I can fix that. But it's not a great system.  I think it would be much better if the program could accept a String from the user, and check to see if any part of that string is a substring of the App's text.  (as opposed to making a giant if else or switch statement block) Then I could print a more helpful answer.</p>

<p>Any thoughts on how to do that?<br />
currently trying variations of<br />
<code>if (myText.substring(0,myText.length()-1).equalsIgnoreCase("madra"))</code>
//but that ain't it...</p>
]]></description>
   </item>
   <item>
      <title>Search strings for words in between a tag?</title>
      <link>https://forum.processing.org/two/discussion/13226/search-strings-for-words-in-between-a-tag</link>
      <pubDate>Sat, 24 Oct 2015 15:05:00 +0000</pubDate>
      <dc:creator>bnjm</dc:creator>
      <guid isPermaLink="false">13226@/two/discussions</guid>
      <description><![CDATA[<p>How can I use Processing to search strings (Text from a webpage) and pull out the words in-between a tag, for example everything between <code>&lt;p&gt; and &lt;/p&gt;</code></p>
]]></description>
   </item>
   <item>
      <title>Copy part of a String</title>
      <link>https://forum.processing.org/two/discussion/12530/copy-part-of-a-string</link>
      <pubDate>Tue, 15 Sep 2015 21:21:06 +0000</pubDate>
      <dc:creator>Jose_Aparecido</dc:creator>
      <guid isPermaLink="false">12530@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys,</p>

<p>It can copy part of a String, (from a certain position)?
I am unable to copy the second part (after the stroke) ...
What could be wrong?</p>

<pre><code>String str = "1234-5678";
String sub1 = str.substring(0,4);
String sub2 = str.substring(4,4);
println("Str/Sub: " + str + " - " + sub1 + " - " + sub2);
</code></pre>

<p>Thank you,</p>
]]></description>
   </item>
   </channel>
</rss>