<?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 redraw() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=redraw%28%29</link>
      <pubDate>Sun, 08 Aug 2021 18:48:06 +0000</pubDate>
         <description>Tagged with redraw() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedredraw%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Is it possibile to sync Processing's frameRate/draw function with and incoming MIDI signal?</title>
      <link>https://forum.processing.org/two/discussion/27280/is-it-possibile-to-sync-processing-s-framerate-draw-function-with-and-incoming-midi-signal</link>
      <pubDate>Sun, 25 Mar 2018 17:29:51 +0000</pubDate>
      <dc:creator>fedpep</dc:creator>
      <guid isPermaLink="false">27280@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, today I had this idea and tried to write some code but then got stucked.</p>

<p>I'm thinking about syncing Processing's frameRate/draw function with an incoming MIDI signal because I would love to create a visualization in sync with music coming from Ableton.</p>

<p>With the MidiBus Library and through the IAC Driver on my Mac I got the Sync/Clock MIDI Message from Ableton into Processing but then I wasn't able to link those two things together.</p>

<p>This is my code so far but I'm not sure it's working properly. Any help would be greatly appreciated.</p>

<pre><code>import themidibus.*; //Import the library
import javax.sound.midi.MidiMessage; //Import the MidiMessage classes <a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/midi/MidiMessage.html" target="_blank" rel="nofollow">http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/midi/MidiMessage.html</a>
import javax.sound.midi.SysexMessage;
import javax.sound.midi.ShortMessage;

MidiBus myBus; // The MidiBus

int i = 1;

void setup() {
  size(400, 400);
  background(0);
  frameRate(60);
  MidiBus.list();
  myBus = new MidiBus(this, 0, 1);
}

void draw() {
 if(frameCount % 60 == 0) {
   println("min");
   i = 1;
 }
}

void midiMessage(MidiMessage message) {
  print(i + " ");
  i++;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Play video using Processing, Arduino and PIR Sensor</title>
      <link>https://forum.processing.org/two/discussion/25365/play-video-using-processing-arduino-and-pir-sensor</link>
      <pubDate>Sun, 03 Dec 2017 22:41:30 +0000</pubDate>
      <dc:creator>m4rdones</dc:creator>
      <guid isPermaLink="false">25365@/two/discussions</guid>
      <description><![CDATA[<p>Hi. A friend and I are in the middle of a video installation tests. I'm using an Arduino PIR Sensor and an Arduino Uno board.</p>

<p>I need to stop a video when the PIR is "On" (Detects motion) and to play that video if the PIR is "Off".</p>

<p>Checking the Processing and Arduino websites, examples and references I couldn't figured out what I'm doing wrong.
Please let me know if something is missing or left.
Thanks in advance for any help!</p>

<p>This is the Arduino Code (copied from Arduino and Processing communication tutorials found on the web):</p>

<pre><code>/*
   PIR sensor tester
*/

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input

  Serial.begin(9600);
}

void loop() {
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH) {
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}
</code></pre>

<p>And here is the Processing code:</p>

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

Serial myPort;
String val;    

Movie video;

void setup() {
  size(640,480);
  video = new Movie(this,"sujeto1.mp4");
  video.loop();
  String portName = Serial.list()[0];
  myPort = new  Serial(this, portName, 9600);
  myPort.bufferUntil('\n');
}

void serialEvent (Serial myPort) {
  if (myPort.available() &gt; 0) {
    val=myPort.readStringUntil('\n');
  }
  if (val=="Motion detected!") {
    video.stop();
  } else {
    video.loop();
  }
  println(val);

}
void draw() {
  background(0);
  image(video,0,0);

} 

void movieEvent(Movie video) {
  video.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to go back to original colour using IF statements?</title>
      <link>https://forum.processing.org/two/discussion/24960/how-to-go-back-to-original-colour-using-if-statements</link>
      <pubDate>Sat, 11 Nov 2017 03:00:26 +0000</pubDate>
      <dc:creator>newcode123</dc:creator>
      <guid isPermaLink="false">24960@/two/discussions</guid>
      <description><![CDATA[<p>I want to be able to cycle my colours indefinitely on mouse clicks, and I know that if I have three colours in total, so colourOne=0, colourTwo=1, colourThree=2, then I will need to make it so when the mouse is clicked at colourThree, i'll get the value 0. but I am not sure how to put that in my code.</p>

<pre><code>boolean colourOne= false;
boolean colourTwo= false;
boolean colourThree= false;

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

void draw(){

  rect(100,100,50,50);
  allColours();
}

void colourRed(){
  background(255,0,0);
}

void colourGreen(){
  background(0,255,0);
}

void colourBlue(){
  background(0,0,255);
}
void allColours(){
  if(colourOne){
    colourRed();
    if(colourTwo){
      colourGreen();
      if(colourThree){
        colourBlue();

}
    }
  }
}

void mouseClicked(){
  if(!colourOne){
    colourOne=true;
  }
  else if(!colourTwo){
    colourTwo=true;
  }
  else if(!colourThree){
    colourThree=true;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Please explain me the effect of redraw() / loop() / noloop() here</title>
      <link>https://forum.processing.org/two/discussion/24833/please-explain-me-the-effect-of-redraw-loop-noloop-here</link>
      <pubDate>Wed, 01 Nov 2017 11:53:34 +0000</pubDate>
      <dc:creator>ddaann88</dc:creator>
      <guid isPermaLink="false">24833@/two/discussions</guid>
      <description><![CDATA[<p>Please explain me these cases:</p>

<h2>    1. If I run code below, the thick line is drawn after the 2nd click</h2>

<h2>    2. If I remove noLoop(); , the thick line is drawn after the 1st click</h2>

<h2>    3. If I remove loop(); , the thick line is not drawn, not matter how many clicks I perform</h2>

<h2>    4. If I remove noLoop(); and loop();, the thick line is drawn after the 1st click</h2>

<pre><code>         boolean ready_for_thick_line = false; 

         void mousePressed() {
           drawLine(10);
           ready_for_thick_line = true;
           redraw();
         }

         void drawLine(int width) {
           strokeWeight(width);
           line(20, 20, 80, 20);
         }

         void draw() {
         if (ready_for_thick_line) 
         {
            loop();
         }
         else{
            drawLine(1);
            noLoop();
         }  
        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to integrate a p5 canvas in an interactive map</title>
      <link>https://forum.processing.org/two/discussion/24594/how-to-integrate-a-p5-canvas-in-an-interactive-map</link>
      <pubDate>Tue, 17 Oct 2017 07:01:55 +0000</pubDate>
      <dc:creator>grab06</dc:creator>
      <guid isPermaLink="false">24594@/two/discussions</guid>
      <description><![CDATA[<p>hello,</p>

<p>I'm developping a personnal project around the "concept of" interactive map.</p>

<p>On this interactive map, I would like to gather as many as possible of information related to one specific thematic.</p>

<p>I mean, I will represent static information (markers, geographical forms ...) and dynamic information (pathes, animations ...). The dynamic information and animations are scheduled according to a global timer (day by day, hour by hour ...). I may have several tens of thousand information per map ...</p>

<p>I've started prototyping the project using <strong>leaflet</strong> and some of its addons. Leaflet uses the concept of layers to manage different level of information or interactions with the user.</p>

<p>One of these addons is <strong>canvasLayer.js</strong> that I use for the dynamic part of the project. I can add a canvas layer to the interactive map and draw on this canvas. Being integrated to the leaflet map, this canvas layer is automatically managed when resizing, moving, spanning and managing the user interaction. But, to me, I suffer from a lack of algorithms for drawing all kinds of dynamic objects and then I have to implement most of them by myself ...</p>

<p>On the other hand , <strong>p5.js</strong> offers a huge amount of animation of all kinds (steering behavior, ...) that I would like to integrate in my interactive map.</p>

<p>Now I'm at the point to ask my questions:</p>

<p><em>Is it feasible to integrate the p5.js library in a leaflet interactive map? if yes ... how to do that?</em></p>

<p>I could replace leaflet by mapbox, as long as I keep the concept of interactive map.</p>

<p>I'm open to any discussion about different approach in order to reach the same goal.</p>

<p>Could you help me please?</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>Is this a known bug?</title>
      <link>https://forum.processing.org/two/discussion/24624/is-this-a-known-bug</link>
      <pubDate>Wed, 18 Oct 2017 14:13:00 +0000</pubDate>
      <dc:creator>Puddle</dc:creator>
      <guid isPermaLink="false">24624@/two/discussions</guid>
      <description><![CDATA[<p>I am currently working on an assignment for my school and I am running into a problem I can not seem to solve.</p>

<p>As this is a graded problem I would like to ask not to give me a solution but just to point out what could be causing this or if it's a known bug.</p>

<p>I am coding a program that needs to draw some content. The drawing is managed by a function that is invoked at the mouseClicked event.</p>

<p>Before the screen is drawn, the entire screen is refreshed within the called function using background(255).</p>

<p>The thing I am running into is that from time to time text content is placed on top of old content or lines are drawn towards the point that make up the starting point from where the text is drawn.</p>

<p>It does not produce this problem every time the program runs nor are any variables used that could effect the logic behind what is happening. Most annoying is that I can not seem to reproduce it myself. Going through the application the exact same way twice could one time produce this issue and the other time everything goes fine.</p>

<p>Any suggestions into what could be causing this would be great.</p>
]]></description>
   </item>
   <item>
      <title>loosing or gaining bytes through serial</title>
      <link>https://forum.processing.org/two/discussion/24268/loosing-or-gaining-bytes-through-serial</link>
      <pubDate>Tue, 26 Sep 2017 15:21:54 +0000</pubDate>
      <dc:creator>w4lt3r</dc:creator>
      <guid isPermaLink="false">24268@/two/discussions</guid>
      <description><![CDATA[<p>hello</p>

<p>I have a issue that Processing isn't reading out all(or too much) of the data it gets.</p>

<p>I am sending data from the arduino(in this case just the numbers 1-6) and want to read them out in processing. the Baudrate has some  effect but above and below 9600 it gets worse. I had in the past a delay in the arduino code, it didn't worked out neither.
 the catch(nullPointerException e) is there to catch strings that are 0, happened too in the past.</p>

<p>if i use other tools to read out the data from the serial such as the arduino serial monitor or Tera Term then there are no missing character/bytes.</p>

<p>SerialEvent doesn't trigger at all(with bufferuntil(10) or ('\n').</p>

<p>I hope someone has some ideas where the bug is crawling around.</p>

<p>walter</p>

<p>the processing code;</p>

<p>```
    import processing.serial.*;</p>

<pre><code>Serial myPort;        // The serial port
int xPos = 1;
int i,j,h,ii;         // horizontal position of the graph 
int lastxPos=1;
int lastheight=0;
int xPos1 = 1;         // horizontal position of the graph 
int lastxPos1=1;
int lastheight1=0;

String a="0";
int n=5;
String[] indata={a,a,a,a,a,a,a};//new String[6];
String[] indata2=new String[7];
  String InString;
int[] rawdata=new int[7];
float[] data=new float[7];
PrintWriter output;
//Variables to draw a continuous line.


int lf= 10;



public static final int portIndex=1;

void setup () {
  output= createWriter("output");
  // List all the available serial ports
  println(Serial.list());
  // Check the listed serial ports in your machine
  // and use the correct index number in Serial.list()[].
  println(" Connecting to -&gt; " + Serial.list()[portIndex]);
  myPort = new Serial(this, Serial.list()[portIndex], 9600);  //
  delay(3000);
  myPort.write(65);
  // A serialEvent() is generated when a newline character is received :
  myPort.bufferUntil('\n');
  background(7000);      // set inital background:
//  delay(100);
}

void draw(){

//print(InString);
  InString=myPort.readStringUntil('\n');
  print(InString);

  try{
     indata2=split(trim(InString)," ");
  for(int ii=0;ii&lt;indata2.length;ii++){  _**here the error is created**_
    indata[ii]=indata2[ii];
  }}
    catch(NullPointerException e){println("error invalid array");}
  for(int j=0;j&lt;indata.length;j++){
  rawdata[j]=int(trim(indata[j]));
  }
 //  println(rawdata);
 //  println(interval);
}
</code></pre>

<p>the arduino code:</p>

<pre><code>void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  for(int i=0;i&lt;7;i++){
Serial.print(i);
Serial.print("\r"" ");
  }
  Serial.print('\n');
}
</code></pre>

<p>and a typical output</p>

<p>5 61 2 3 4 5 6</p>

<p>0 1 2 3 4 5 6</p>

<p>0 0 1 2 3 4 5 6
or
0 1 2 3 4 5 6 1 2 3 4 5 6</p>
]]></description>
   </item>
   <item>
      <title>How to pause/play a sketch with the same button?</title>
      <link>https://forum.processing.org/two/discussion/23531/how-to-pause-play-a-sketch-with-the-same-button</link>
      <pubDate>Wed, 19 Jul 2017 22:20:41 +0000</pubDate>
      <dc:creator>s_diaconu</dc:creator>
      <guid isPermaLink="false">23531@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,
I'm trying to implement a pause/play for a sketch with the same key, for example if I press p the sketch should stop and if I press p again, the sketch should start again. So far I used the noLoop()/loop() to do this but with two different keys (p for pause, r for start). It does work if I use keyPressed() and keyReleased() but this means to hold down the key but this doesn't answer my question. Also in the pause mode I used redraw() for a single step while noLoop() and works good.
Here is some code I tried so far with two different keys:</p>

<p>public void keyPressed(){</p>

<pre><code>if ( key == 'p' )
    noLoop();
if ( key == 'r' )
    loop();
if ( key == 's' )
    redraw();
</code></pre>

<p>}</p>

<p>And this is the code with the same key:</p>

<p>public void keyPressed(){</p>

<pre><code>if ( key == 'p' )
    noLoop();
if ( key == 'p' )
    loop();
if ( key == 's' )
    redraw();
</code></pre>

<p>}</p>

<p>In this case when I press key it doesn't have any effect.
And the last one I tried is this:</p>

<p>public void keyPressed(){</p>

<pre><code>if ( key == 'p' )
    noLoop();
else
    loop();
if ( key == 's' )
    redraw();
</code></pre>

<p>}</p>

<p>In this case when I press 'p' it stops the sketch but is doesn't play again. Because of the 'else' it plays again when I press any key including 's' which suppose to be just for a single step.
Any help is more than welcome.
Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Touchdesigner - Equivalent in processing - Realtime button</title>
      <link>https://forum.processing.org/two/discussion/22936/touchdesigner-equivalent-in-processing-realtime-button</link>
      <pubDate>Mon, 05 Jun 2017 09:43:40 +0000</pubDate>
      <dc:creator>Sugarbank</dc:creator>
      <guid isPermaLink="false">22936@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys,
Just wanted to see if there is a similar functionality in processing where processing will wait until an entire frame is "cooked" until moving onto the next frame.....without trying to maintain real time playback.
Basically the functionality of the realtime button in TD</p>

<p>Trying to write out frames with out the skletch  running in realtime, however having the same result.
Cheers oin advance</p>
]]></description>
   </item>
   <item>
      <title>How to trigger programmaticaly the draw method of a sketch in 'instance' mode?</title>
      <link>https://forum.processing.org/two/discussion/22310/how-to-trigger-programmaticaly-the-draw-method-of-a-sketch-in-instance-mode</link>
      <pubDate>Mon, 01 May 2017 04:24:28 +0000</pubDate>
      <dc:creator>radumir</dc:creator>
      <guid isPermaLink="false">22310@/two/discussions</guid>
      <description><![CDATA[<p>Hi!</p>

<p>I just want to use noLoop() in setup and therefore call only once the draw method but I want to update (to draw again) the sketch in some circumstances.</p>

<p>What's the best advice to achieve this?</p>

<p>I saw that in 'instance' mode it is needed a function f(sketch) that inside defines sketch.setup and sketch.draw and returns nothing.</p>

<p>I intend to define inside a function, let's say drawMethod and make the sketch.draw = drawMethod and finally return an object { draw: drawMethod } in order to expose the method to the outside world and be able to be called later.</p>

<p>I'm not sure if this is the recommended way or not.</p>

<p>Kind regards,</p>

<p>Radu Mirescu</p>
]]></description>
   </item>
   <item>
      <title>Redraw() function not working, assistance required.</title>
      <link>https://forum.processing.org/two/discussion/21986/redraw-function-not-working-assistance-required</link>
      <pubDate>Thu, 13 Apr 2017 23:36:14 +0000</pubDate>
      <dc:creator>Gerdon</dc:creator>
      <guid isPermaLink="false">21986@/two/discussions</guid>
      <description><![CDATA[<p>Hello!
I'm quite new to processing and still figuring out how some of the basics work. I'm trying to use the redraw() function in this sketch, in order to redraw the screen. However, it's not redrawing anything.
I have a println() function in the void setup() which shows a value for the x variable, which randomises each time the sketch is run.
Whenever I press a key, I'm thinking that shouldn't the value of the x variable change in the console, which would then determine what the colour of the ellipse would be in the sketch? But, nothing is happening to the sketch. :(.</p>

<pre><code>float x = int (min(1,10));

void setup() {
  size(100, 100);
  smooth();
  println(x);
}

void draw() {
  if (x &gt; 5) {
    ellipse(50, 50, 50, 50);
  } else {
    rect(50, 50, 50, 50);
  }
}

void keyPressed() {
  redraw();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Two sensors trigger same part of code</title>
      <link>https://forum.processing.org/two/discussion/21447/two-sensors-trigger-same-part-of-code</link>
      <pubDate>Fri, 17 Mar 2017 03:27:40 +0000</pubDate>
      <dc:creator>Julo</dc:creator>
      <guid isPermaLink="false">21447@/two/discussions</guid>
      <description><![CDATA[<p>I am using two pressure sensors with arduino to receive two sets of values so I can trigger different things on the screen, but the two sensors keep only triggering the same part of code, I think it's the port problem but couldn't figure it out.</p>

<pre><code>import processing.sound.*;
import processing.serial.*;
import cc.arduino.*;

int linefeed;
int count;
int sensors[];
int a,b,c;

int lf0 = 10;
int lf1 = 10;

String myString0 = null;
String myString1 = null;
Serial myPort0;
Serial myPort1;
float pressureSession0num, pressureSession1num;

void setup() {
  myPort0 = new Serial(this, Serial.list()[0], 9600);
  myPort1 = new Serial(this, Serial.list()[1], 9600);
  myPort0.clear();
  myPort1.clear();
  fullScreen();
  smooth();
}

void draw() {
  background(0);
  while (myPort0.available() &gt; 0) {
    myString0 = myPort0.readStringUntil(lf0);
    if (myString0 != null) {
      pressureSession0num=float(myString0);  
      println("1P"+pressureSession0num);
    }
  }
  myPort0.clear();

  while (myPort1.available() &gt; 0) {  
    myString1 = myPort1.readStringUntil(lf1);
    if (myString1 != null) {
      pressureSession1num=float(myString1);  
      println("2P"+pressureSession1num);
    }
  }
  myPort1.clear();
}
  void counter() {
    if (pressureSession0num&gt;500) {
      a += 1;
    }
    if (pressureSession1num&gt;500) {
      b += 1;
    }
  }
</code></pre>

<p>Arduino code</p>

<pre><code>int analogPin0 = 0;
int analogPin1 = 1;

float temp0=0;
float temp1=0;

void setup() { 
  Serial.begin(9600);
} 

void loop() {
  temp0=analogRead(analogPin0);
  temp1=analogRead(analogPin1);

  Serial.println(temp0); // println add Linefeed to my float
  Serial.println(temp1); // println add Linefeed to my float

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

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

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

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

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

void draw() {
  background(0);
  fill(255);
  rect(10, 10, 20, 20);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>how to access an image that's dragged onto a DOM element</title>
      <link>https://forum.processing.org/two/discussion/19831/how-to-access-an-image-that-s-dragged-onto-a-dom-element</link>
      <pubDate>Mon, 19 Dec 2016 19:34:56 +0000</pubDate>
      <dc:creator>djneils98</dc:creator>
      <guid isPermaLink="false">19831@/two/discussions</guid>
      <description><![CDATA[<p>playing around with file dragging. I can get an image dragged into the page to display on the page using a createimg command and then I can put that image into the P5 canvas but is there a way of getting the dropped image file straight into a variable so I can access its pixels?
I tried this but no dice:</p>

<p>function gotFile(file){</p>

<p>var img = file.data
  image(img,0,0)
}</p>
]]></description>
   </item>
   <item>
      <title>In below code error Array out of bounds is coming in portName= Serial.list()[PortSelected];this line</title>
      <link>https://forum.processing.org/two/discussion/16199/in-below-code-error-array-out-of-bounds-is-coming-in-portname-serial-list-portselected-this-line</link>
      <pubDate>Sat, 23 Apr 2016 05:20:58 +0000</pubDate>
      <dc:creator>PPP12345</dc:creator>
      <guid isPermaLink="false">16199@/two/discussions</guid>
      <description><![CDATA[<p>import processing.serial.*;
int SerialPortNumber=2;
int PortSelected=2;</p>

<p>/*   =================================================================================<br />
 Global variables
 =================================================================================*/</p>

<p>int xValue, yValue, Command; 
boolean Error=true;</p>

<p>boolean UpdateGraph=true;
int lineGraph; 
int ErrorCounter=0;
int TotalRecieved=0;</p>

<p>/*   =================================================================================<br />
 Local variables
 =================================================================================*/
boolean DataRecieved1=false, DataRecieved2=false, DataRecieved3=false;</p>

<p>float[] DynamicArrayTime1, DynamicArrayTime2, DynamicArrayTime3;
float[] Time1, Time2, Time3; 
float[] Voltage1, Voltage2, Voltage3;
float[] current;
float[] DynamicArray1, DynamicArray2, DynamicArray3;</p>

<p>float[] PowerArray= new float[0];            // Dynamic arrays that will use the append()
float[] DynamicArrayPower = new float[0];    // function to add values
float[] DynamicArrayTime= new float[0];</p>

<p>String portName; 
String[] ArrayOfPorts=new String[SerialPortNumber];</p>

<p>boolean DataRecieved=false, Data1Recieved=false, Data2Recieved=false;
int incrament=0;</p>

<p>int NumOfSerialBytes=8;                              // The size of the buffer array
int[] serialInArray = new int[NumOfSerialBytes];     // Buffer array
int serialCount = 0;                                 // A count of how many bytes received
int xMSB, xLSB, yMSB, yLSB;                     // Bytes of data</p>

<p>Serial myPort;                                        // The serial port object</p>

<p>/*   =================================================================================<br />
 A once off serail port setup function. In this case the selection of the speed,
 the serial port and clearing the serial port buffer<br />
 =================================================================================*/</p>

<p>void SerialPortSetup() {</p>

<p>//  text(Serial.list().length,200,200);</p>

<p>portName= Serial.list()[PortSelected];
  //  println( Serial.list());
  ArrayOfPorts=Serial.list();
  println(ArrayOfPorts);
  myPort = new Serial(this, portName, 115200);
  delay(50);
  myPort.clear(); 
  myPort.buffer(20);
}</p>

<p>/* ============================================================<br />
 serialEvent will be called when something is sent to the 
 serial port being used. 
 ============================================================   */</p>

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

<p>while (myPort.available ()&gt;0)
  {
    /* ============================================================<br />
     Read the next byte that's waiting in the buffer. 
     ============================================================   */</p>

<pre><code>int inByte = myPort.read();

if (inByte==0)serialCount=0;

if (inByte&gt;255) {
  println(" inByte = "+inByte);    
  exit();
}

// Add the latest byte from the serial port to array:

serialInArray[serialCount] = inByte;
serialCount++;

Error=true;
if (serialCount &gt;= NumOfSerialBytes ) {
  serialCount = 0;

  TotalRecieved++;

  int Checksum=0;

  //    Checksum = (Command + yMSB + yLSB + xMSB + xLSB + zeroByte)%255;
  for (int x=0; x&lt;serialInArray.length-1; x++) {
    Checksum=Checksum+serialInArray[x];
  }

  Checksum=Checksum%255;



  if (Checksum==serialInArray[serialInArray.length-1]) {
    Error = false;
    DataRecieved=true;
  }
  else {
    Error = true;
    //  println("Error:  "+ ErrorCounter +" / "+ TotalRecieved+" : "+float(ErrorCounter/TotalRecieved)*100+"%");
    DataRecieved=false;
    ErrorCounter++;
    println("Error:  "+ ErrorCounter +" / "+ TotalRecieved+" : "+float(ErrorCounter/TotalRecieved)*100+"%");
  }
}

if (!Error) {


  int zeroByte = serialInArray[6];
  // println (zeroByte &amp; 2);

  xLSB = serialInArray[3];
  if ( (zeroByte &amp; 1) == 1) xLSB=0;
  xMSB = serialInArray[2];      
  if ( (zeroByte &amp; 2) == 2) xMSB=0;

  yLSB = serialInArray[5];
  if ( (zeroByte &amp; 4) == 4) yLSB=0;

  yMSB = serialInArray[4];
  if ( (zeroByte &amp; 8) == 8) yMSB=0;


  //   println( "0\tCommand\tyMSB\tyLSB\txMSB\txLSB\tzeroByte\tsChecksum"); 
  //  println(serialInArray[0]+"\t"+Command +"\t"+ yMSB +"\t"+ yLSB +"\t"+ xMSB +"\t"+ xLSB+"\t" +zeroByte+"\t"+ serialInArray[7]); 

  // &gt;=====&lt; combine bytes to form large integers &gt;==================&lt; //

  Command  = serialInArray[1];

  xValue   = xMSB &lt;&lt; 8 | xLSB;                    // Get xValue from yMSB &amp; yLSB  
  yValue   = yMSB &lt;&lt; 8 | yLSB;                    // Get yValue from xMSB &amp; xLSB

    // println(Command+ "  "+xValue+"  "+ yValue+" " );

  /*
</code></pre>

<p>How that works: if xMSB = 10001001   and xLSB = 0100 0011 
       xMSB &lt;&lt; 8 = 10001001 00000000    (shift xMSB left by 8 bits)<br />
       xLSB =          01000011<br />
       xLSB | xMSB = 10001001 01000011    combine the 2 bytes using the logic or |
       xValue = 10001001 01000011     now xValue is a 2 byte number 0 -&gt; 65536<br />
       */</p>

<pre><code>  /*  ==================================================================
   Command, xValue &amp; yValue have now been recieved from the chip
   ==================================================================  */

  switch(Command) {


    /*  ==================================================================
     Recieve array1 and array2 from chip, update oscilloscope      
     ==================================================================  */

  case 1: // Data is added to dynamic arrays
    DynamicArrayTime3=append( DynamicArrayTime3, (xValue) );
    DynamicArray3=append( DynamicArray3, (yValue) );

    break;

  case 2: // An array of unknown size is about to be recieved, empty storage arrays
    DynamicArrayTime3= new float[0]; 
    DynamicArray3= new float[0]; 
    break;    

  case 3:  // Array has finnished being recieved, update arrays being drawn 
    Time3=DynamicArrayTime3;
    Voltage3=DynamicArray3;
 //   println(Voltage3.length);
    DataRecieved3=true;
    break;  

    /*  ==================================================================
     Recieve array2 and array3 from chip
     ==================================================================  */


  case 4: // Data is added to dynamic arrays
    DynamicArrayTime2=append( DynamicArrayTime2, xValue );
    DynamicArray2=append( DynamicArray2, (yValue-16000.0)/32000.0*20.0  );
    break;

  case 5: // An array of unknown size is about to be recieved, empty storage arrays
    DynamicArrayTime2= new float[0]; 
    DynamicArray2= new float[0]; 
    break;    

  case 6:  // Array has finnished being recieved, update arrays being drawn 
    Time2=DynamicArrayTime2;
    current=DynamicArray2;
    DataRecieved2=true;
    break;  

    /*  ==================================================================
     Recieve a value of calculated power consumption &amp; add it to the 
     PowerArray.
     ==================================================================  */
  case 20:  
    PowerArray=append( PowerArray, yValue );

    break; 

  case 21:  
    DynamicArrayTime=append( DynamicArrayTime, xValue ); 
    DynamicArrayPower=append( DynamicArrayPower, yValue );



    break;
  }
}
</code></pre>

<p>}
  redraw();<br />
  //    }
}</p>
]]></description>
   </item>
   <item>
      <title>myPort.available always 0</title>
      <link>https://forum.processing.org/two/discussion/14534/myport-available-always-0</link>
      <pubDate>Tue, 19 Jan 2016 15:35:27 +0000</pubDate>
      <dc:creator>langrenne</dc:creator>
      <guid isPermaLink="false">14534@/two/discussions</guid>
      <description><![CDATA[<p>Hy,</p>

<p>I'm on Linux kubuntu.
I would like receive data from an arduino nano (3 axis motion for head tracking).
The arduino code works because I can read data with Pure Data (Pd).
The arduino is on port [32] (/dev/ttyUSB0)</p>

<p>I use the common code:</p>

<pre><code>// Example by Tom Igoe

import processing.serial.*;

int lf = 10;    // Linefeed in ASCII
String myString = null;
Serial myPort;  // The serial port

void setup() {
  // List all the available serial ports
  printArray(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[32], 9600);
  myPort.clear();
  // Throw out the first reading, in case we started reading 
  // in the middle of a string from the sender.
  myString = myPort.readStringUntil(lf);  
  myString = null;
}

void draw() {
  println(myPort.available());

  while (myPort.available() &gt; 0) {
    myString = myPort.readStringUntil(lf);
    if (myString != null) {
      println(myString);
    }
  }
}
</code></pre>

<p>But myPort.available is always 0. I can't read anything.</p>

<p>Can someone help me ?</p>

<p>thanks</p>
]]></description>
   </item>
   <item>
      <title>How to exclude values in a variable and reset the program to start with a single click mouse</title>
      <link>https://forum.processing.org/two/discussion/14883/how-to-exclude-values-in-a-variable-and-reset-the-program-to-start-with-a-single-click-mouse</link>
      <pubDate>Fri, 12 Feb 2016 23:29:05 +0000</pubDate>
      <dc:creator>theomail</dc:creator>
      <guid isPermaLink="false">14883@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I would like to know how to exclude values in a variable when it takes values in a random () function. For example my variable y takes values randomly between 20 and 780 or y = (random (20,780))
However I do not want the variable y takes values between 300 and 400.
Basically I want a function that prohibits y to take value between 300 and 400 but the rest yes.
In addition I also search a function to initialize the program at the beginning when I press my mouse with a simple click. Indeed when I click on run, the program starts on a page 1 and when I finished my program, the program shows me on page 2. So on the page 2 when I click with my mouse, it starts again like at the beginning. If it's possible of course.</p>

<p>Thank you.</p>
]]></description>
   </item>
   <item>
      <title>Button-problem method()</title>
      <link>https://forum.processing.org/two/discussion/14039/button-problem-method</link>
      <pubDate>Thu, 17 Dec 2015 10:08:52 +0000</pubDate>
      <dc:creator>Eeyorelife</dc:creator>
      <guid isPermaLink="false">14039@/two/discussions</guid>
      <description><![CDATA[<p>I started a thread some time ago asking for neat ways to code buttons (<a href="https://forum.processing.org/two/discussion/13157/what-s-your-favourite-way-to-code-a-button#latest" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/13157/what-s-your-favourite-way-to-code-a-button#latest</a>)
And There were two great answers that used <code>method()</code> Which I didn't even knew existed. 
But is there a way to use <code>method()</code> or something similar to access a method inside a class?</p>
]]></description>
   </item>
   <item>
      <title>Continual RESTful request to JSON on server, parse on the fly, render data inside P5js draw loop.</title>
      <link>https://forum.processing.org/two/discussion/13845/continual-restful-request-to-json-on-server-parse-on-the-fly-render-data-inside-p5js-draw-loop</link>
      <pubDate>Tue, 08 Dec 2015 22:22:34 +0000</pubDate>
      <dc:creator>bisr</dc:creator>
      <guid isPermaLink="false">13845@/two/discussions</guid>
      <description><![CDATA[<p>Hi All, I am doing an agent-based model in Go (golang.org). I am a final year CS student working on a research project for in conjunction with researchers in the Biology department at my university.</p>

<p>I need a web-client viewport which will render the 'state' (i.e. position etc) of each agent within the 2D environment which is handled on the server. There are tens of thousands of agents (potentially millions) which necessitates a true concurrent programming and runtime environment (hence why I am doing it in Go) – this is way too much overhead to be done entirely in a sketch or even dynamically on the client side. Therefore the actual drawing is offloaded to the client, but all the computation (beyond JSON unmarshalling and coordinate translation to the world space of the sketch/viewport) is done on a dedicated server.</p>

<p>I also come from art school prior to going into computer science, and I really like Processing/P5 as it directly gives you the drawing/animation environment and nothing else (unless you want to go digging under the hood). It's much faster to iterate and get what you want on screen. I know what I want to do can be done in HTML5 canvas only, or in Javascript + CSS but it's unnecessarily laborious and P5 has all the drawing functionality I need with a very easy to use API. Learning one language (Go) for this project is more than enough for me.</p>

<p>What I want to draw inside a sketch (viewport) is very simple: points, with varying stroke widths and colours. That's it. I just need to draw tens of thousands of them constantly, updating as they change position. All the computation which determines where those points are before being drawn is delivered via a JSON from the server. What I need is for the P5 sketch to do a bit of translation from the JSON object into some (predeclared and global) arrays of x,y pairs and just draw points at those coordinates by iterating through the said arrays. I don't need to block draw() from being called until the GET request is filled and the JSON has been processed, it should just render the contents of the arrays in the state they currently are in. So, there are two continual processes occurring by the client.</p>

<p>FIRST: LOOP( requesting the JSON data, processing it)
SECOND: DRAW LOOP.</p>

<p>Anyone have any experience with something like this? Maybe there is a better and simpler way to do it?</p>

<p>I would say that the obvious alternative would be to bypass the seperate request for the JSON entirely and just have a web socket open so you are directly getting the array data from a function call inside the draw loop. I.e. via http you get the iteration range, then a value for the co-ordinates of each point... hmm.... It doesn't matter that this will slow down the framerate at all by waiting for the requests. I just need the easiest way to get the co-ordinates into memory to be drawn in the sketch.</p>
]]></description>
   </item>
   <item>
      <title>How make key combos?</title>
      <link>https://forum.processing.org/two/discussion/13786/how-make-key-combos</link>
      <pubDate>Sat, 05 Dec 2015 07:02:19 +0000</pubDate>
      <dc:creator>Jayccob</dc:creator>
      <guid isPermaLink="false">13786@/two/discussions</guid>
      <description><![CDATA[<p>So I am working on a simple UI and What the hope is that when I press UP a small ellipse goes up, when I press LEFT it goes left. However when I press UP &amp;&amp; LEFT it goes to the upper left hand corner.So far I have tried to get this with this code</p>

<pre><code>void trackerKeys(){
  if(keyPressed== true){
    switch(keyCode){      
      case LEFT:
         ellipse(50,125, 25, 25);
         break;
      case RIGHT:
         ellipse(200,125, 25, 25);
         break;
      case UP:
         ellipse(125,50, 25, 25);
         break;
      case DOWN:
           ellipse(125,200, 25, 25);
           break;
      default:
         ellipse(125,125, 25, 25);
         break;
    }
  }
  else{
     ellipse(125,125, 25, 25);
  }
}
</code></pre>

<p>But all that gets me is one plane of movement. Then there was this code</p>

<pre><code>void trackerKeys(){
    switch(keyCode){      
      case LEFT:
         g= 50;
         break;
      case RIGHT:
         g= 200;
         break;
      case UP:
         f= 50;
         break;
      case DOWN:
         f= 200;
         break;
      default:
        f=125;
        g=125;
        break;
  }
  ellipse(g,f,25,25);
}
</code></pre>

<p>And all that gets me is the ellipse is stuck in the corners, so close....
I played with some if/else stuff but that wasn't to good at all. Any ideas?</p>
]]></description>
   </item>
   <item>
      <title>mapping event (modifying x and y)</title>
      <link>https://forum.processing.org/two/discussion/13573/mapping-event-modifying-x-and-y</link>
      <pubDate>Fri, 20 Nov 2015 03:03:29 +0000</pubDate>
      <dc:creator>gperez</dc:creator>
      <guid isPermaLink="false">13573@/two/discussions</guid>
      <description><![CDATA[<p>Hi. 
I'm working on a "control window", meaning a secondary window that can control the primary one. 
In that control window I have a little representation of the main window. And i wish i could click on that little section and map mouseEvents to primary window. Issue is that mouseEvent class has no public method to modify x and y values. 
Is there any java trick I could implement?
Thanks in advance.</p>
]]></description>
   </item>
   <item>
      <title>Receiving 3 data from arduino to processing</title>
      <link>https://forum.processing.org/two/discussion/12596/receiving-3-data-from-arduino-to-processing</link>
      <pubDate>Sun, 20 Sep 2015 13:13:32 +0000</pubDate>
      <dc:creator>Avishek</dc:creator>
      <guid isPermaLink="false">12596@/two/discussions</guid>
      <description><![CDATA[<p>Dear All,</p>

<p>I am new to JAVA and processing. Can you tell me that how can I receive three serial data from arduino uno.</p>

<p>I am sending three parameters from arduino as.</p>

<pre><code>Serial.print(i);
Serial.print(",");
Serial.print(D1);
Serial.print("_");
Serial.print(D2);
Serial.print(".");  // termination.
</code></pre>

<p>But I do not know how to receive the three different data. Yet I am sucessful to receive TWO of them.</p>

<p>Please help me Sir/ Madam</p>
]]></description>
   </item>
   <item>
      <title>Placing images in draw loop (slows browser down)</title>
      <link>https://forum.processing.org/two/discussion/12120/placing-images-in-draw-loop-slows-browser-down</link>
      <pubDate>Mon, 17 Aug 2015 08:57:02 +0000</pubDate>
      <dc:creator>brig</dc:creator>
      <guid isPermaLink="false">12120@/two/discussions</guid>
      <description><![CDATA[<p>Hi there. 
In the p5 examples, I see images loaded in setup() and then drawn in draw(). However, when I draw four or so images in the draw() loop, the browser gets jerky/slow on browser window resize. I can fix this problem by calling noLoop() in setup, but that creates a whole host of other issues and workarounds (like trying to determine the value on change of a p5 slider).</p>

<p>I suppose my question is: are images really supposed to be drawn in draw()? Seems like drawing the image over and over again in this loop isn't the best use of resources - as evidenced by the slowdown on resize.</p>

<p>Maybe I'm missing a paradigm? I'm a newbie - so would be happy to hear how I'm supposed to be thinking about this. It just seems a little strange to put image(img, 0, 0) in the draw loop, when i know it's not going to change - unless there's a given user event. Know what I mean?</p>
]]></description>
   </item>
   <item>
      <title>Resizing Window Causes Problems? (Processing 3)</title>
      <link>https://forum.processing.org/two/discussion/12333/resizing-window-causes-problems-processing-3</link>
      <pubDate>Tue, 01 Sep 2015 02:27:42 +0000</pubDate>
      <dc:creator>bogusburger</dc:creator>
      <guid isPermaLink="false">12333@/two/discussions</guid>
      <description><![CDATA[<p>Heres's a little program I wrote to test a problem I had in a project I'm working on:</p>

<pre><code>int bg = 0;
int i = 0;

void setup() {
  size(790,640);
  surface.setResizable(true);
  test();
}

void draw() {

}

void keyPressed() {
  test();
}

void test() {
  surface.setSize(790, 640+10*i);
  background(bg);
  if (bg == 0) {bg = 50;} else {bg = 0;}
  fill(bg);
  ellipse(width/2, height/2, 200, 200);
  i++;
}
</code></pre>

<p>This code <em>should</em> draw a circle in the center of the window every time a key is pressed, along with resizing the window to be 10 pixels longer. However, for some reason the circle stops drawing when I press a key, yet background still changes. This also happens with line() and rect(). The only way I can get the circle to draw is if I put it in the draw() loop, but that will eat CPU. I also tried this in Processing 2 with frame.setSize(), with no luck. Is there an explanation to why this is happening or anything I can do to fix it?</p>

<p>Any help is greatly appreciated!</p>
]]></description>
   </item>
   <item>
      <title>Is there a way to set a new draw handler?</title>
      <link>https://forum.processing.org/two/discussion/12265/is-there-a-way-to-set-a-new-draw-handler</link>
      <pubDate>Wed, 26 Aug 2015 22:53:59 +0000</pubDate>
      <dc:creator>shawnlau</dc:creator>
      <guid isPermaLink="false">12265@/two/discussions</guid>
      <description><![CDATA[<p>Below is a brief example of my problem. The draw function acts completely different depending on the mode. In the real case, there are a lot more modes and things area lot more complicated than drawing a shape. I don't want my draw loop to run through a bunch of nested booleans every time it executes. Ideally, the draw function for that mode should be set when the user changes mode instead of checking a bunch of  booleans 60 times a second. In C I'd use a pointer to a function and reset it when the mode changes. How would I get the same function in Processing? I know with a gp4 window you can
 myWindow.addDrawHandler(), but I think you can only do it at the setup. I need a way to change the main draw loop dynamically.</p>

<pre><code>PImage img;
int CIRCLE = 0;
int RECTANGLE = 1;
int mode = CIRCLE;

void setup(){
size(200,200);
img = createImage(200,200,RGB);
}
void draw(){
     background(150);
     if( mode == CIRCLE)
          ellipse(100,100,30,30);
     if( mode == RECTANGLE)
          rect(75,75,50,50);
}
void keyPressed(){
     if(key == ' '){
          if(mode == CIRCLE)
               mode = RECTANGLE;
          else mode = CIRCLE;
     }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why do I have to call  pg.beginDraw() pg.endDraw(0 on a PGraphics I'm copying, not drawing on?</title>
      <link>https://forum.processing.org/two/discussion/12048/why-do-i-have-to-call-pg-begindraw-pg-enddraw-0-on-a-pgraphics-i-m-copying-not-drawing-on</link>
      <pubDate>Wed, 12 Aug 2015 16:38:32 +0000</pubDate>
      <dc:creator>shawnlau</dc:creator>
      <guid isPermaLink="false">12048@/two/discussions</guid>
      <description><![CDATA[<p>This first code fails unless you uncomment the spurious canvas.beginDraw() canvas.endDraw().</p>

<p>Why is that needed? I've drawn to it with beginDraw() and endDraw() but I can't copy it unless I call them again.</p>

<pre><code>PGraphics canvas;
PGraphics hidden;
PGraphics temp;

void setup(){
     canvas = createGraphics(400,400);
     hidden = createGraphics(400,400);
     temp = createGraphics(400,400);
     size(400,400);
     canvas.beginDraw();
     canvas.background(100);
     canvas.endDraw();
     hidden.beginDraw();
     hidden.fill(150,200,0);
     hidden.rect(150,150,100,100);
     hidden.endDraw();
}
void draw(){

     image(canvas,0,0);
}  
void keyPressed(){
     if(key == '1'){
    //      canvas.beginDraw();  //uncomment these lines and it works.
   //       canvas.endDraw();
          temp.beginDraw();
          temp.image(canvas,0,0);
          temp.endDraw();
          canvas.beginDraw();
          canvas.image(hidden,0,0);
          canvas.endDraw();
          hidden.beginDraw();
          hidden.image(temp,0,0);
          hidden.endDraw();
     }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Open Sound Control Message Lisener instead of draw loop?!</title>
      <link>https://forum.processing.org/two/discussion/12022/open-sound-control-message-lisener-instead-of-draw-loop</link>
      <pubDate>Mon, 10 Aug 2015 05:57:30 +0000</pubDate>
      <dc:creator>algcomposer</dc:creator>
      <guid isPermaLink="false">12022@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>in my current project, i have some timing problems when rendering in realtime. As many of you might have experienced, the draw loop is not always a relieable timer. In my experience, it is better to have objects that render dependent on millis() instead of relying on a stable framerate. But still, this is not very smooth in more complex cases. (Strange, it is not a performance problem. It also happens to be unsmooth when the CPU is happy with 30%)</p>

<p>I am thinking about to trigger the drawing action from outside the Processing sketch, lets say a plain Java-application which just contains one thread which sends an Open Sound Control Message to the sketch every xxx milliseconds. And the sketch will render one Frame when it receives one of these messages.</p>

<p>Something like:</p>

<pre><code>public void oscEvent(OscMessage theOscMessage)
  anObjectWhichDoesRendering.draw(playHead);
  playHead += playHeadStep;
}
</code></pre>

<p>Question to those who know more about Java, OSC and Threading than me: Is this approach worth a try?</p>

<p>Thanks in advance</p>

<p>nossekk</p>
]]></description>
   </item>
   <item>
      <title>How can make my sketch know when the mouse is moved OUTSIDE of the sketch window?</title>
      <link>https://forum.processing.org/two/discussion/11471/how-can-make-my-sketch-know-when-the-mouse-is-moved-outside-of-the-sketch-window</link>
      <pubDate>Fri, 26 Jun 2015 21:53:32 +0000</pubDate>
      <dc:creator>TechWiz777</dc:creator>
      <guid isPermaLink="false">11471@/two/discussions</guid>
      <description><![CDATA[<p>The question says it all. If I'm not mistaken, I need to use something that consists of a Robot, or something like that?</p>
]]></description>
   </item>
   <item>
      <title>'Nullpointerexception' error</title>
      <link>https://forum.processing.org/two/discussion/11182/nullpointerexception-error</link>
      <pubDate>Sat, 06 Jun 2015 05:48:04 +0000</pubDate>
      <dc:creator>omer_z</dc:creator>
      <guid isPermaLink="false">11182@/two/discussions</guid>
      <description><![CDATA[<p>Hi All!</p>

<p>I'm new to Processing so, have mercy...
I keep getting a 'nullpointerexception' error but I cant figure out why.</p>

<p>that's my code (I tried to format it as code but, in the preview its still a mess, sorry I'll give it a shot anyway) :
I get the 'Nullpointerexception' error on the <strong>fill (sensor1Data [k], 0, 0);</strong> line in the draw procedure.</p>

<pre>
import processing.serial.*;

Serial CommPort ;
int [ ] sensor1Data ;
int [ ] sensor2Data ;
int [ ] sensor3Data ;
int [ ] sensor4Data ;
int sensor_cnt = 1 ;
int last_in = 0 ;

void setup() 
  {
  size(800, 800);
  frameRate(30);
  CommPort = new Serial (this, Serial.list( ) [1], 38400);
  CommPort.bufferUntil ('\r');
  println(Serial.list());
  }

void draw()
  {
  background( 100 ) ; 
  if (last_in == 1)
    {
    println( "Update Display" ) ;
    for(int k = 0 ; k &lt; 20 ; k++ )
      {
      fill (sensor1Data [k], 0, 0);
      rect(k*30, 330-k*15, 30, 30) ;
      fill (sensor2Data [k], 0, 0) ;
      rect(k*30, 365-k*5, 30, 30) ;
      fill (sensor3Data [k], 0, 0) ;
      rect(k*30, 400+k*5, 30, 30) ;
      fill (sensor4Data [k], 0, 0) ;
      rect(k*30, 435+k*15, 30, 30) ;
      } 
    last_in = 0 ;
    }
  }

void serialEvent ( Serial CommPort )
{
  println( "Data In!" ) ;
  String usbString = CommPort.readStringUntil ('\r');
  if (usbString != null)
  {
    usbString = trim(usbString);
    switch (sensor_cnt)
    {
    case 1:
      {
        int sensor1Data[ ] = int (split (usbString, ','));
        for (int sensorNum = 0; sensorNum &lt; sensor1Data.length; sensorNum++)
          println( "Sensor1 " + sensorNum + ": " + sensor1Data [sensorNum] );
        sensor_cnt++ ;
      } 
      break ;
    case 2:
      {
        int sensor2Data[ ] = int (split (usbString, ','));
        for (int sensorNum = 0; sensorNum &lt; sensor2Data.length; sensorNum++)
          println( "Sensor2 " + sensorNum + ": " + sensor2Data [sensorNum] );
        sensor_cnt++ ;
      } 
      break ;
    case 3:
      {
        int sensor3Data[ ] = int (split (usbString, ','));
        for (int sensorNum = 0; sensorNum &lt; sensor3Data.length; sensorNum++)
          println( "Sensor3 " + sensorNum + ": " + sensor3Data [sensorNum] );
        sensor_cnt++ ;
      } 
      break ;
    case 4:
      {
        int sensor4Data[ ] = int (split (usbString, ','));
        for (int sensorNum = 0; sensorNum &lt; sensor4Data.length; sensorNum++)
          println( "Sensor4 " + sensorNum + ": " + sensor4Data [sensorNum] );
        sensor_cnt = 1 ;
        last_in = 1 ;
      } 
      break ;
    }
  }
}

</pre>

<p>Many Thanks</p>

<p>Omer</p>
]]></description>
   </item>
   <item>
      <title>How to achieve redraw without mousePress?</title>
      <link>https://forum.processing.org/two/discussion/10823/how-to-achieve-redraw-without-mousepress</link>
      <pubDate>Fri, 15 May 2015 11:14:16 +0000</pubDate>
      <dc:creator>Hill</dc:creator>
      <guid isPermaLink="false">10823@/two/discussions</guid>
      <description><![CDATA[<p>Here is my code, i need to achieve redraw by mousePress. But i want to write the code that when y=300, it code will redraw automatically. By the way, i println my code in gcode writing way, when the code start, it will show in the black window. It is helpful to check each value of x and y</p>

<p>`int x,y,e;
void setup(){
  x=5;
  y=0;
 size(500,500);
}</p>

<p>void draw(){
  background(255,255,255);
   y=y+1;</p>

<p>if (y&gt;300){
    y=300;
    point(x,y);
  }</p>

<p>String[] gcode=new String[6];</p>

<p>gcode[0]="X";
gcode[1]=str(x);
gcode[2]="Y";
gcode[3]=str(y);
gcode[4]="E";
gcode[5]=str(e);</p>

<p>String joinedgcode = join(gcode,"");
println(joinedgcode);</p>

<p>e+=1; 
}</p>

<p>void mousePressed() {
  x += 1;
  y=0;
  redraw();
}`</p>
]]></description>
   </item>
   </channel>
</rss>