<?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 papplet.runsketch() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=papplet.runsketch%28%29</link>
      <pubDate>Sun, 08 Aug 2021 16:16:32 +0000</pubDate>
         <description>Tagged with papplet.runsketch() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedpapplet.runsketch%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Splitting draw() output to multiple monitors</title>
      <link>https://forum.processing.org/two/discussion/28138/splitting-draw-output-to-multiple-monitors</link>
      <pubDate>Mon, 22 Oct 2018 06:25:55 +0000</pubDate>
      <dc:creator>gerome</dc:creator>
      <guid isPermaLink="false">28138@/two/discussions</guid>
      <description><![CDATA[<p>Hello
I draw a 3840 x 2160 picture and want to split this to two monitors: one 4K and one FullHD. or
I draw a 1920 x 2160 picture and want to split this to two FullHD monitors. 
My solution as hitherto with 2 threads on Processing is not suitabel because it is not stable enough. I am now looking more for a paid software solution. Has anybody a hint which to use?</p>
]]></description>
   </item>
   <item>
      <title>How to use Grafica objects/methods in an independent window generated by G4P GUI builder</title>
      <link>https://forum.processing.org/two/discussion/27141/how-to-use-grafica-objects-methods-in-an-independent-window-generated-by-g4p-gui-builder</link>
      <pubDate>Fri, 23 Mar 2018 22:19:58 +0000</pubDate>
      <dc:creator>FRV</dc:creator>
      <guid isPermaLink="false">27141@/two/discussions</guid>
      <description><![CDATA[<p>Dear all,
I'm a beginer with Processing so my question might not be posed in the correct manner.</p>

<p>Still, I tried to use the Gplot objects and the related methods provided in the library Grafica. It works fine when the GPlot are manipulated in the MAIN window (i.e. main Draw function).
I'm now trying to get the same graphs in an independent window generated with G4P builder. For that, I tried to place the Gplot related code (Gplot objects and manipulation) in the draw handler (win_draw) generated by G4P GUI builder.
However, when I'm trying to use the same Gplot objects/methods there, I get consitently the following error :</p>

<p>_An error occured during execution of the eventhandler:
CLASS: DataLogger1_1_PDE   METHOD: win_draw
    Caused by java.lang.NullPointerException)</p>

<p>This makes sometime the computer (OSx10.8 / processing3) crashing.</p>

<p>Can anybody share experience/examples on how to pass a Gplot object to the draw handler / independent window + getting the plot drawn there and not in the main.</p>

<p>Thank you in advance for your hep !!!</p>
]]></description>
   </item>
   <item>
      <title>real time data program</title>
      <link>https://forum.processing.org/two/discussion/28059/real-time-data-program</link>
      <pubDate>Sat, 16 Jun 2018 22:21:54 +0000</pubDate>
      <dc:creator>vjjv</dc:creator>
      <guid isPermaLink="false">28059@/two/discussions</guid>
      <description><![CDATA[<p>hey guys. in this time i need some help to optimize a system to pick shaders in real time (fragment shaders, and vertex shaders). This code is a mix that i recoleted in internet with code writing by myself.</p>

<p>Theres a lot of problem and i need help:</p>

<p>the idea of the program is that user can pick the shader in real time. 
there are two problems, first, i dont know how uploading the vertexShader, when i save it and reload it i need to click in another frag and then vertex upload.</p>

<p>second, it seems very inestable.the window of shaders crash very often, specially when frame rate is lowest. I wondering how to fix that. maybe with thread(), but it dont know exactly how apply this method..</p>

<p>If someone have time and wants to help, im sure that this code needs to be re writing. Thanks!</p>

<pre><code>ShaderWindow shaderWin;

boolean recording = false;


import netP5.*;
import oscP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

import themidibus.*;
MidiBus bus;
MidiBus apc;
float cc [] =new float [256];


boolean record, load;
double folderTime;
File folderShader;
float desmouse = 0.5;

// BUFFERS-SHADERS

String dirFolderShaders;
String dirFolderShaders2;
String dirFolderShadersvertex;

PGraphics [] buffers = new PGraphics [4];
PGraphics buffer;

LoadShader loadshader;

LoadShader loadshader2;
LoadShader loadshaderVertex;

ArrayList&lt;ViewShader&gt;vs = new ArrayList&lt;ViewShader&gt;();
ViewShaderVertex ss;

PShader sh, buffer1;
float count;
float angle = random(0, 0.005);

int choiceSize =1;
//int ww =  1920;
//int h = 1080;

void settings() {
  if (choiceSize==0) fullScreen(P3D, 2);
  if (choiceSize==1) size(1000, 1000, P3D);
  if (choiceSize==2) size(720, 1280, P3D);
}

void setup() {

  // BUFFERS-SHADERS

  dirFolderShaders = sketchPath("frag/");  //PUT SOME FRAGMENT IN THIS FOLDER

  dirFolderShadersvertex = sketchPath("vertex/"); PUT SOME VERTEX IN THIS FOLDER

  loadshader = new LoadShader(dirFolderShaders);

  loadshaderVertex = new LoadShader(dirFolderShadersvertex);


  for (int i = 0; i &lt; buffers.length; i++) {
    buffers[i] = createGraphics(width, height, P3D);
  }


  ss = new ViewShaderVertex(loadshaderVertex.shadersPaths[1], loadshaderVertex, buffer);
  vs.add(new ViewShader(loadshader.shadersPaths[0], loadshader, buffer, ss));

  shaderWin = new ShaderWindow();
}

void draw() {

  background(0);


  for (ViewShader s : vs) {
    s.update();
  }


  if (folderShader.listFiles().length != loadshader.shadersNames.length) {
    loadshaderVertex.loadFolderShader();
  }

  if (folderShader.listFiles().length != loadshader.shadersNames.length) {
    loadshader.loadFolderShader();
  }




  buffers[0].beginDraw();
  buffers[0].background(0);
  buffers[0].translate(width/2, height/2);


  buffers[0].sphere(100);
  buffers[0].endDraw();

  image(buffers[0],0,0);
}



// LOAD SHADER CLASS

class LoadShader {

  String dirFolderShaders;

  String[] shadersNames;
  String[] shadersPaths;

  LoadShader(String _dirFolderShaders) {
    dirFolderShaders= _dirFolderShaders;
    loadFolderShader();
  }

  void loadFolderShader() {
    load = true;
    folderShader = new File(dirFolderShaders);
    File files[] = folderShader.listFiles();
    shadersNames = new String[files.length];
    shadersPaths = new String[files.length];
    for (int i = 0; i &lt; files.length; i++) {
      shadersNames[i] = split(files[i].getName(), ".")[0];
      shadersPaths[i] = files[i].getAbsolutePath();
      //println(shadersNames[i]);
    }
    load = false;
  }
}

class ViewShader {

  boolean reload, error, loaded;
  File fileShader;

  long timeModi;
  long timeModis;
  String src;

  PShader shader;
  PShader shader1;
  PShader shader2;
  float a;
  LoadShader loadshader;
  ViewShaderVertex ss;
  PGraphics b;

  ViewShader(String _src, LoadShader _loadshader, PGraphics _b) {
    src = _src;
    fileShader = new File(src);
    openShader(fileShader);
    //shader1 = loadShader("blur.glsl", "bloomVert.glsl");
    //shader2 = loadShader("blur_vertical.glsl", "bloomVert.glsl");
    loadshader = _loadshader;
    b = _b;
  }

  ViewShader(String _src, LoadShader _loadshader, PGraphics _b, ViewShaderVertex _s) {
    ss = _s;

    //shader = loadShader("test2.glsl", "defaultVertex2.glsl");
    //shader1 = loadShader("blur.glsl", "bloomVert.glsl");
    //shader2 = loadShader("blur_vertical.glsl", "bloomVert.glsl");

    src = _src;
    fileShader = new File(src);
    openShader(fileShader);
    loadshader = _loadshader;
    b = _b;
  }


  void update() {
    if (reload) {      
      openShader(fileShader);
      reload = false;
    }
    if (shader != null) {

      //float p = map(cc[15], 0, 1, 0, 1);
      //float amt = map(cc[16], 0, 1, 1, 50);
      //float  h = map(cc[48], 0, 1, 0, 0.1);
      // //float  h = map(cc[14], 0, 1, 0, 0.5);


      shader.set("u_time", random(10));

      //shader1.set("u_time", angle);
      //shader2.set("u_time", angle);

      //shader.set("var2", p);
      //shader.set("amt", amt);

      //shader1.set("var2", p);
      //shader2.set("var2", p);


      if (fileShader.lastModified() != timeModi) {
        openShader(fileShader);
      }
    }
  }


  void newShader(String _srcc) {
    src = _srcc;
    fileShader = new File(src);
    reload = true;
    openShader(fileShader);
  }

  void openShader(File file) {
    if (file != null) {
      fileShader = file;
      timeModi = fileShader.lastModified();  
      try {
        shader = loadShader(file.getAbsolutePath(), ss.fileShader.getAbsolutePath());

        buffers[0].shader(shader);


        println(file.getAbsolutePath());
        error = false;
        loaded = true;
      }
      catch (RuntimeException e) {
        if (error == false) {
          error = true;
          // String time = nf(str(hour()),2) + ":" + nf(str(minute()),2) + ":" + nf(str(second()),2);
          println("\n");
          // println("At", time, "loadShader() returned the following error: \n");
          println("loadShader() returned the following error: \n");
          e.printStackTrace();
        }
        loaded = false;
      }
    }
  }
}

public class ShaderWindow extends PApplet {

  ShaderWindow() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  }

  boolean mover;

  void settings() {
    size(600, 800, P2D);
  }

  void setup() {
    this.frameRate(30);
  }


  void draw() {

    background(25);


    for (int i = 0; i &lt; vs.size(); i++) {
      ViewShader sss = vs.get(i);
      selector(i*100, 16, 100, width-16, sss, sss.loadshader, this);
    }

    ViewShaderVertex s = ss;  
    selector2(400, 16, 100, width-16, s, ss.loadshader, this);

  }

  void selector(float xx, float yy, float ww, float hh, ViewShader vs, LoadShader loadshader, PApplet p) {
    p.fill(150);
    p.noStroke();
    p.rectMode(CORNER);

    int cant = loadshader.shadersNames.length;
    p.rect(xx, yy+cant*16, ww, hh-cant*16);
    for (int i = 0; i &lt; cant; i++) {
      boolean sobre = false;
      if (p.mouseX &gt;= xx &amp;&amp; p.mouseX &lt; xx+ww &amp;&amp; p.mouseY &gt;= yy+i*16 &amp;&amp; p.mouseY &lt; yy+(i+1)*16) {
        sobre = true;
      }
      if (sobre) {
        p.fill(125);
      } else {
        p.fill(100, 50);
      }
      boolean selec = vs.src.equals(loadshader.shadersPaths[i]);
      if (p.mousePressed &amp;&amp; sobre &amp;&amp; !selec) {
        vs.newShader(loadshader.shadersPaths[i]);
      }

      if (selec) {
        p.fill(100);
        if (vs.error) {
          p.fill(200, 10, 10);
        }
      }

      p.rect(xx, yy+i*16, ww, 16);
      p.textAlign(LEFT, TOP);
      p.fill(250);
      if (i &lt; loadshader.shadersNames.length &amp;&amp; !load)
        text(loadshader.shadersNames[i], xx+5, yy+i*16);
    }
  }

  void selector2(float xx, float yy, float ww, float hh, ViewShaderVertex vs, LoadShader loadshader, PApplet p) {
    p.fill(150);
    p.noStroke();
    p.rectMode(CORNER);

    int cant = loadshader.shadersNames.length;
    p.rect(xx, yy+cant*16, ww, hh-cant*16);
    for (int i = 0; i &lt; cant; i++) {
      boolean sobre = false;
      if (p.mouseX &gt;= xx &amp;&amp; p.mouseX &lt; xx+ww &amp;&amp; p.mouseY &gt;= yy+i*16 &amp;&amp; p.mouseY &lt; yy+(i+1)*16) {
        sobre = true;
      }
      if (sobre) {
        p.fill(125);
      } else {
        p.fill(100, 50);
      }
      boolean selec = ss.src.equals(loadshader.shadersPaths[i]);
      if (p.mousePressed &amp;&amp; sobre &amp;&amp; !selec) {
        vs.newShader(loadshader.shadersPaths[i]);
      }

      if (selec) {
        p.fill(100);
        if (vs.error) {
          p.fill(200, 10, 10);
        }
      }

      p.rect(xx, yy+i*16, ww, 16);
      p.textAlign(LEFT, TOP);
      p.fill(250);
      if (i &lt; loadshader.shadersNames.length &amp;&amp; !load)
        p.text(loadshader.shadersNames[i], xx+5, yy+i*16);
    }
  }
}

class ViewShaderVertex {

  boolean reload, error, loaded;
  File fileShader;
  long timeModi;
  String src;
  String src2;

  PShader shader;

  float a;
  LoadShader loadshader;
  ViewShader ss;

  ViewShaderVertex(String _src, LoadShader _loadshader, PGraphics b) {

    src = _src;
    fileShader = new File(src);
    openShader(fileShader);

    loadshader = _loadshader;
  }



  void update() {
    if (reload) {      
      openShader(fileShader);
      reload = false;
    }
    if (shader != null) {

      if (fileShader.lastModified() != timeModi) {
        openShader(fileShader);

      }
    }
  }


  void newShader(String src) {
    this.src = src;
    fileShader = new File(src);
    reload = true;
    openShader(fileShader);
  }

  void openShader(File file) {

    if (file != null) {
      fileShader = file;
      timeModi = fileShader.lastModified();

      try {
                for (ViewShader s : vs) {
          s.update();
        }
        //shader = loadShader("test.glsl", file.getAbsolutePath());
        shader.setVertexShader(file.getAbsolutePath());
        buffers[0].shader(shader);

        println(file.getAbsolutePath());
        error = false;
        loaded = true;
      }
      catch (RuntimeException e) {
        if (error == false) {
          error = true;
          // String time = nf(str(hour()),2) + ":" + nf(str(minute()),2) + ":" + nf(str(second()),2);
          println("\n");
          // println("At", time, "loadShader() returned the following error: \n");
          println("loadShader() returned the following error: \n");
          e.printStackTrace();
        }
        loaded = false;
      }
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>multiple window - clone main window</title>
      <link>https://forum.processing.org/two/discussion/28051/multiple-window-clone-main-window</link>
      <pubDate>Mon, 11 Jun 2018 07:57:22 +0000</pubDate>
      <dc:creator>pietroLama</dc:creator>
      <guid isPermaLink="false">28051@/two/discussions</guid>
      <description><![CDATA[<p>hi to all!</p>

<p>i use processing as my principal instrument to do visual live set, and i've the necessity to clone the main window to another to control what is rendering in that moment!</p>

<p>for now i'm using this code:</p>

<pre><code>class PWindow extends PApplet {
  PWindow() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  }

  void settings() {
    size(500, 200);
  }

  void setup() {
    background(150);
  }

  void draw() {
    //here i want to clone the main window
  }

  void mousePressed() {
    println("mousePressed in secondary window");
  }
}


PWindow win;

public void settings() {
  size(320, 240);
}

void setup() { 
  win = new PWindow();
}

void draw() {
  background(255, 0, 0);
  fill(255);
  rect(10, 10, frameCount, 10);
}

void mousePressed() {
  println("mousePressed in primary window");
}  
</code></pre>

<p>is possible do what i ask starting with this?</p>

<p>thank to everyone!!</p>
]]></description>
   </item>
   <item>
      <title>Send value to a object</title>
      <link>https://forum.processing.org/two/discussion/28037/send-value-to-a-object</link>
      <pubDate>Sun, 03 Jun 2018 00:49:55 +0000</pubDate>
      <dc:creator>vjjv</dc:creator>
      <guid isPermaLink="false">28037@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody. I`ve a problem:</p>

<p>I`ve a array of ellipse Objects. Every object has his variable of size in the constructor. In a second screen, via controlP5, a slider that change the size of every ellipse. What i want is change the size of an ellipse object when isClicked is true, and in that particular object, and store that value. But i cant, and i dont know exaclty why. I think that when i change the size in the constructor every object take the same value.</p>

<p>here the code, sorry for my very bad english, hope you understand:</p>

<p>(in resume: click the object, change it value, store the value. click in another object, and change it value (different of object 1)…etc.)</p>

<pre><code>import controlP5.*;

ArrayList&lt;Sphere&gt;s;
PWindow controller;


void settings() {
  size(500, 500, P3D);
}


void setup() {
  controller = new PWindow();

  s = new ArrayList&lt;Sphere&gt;();
  s.add(new Sphere(new PVector(random(width), random(height)), 255, 50, 0));
}

void draw() {
  background(0);
  pushMatrix();
  select();

  for (Sphere s : s) {
    s.display();
    s.isOver(mouseX, mouseY);
  }
  popMatrix();
}

void select() {
  for (Sphere s : s) {
    if (s.isClick) {
      println(s.id, "HOLA");
      s.c = 25;
      println("");
    }
  }
}

void mousePressed() {

  if (mouseButton==RIGHT) s.add(new Sphere(new PVector(mouseX, mouseY), 255, 50, s.size()+1));

  for (Sphere s : s) {
    if (mouseButton==LEFT &amp;&amp; s.over) {
      s.isClick = true;
    } else {
      s.isClick = false;
    }
  }
}

class Sphere {

  float c, size;
  float x, y;
  ArrayList&lt;PVector&gt; p = new ArrayList&lt;PVector&gt;();
  boolean over = false;
  boolean isClick = false;
  int id;
  int initialValue = 50;

  Sphere(PVector pos, float _color, float _size, int _id) {
    p.add(pos);
    c = _color;
    size = _size;
    id = _id;
  }

  void display() {
    for (PVector pos : p) {
      pushMatrix();
      translate(pos.x, pos.y);
      fill(c);  
      ellipse(0, 0, size, size);
      popMatrix();
    }
  }

  boolean isOver(float px, float py) {
    ellipseMode(RADIUS);
    for (PVector pos : p) {
      float d = dist(px, py, pos.x, pos.y);
      if (d &lt; size) {
        over = true;
        c = 150;
        return true;
      } else {
        over = false;
        c = 255;
        return false;
      }
    }
    return false;
  }
}
public class PWindow extends PApplet {  

  PWindow() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  }

  ControlP5 cp5;

  int vertices = 50;
  float ss;


  Slider abc;


  void settings() {
    size(500, 250, P2D);
  }

  void setup() {
    cp5 = new ControlP5(this);
    background(0);


    cp5.addSlider("vertices")
      .setPosition(25, 50)
      .setSize(200, 20)
      .setRange(0, 50)
      ;
  }

  void draw() {
    background(0);

    for (int i = s.size()-1; i &gt;= 0; i--) {
      Sphere obj = s.get(i); 
      ss = vertices;

      if (obj.isClick==true) {
        fill(255);
        stroke(255);
        textSize(13);
        text(i, width/2, 150);
        println(i);
        obj.size = vertices;
      }
    }
  }

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to pick the place in the screen when run the sketch</title>
      <link>https://forum.processing.org/two/discussion/28040/how-to-pick-the-place-in-the-screen-when-run-the-sketch</link>
      <pubDate>Tue, 05 Jun 2018 04:08:27 +0000</pubDate>
      <dc:creator>vjjv</dc:creator>
      <guid isPermaLink="false">28040@/two/discussions</guid>
      <description><![CDATA[<p>hello. at this time when i run my sketch 3 differents windows (PAplets) are opening, to controll different parameters of objects. but all of them open in the same place (the center of the screen), so i need to move it to see it. is there any way to pick the place of the windows when the sketch is ejecute? e.x one next to the other.</p>
]]></description>
   </item>
   <item>
      <title>stream video on second monitor</title>
      <link>https://forum.processing.org/two/discussion/27915/stream-video-on-second-monitor</link>
      <pubDate>Fri, 04 May 2018 16:22:23 +0000</pubDate>
      <dc:creator>secondsky</dc:creator>
      <guid isPermaLink="false">27915@/two/discussions</guid>
      <description><![CDATA[<p>Hi All, i would be able to stream two video on two different monitor, at the same time.
So far this is the code i written to stream one on the secondary monitor, but is not working:</p>

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

final PApplet projector0 = new ProjectorSketch();
final PApplet projector1 = new ProjectorSketch();

void setup() {
  size(300, 300, JAVA2D);
  smooth(4);
  noLoop();
  stroke(-1);

  runSketch(new String[] { "--display=1", "--present",  "--sketch-path=" + sketchPath(), "Projector" }, projector0);

}

void draw() {
  background(0);
}


class ProjectorSketch extends PApplet {
  Movie movie;


 void setup() {

   stroke(#FFFF00);
   movie = new Movie(this, "transit.mov");
  movie.loop();

   }


  public void settings() {
    size(displayWidth, displayHeight, JAVA2D);

  }

  void draw() {

  image(movie, 0, 0, width, height);
  }
}

public void movieEvent(Movie m) {
  m.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>with second applet, strange errors about createGraphics</title>
      <link>https://forum.processing.org/two/discussion/27782/with-second-applet-strange-errors-about-creategraphics</link>
      <pubDate>Tue, 17 Apr 2018 03:23:45 +0000</pubDate>
      <dc:creator>prismspecs</dc:creator>
      <guid isPermaLink="false">27782@/two/discussions</guid>
      <description><![CDATA[<pre><code>PGraphics canvas;

void setup() {
  size(400, 400, P3D);
  canvas = createGraphics(400, 400, P3D);

  String[] args = {"YourSketchNameHere"};
  SecondApplet sa = new SecondApplet();
  PApplet.runSketch(args, sa);
}

void draw() {

  canvas.beginDraw();
  canvas.background(127);
  canvas.lights();
  canvas.translate(width/2, height/2);
  canvas.rotateX(frameCount * 0.01);
  canvas.rotateY(frameCount * 0.01);  
  canvas.box(150);
  canvas.endDraw();
  image(canvas, 0, 0);
}     

public class SecondApplet extends PApplet {

  public void settings() {
    size(200, 100,P3D);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}
</code></pre>

<p>With that code I get "createGraphics() requires size to use P3D or P2D" (paraphrasing)</p>

<p>Or if I try to create an instance of a Syphon window, for example, I get null pointer.</p>

<p>What's the deal? My goal is to create a 2-window app with Syphon output from one window and a P5 control setup on the other.</p>
]]></description>
   </item>
   <item>
      <title>ArrayList - ConcurrentModificationException</title>
      <link>https://forum.processing.org/two/discussion/26815/arraylist-concurrentmodificationexception</link>
      <pubDate>Tue, 13 Mar 2018 21:05:48 +0000</pubDate>
      <dc:creator>vjjv</dc:creator>
      <guid isPermaLink="false">26815@/two/discussions</guid>
      <description><![CDATA[<p>hey, im trying to add Objects into an arrayList that is a part of a class, from a second Papplet,(when the user click the mouse, add a new Obj). But it doesnt work properly, an concurrent modification exception is crashing the sketch:</p>

<p>here the code:</p>

<p>the main scene 3D</p>

<pre><code>System s;
PWindow w;
void settings() {
  s = new System();
  size(500, 500, P3D);

}

void setup() {
  background(0);
  s = new System();
  w = new PWindow();
}

void draw() {
  background(0);
  pushMatrix();
  translate(width/2, height/2);
  s.run();
  popMatrix();
}

class System {
  ArrayList&lt;Obj&gt;o;
  System() {
    o = new ArrayList&lt;Obj&gt;();
  }

  void addObj(float x, float z) {
    o.add(new Obj(new PVector(x, 0, z)));
  }


  void run() {
    for (Obj obj : o) {
      obj.display();
    }
  }

}

class Obj {

  PVector pos;

  Obj(PVector o) {
    pos = o.get();
  }

  void display() {
    pushMatrix();
    translate(pos.x, pos.y, pos.z);
    sphere(100);
    popMatrix();
  }
}
</code></pre>

<p>the second Papplet , when the user click the screen, add a new Obj</p>

<pre><code>    class PWindow extends PApplet {

      PWindow() {
        super();
        PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
      }


      void settings() {
        size(500, 500, P2D);
      }

      void setup() {
      }

      void draw() {
        for(Obj o : s.o){
        ellipse(o.pos.x, o.pos.z, 20, 20);
        }
      }

      void mousePressed(){
      s.addObj(mouseX,mouseY);
      }


    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to add a processing 3 applet to a JFrame</title>
      <link>https://forum.processing.org/two/discussion/16439/how-to-add-a-processing-3-applet-to-a-jframe</link>
      <pubDate>Thu, 05 May 2016 14:02:27 +0000</pubDate>
      <dc:creator>hydrodog</dc:creator>
      <guid isPermaLink="false">16439@/two/discussions</guid>
      <description><![CDATA[<p>It used to be that a processing 2 applet could be added to a JFrame because it was inherited from Applet which inherits from JPanel.  Now it's not.</p>

<p>I see this long discussion: <a href="https://forum.processing.org/two/discussion/12774/embedding-papplet-in-java-jframe" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/12774/embedding-papplet-in-java-jframe</a></p>

<p>but I do not see how to create a JFrame in Java, and add a PApplet as a component.  Particularly important is that the PApplet be able resize when told to do so by the layout manager.</p>

<p>Is there any way to do this without using runSketch?  It's a real hack to have to have the drawing area create the window.</p>
]]></description>
   </item>
   <item>
      <title>everybody... post novelty stuffs here!</title>
      <link>https://forum.processing.org/two/discussion/25779/everybody-post-novelty-stuffs-here</link>
      <pubDate>Mon, 01 Jan 2018 19:41:57 +0000</pubDate>
      <dc:creator>robotman2412</dc:creator>
      <guid isPermaLink="false">25779@/two/discussions</guid>
      <description><![CDATA[<p>Yo. you can put all of your cool little or big projects here.
let's see what you make of it!</p>
]]></description>
   </item>
   <item>
      <title>Second applet and Classes</title>
      <link>https://forum.processing.org/two/discussion/26310/second-applet-and-classes</link>
      <pubDate>Sun, 11 Feb 2018 03:59:46 +0000</pubDate>
      <dc:creator>vjjv</dc:creator>
      <guid isPermaLink="false">26310@/two/discussions</guid>
      <description><![CDATA[<p>Hey, i`ve this simple code:</p>

<pre><code>PWindow w;
Radar r;

void settings() {
  size(500, 500, P3D);
}
void setup() {
  w = new PWindow();
  r = new Radar();
}


void draw() {

  translate(width/2, height/2);
  box(200);
}

class Radar{

Radar(){
}

void display(){
  stroke(255);
  ellipse(width/2, height/2, 100, 100);
}

}

class PWindow extends PApplet {

  PWindow() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);

  }

  void settings() {
    size(500, 500, P2D);
  }

void setup(){
background(0);
}

  void draw(){
  r.display();
  }
}
</code></pre>

<p>but it doesn't work (crash). im really don't know how use a class inside a extra applet.
any suggestion?</p>
]]></description>
   </item>
   <item>
      <title>exit extended PApplet/ second window</title>
      <link>https://forum.processing.org/two/discussion/21813/exit-extended-papplet-second-window</link>
      <pubDate>Wed, 05 Apr 2017 00:28:53 +0000</pubDate>
      <dc:creator>jcunha</dc:creator>
      <guid isPermaLink="false">21813@/two/discussions</guid>
      <description><![CDATA[<p>I'm using processing 3.3. Basically this code opens a save window when "g" is pressed. You type the "name" and and "notes" and click on the save button so it appears on the main window. What I want is to be able to close the second window after clicking "save" and, if possible, when the second window opens i want it to open over the main window and not behind like it's doing. I've searched a lot and all the answers for this kind of problem don't work or the functions suggested are for preview versions of processing. Thank you for all the help</p>

<pre><code>import controlP5.*;
ControlP5 caixas;
String caixa1;
String caixa2;
String texto1;
String texto2;
Save cf;

void settings() {
  size(400,400,P3D);
}

void setup(){
}
void keyPressed() {
  if (key == 'g') {
  cf = new Save(this, 800, 800);
}
}

void draw() {
  background(0);
  text("texto 1: " + texto1 + "\ntexto 2: " + texto2,50,50);
}

class Save extends PApplet {

  int w, h;
  PApplet parent;
  ControlP5 cp5;

  public Save(PApplet _parent, int _w, int _h) {
    super();   
    parent = _parent;
    w=_w;
    h=_h;
    PApplet.runSketch(new String[]{this.getClass().getName()}, this);
  }

  public void settings() {
    size(w,h);
  }

  public void setup() {
  caixas = new ControlP5(this); 

  caixas.addTextfield("Name").setPosition(20, 100).setSize(200, 40);

  caixas.addButton("Save").setPosition(20,60).setSize(100,40);

  caixas.addTextfield("Notes").setPosition(20, 170).setSize(200, 40);

  }

  void draw() {
    background(40);
  }

  public void controlEvent(ControlEvent theEvent) {
    texto1 = caixas.get(Textfield.class,"Nome").getText();
    texto2 = caixas.get(Textfield.class,"Notas").getText();
// HERE THE FUNCTION OR ANYTHING TO MAKE IT CLOSE
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Spoiled the processing((((</title>
      <link>https://forum.processing.org/two/discussion/26152/spoiled-the-processing</link>
      <pubDate>Sun, 28 Jan 2018 15:24:19 +0000</pubDate>
      <dc:creator>Myrad</dc:creator>
      <guid isPermaLink="false">26152@/two/discussions</guid>
      <description><![CDATA[<p>all the good day.</p>

<p>1) why PApplet does not inherit from Fragment ???.</p>

<p>2) how to create PApplet in a new thread ???.</p>

<p>3) I want that at me PApplet it was displayed in View element and in a new flow in half of the screen earlier I could simply make it now neznaju how it to make ???.</p>
]]></description>
   </item>
   <item>
      <title>pop up window</title>
      <link>https://forum.processing.org/two/discussion/17520/pop-up-window</link>
      <pubDate>Wed, 13 Jul 2016 16:51:29 +0000</pubDate>
      <dc:creator>robotman2412</dc:creator>
      <guid isPermaLink="false">17520@/two/discussions</guid>
      <description><![CDATA[<p>hi!
i am trying to make a compiler with processing.
i had wanted to try a pop-up window but all i found on google was useless to me.
do you know a SIMPLE way of making pop-up windows?</p>
]]></description>
   </item>
   <item>
      <title>Can you run a sketch on two screens at the same time?</title>
      <link>https://forum.processing.org/two/discussion/25082/can-you-run-a-sketch-on-two-screens-at-the-same-time</link>
      <pubDate>Sat, 18 Nov 2017 21:14:04 +0000</pubDate>
      <dc:creator>Joar_10_aar</dc:creator>
      <guid isPermaLink="false">25082@/two/discussions</guid>
      <description><![CDATA[<p>Hi!
I want two run my processing sketch at two screens at the same time, is that possible? + I want the sketch to have fullscreen at both screens.</p>
]]></description>
   </item>
   <item>
      <title>Refferancing applets</title>
      <link>https://forum.processing.org/two/discussion/25507/refferancing-applets</link>
      <pubDate>Mon, 11 Dec 2017 08:13:02 +0000</pubDate>
      <dc:creator>LaxOfBayDay</dc:creator>
      <guid isPermaLink="false">25507@/two/discussions</guid>
      <description><![CDATA[<p>If I wanted to write code in one applet's "draw" to display an image in the other, what would I do?</p>

<p>In the situation below, if I move "image(example.get(0),0,0);" to draw and put "sa." or "SecondApplet." in front of it. I get an error that the name isn't recognizable or that I'm mixing static with non-static. How would I refer to the second applet in this case?</p>

<pre><code>ArrayList&lt;PImage&gt; example = new ArrayList&lt;PImage&gt;();

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

  text.add(loadImage("example.png"));

  String[] args = {"TwoFrameTest"};
  SecondApplet sa = new SecondApplet();
  PApplet.runSketch(args, sa);
}

void draw() {
  background(0);
  ellipse(50, 50, 10, 10);

}     

public class SecondApplet extends PApplet {

  public void settings() {
    size(200, 100);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
    //////////
    image(example.get(0),0,0);
    /////////
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Loading images to a second applet?</title>
      <link>https://forum.processing.org/two/discussion/25484/loading-images-to-a-second-applet</link>
      <pubDate>Sun, 10 Dec 2017 01:04:13 +0000</pubDate>
      <dc:creator>LaxOfBayDay</dc:creator>
      <guid isPermaLink="false">25484@/two/discussions</guid>
      <description><![CDATA[<p>I'm creating a program that uses multiple windows.</p>

<p>I finally figured out how to create the second window using the code from <a rel="nofollow" href="https://gist.github.com/atduskgreg/666e46c8408e2a33b09a"><em>here</em>.</a></p>

<p>But when I try to load a picture into it I get a null Pointer exception despite the fact that the image is in the data folder and the named correctly. Any idea why?</p>

<pre><code>//here's the class itself
class PWindow extends PApplet {
   //   PImage[] subs = new PImage[2];
     // String testKey="m";
  PWindow() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);

  }

  void settings() {
    size(1920, 1080);
  }

  void setup() {
    background(150);
      subs[0]=loadImage("test.png");
  }

  void draw() {
    if (keyPressed &amp;&amp; key == testKey.charAt(0)){
    image(subs[0], 0,0);
   println("well it works");
    }
  }

  void mousePressed() {
    println("mousePressed in secondary window");
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can't load image</title>
      <link>https://forum.processing.org/two/discussion/25448/can-t-load-image</link>
      <pubDate>Fri, 08 Dec 2017 05:37:20 +0000</pubDate>
      <dc:creator>LaxOfBayDay</dc:creator>
      <guid isPermaLink="false">25448@/two/discussions</guid>
      <description><![CDATA[<p>So I need to make an app with two windows. I got this code online and it works but I cant load an image into it (the commented out part is mine). Any idea why the app freezes when I try to run it while loading an image?</p>

<blockquote class="Quote">
  <p>class PWindow extends PApplet {
     //   PImage[] subs = new PImage[2];
       // String testKey="m";
    PWindow() {
      super();
      PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  <br />
    }</p>
  
  <p>void settings() {
      size(1920, 1080);
    }</p>
  
  <p>void setup() {
      background(150);
      //  subs[0]=loadImage("test.png");
    }</p>
  
  <p>void draw() {
      //if (keyPressed &amp;&amp; key == testKey.charAt(0)){
     // image(subs[0], 0,0);
     println("well it works");
      //}
    }</p>
  
  <p>void mousePressed() {
      println("mousePressed in secondary window");
    }
  }</p>
</blockquote>
]]></description>
   </item>
   <item>
      <title>second window with PApplet and OscP5?</title>
      <link>https://forum.processing.org/two/discussion/24899/second-window-with-papplet-and-oscp5</link>
      <pubDate>Tue, 07 Nov 2017 16:48:26 +0000</pubDate>
      <dc:creator>jcharney</dc:creator>
      <guid isPermaLink="false">24899@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm trying to control a sketch using OSC from Max using the oscP5 library. I want two screens that have identical "players", differentiated by an argument in their constructor. I'm using the "extends PApplet" function to create the second window.</p>

<p>Each Player needs to see global variables that are updated from Max (as sometimes they need to refer to each other's sensor data). I can't seem to figure out where to put the OSC.plug code to make sure each of them gets updated – only the main window updates right now when I put that code within the main setup(), and it doesn't work if I duplicate that code within the second setup(). Do I need to be duplicating the data I'm sending from Max on a separate port, or is there something else I'm not getting? I'm not sure where I should be initializing the Player classes or OSC assignments.</p>

<p>Example of code below (main project has many more functions within the Player class, ie, more roles).</p>

<pre><code>PWindow win;

import oscP5.*;
import netP5.*;

OscP5 osc0;

NetAddress FromMax;    

float sensor0, sensor1; //receive sensor values from Max

int role0, role1; //change modes

Player Player0, Player1;

public void settings(){
  size(800,600);
}

void setup(){
  win = new PWindow();
  Player0 = new Player(0);
  //set up OSC receives
  osc0 = new OscP5(this, 12000);
  FromMax = new NetAddress("127.0.0.1", 12000);
  osc0.plug(this, "oscrole0", "/role0");
  osc0.plug(this, "oscrole1", "/role1");
  osc0.plug(this, "oscsensor0", "/sensor0");
  osc0.plug(this, "oscsensor1", "/sensor1");
}

////First Window
void draw(){
  Player0.update(role0);
}

///Second Window
class PWindow extends PApplet {

  PWindow() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);

  }

  void settings() {
    size(800,600);
  }

  void setup() {
    Player1 = new Player(1);

  }

  void draw() {
  Player1.update(1);
  }
}
/////Player class - one on each screen.
class Player {

  int role;
  int playerNumber;
  float sensor;

  Player (int tempplayerNumber){
    playerNumber = tempplayerNumber;
  }

//  
  void update(int temprole){

  //update sensor
    if (playerNumber == 0){
      role = role0;
      sensor = sensor0; 
       }
    if (playerNumber == 1){
      role = role1;
      sensor = sensor1;
    }

    if (temprole == -1){
      background(0);
      fill(255);
      text(sensor,width/2,height/2);
    }
    if (temprole == 0){
      background(255);
      fill(0);
      text(sensor,width/2,height/2);
    }

    }
}

//reassign OSC plugs
void oscrole0(int oscrole0) {
  role0 = oscrole0;
}

void oscrole1(int oscrole1) {
  role1 = oscrole1;
}

void oscsensor0(float oscsensor0) {
  sensor0 = oscsensor0;
}

void oscsensor1(float oscsensor1) {
  sensor1 = oscsensor1;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to create another window in one sketch</title>
      <link>https://forum.processing.org/two/discussion/24842/how-to-create-another-window-in-one-sketch</link>
      <pubDate>Wed, 01 Nov 2017 22:34:37 +0000</pubDate>
      <dc:creator>melisaztrk</dc:creator>
      <guid isPermaLink="false">24842@/two/discussions</guid>
      <description><![CDATA[<p>I want to make another sketch window appear, when i clicked to button. Should i use PFrame or PApplet is enough for this. I am confused abut how to do that.</p>
]]></description>
   </item>
   <item>
      <title>Size problem on two window at the same sketch</title>
      <link>https://forum.processing.org/two/discussion/23268/size-problem-on-two-window-at-the-same-sketch</link>
      <pubDate>Fri, 30 Jun 2017 13:55:56 +0000</pubDate>
      <dc:creator>forty69</dc:creator>
      <guid isPermaLink="false">23268@/two/discussions</guid>
      <description><![CDATA[<p>Hi Everyone,</p>

<p>I have written a code that uses the "controlP5" library. The sketch has some sliders and textboxes. The setup function of the sketch has the information about the position of the gui elements.</p>

<p>So, I want to make a simulation. In fact, I did on other sketch, but I got a size problem when I implement the simulation and the code on the same sketch. Let me explain a bit more about the simulation :</p>

<p>I used P3D to apply the coordinates of the shape by using vertex function.</p>

<p>Here is a quick example of what I did so far :</p>

<pre><code>          public class SecondApplet extends PApplet {
          public void settings() {
                size(1000, 600,P3D);
              }
          public void setup() {

            translate(width/2,height/3, -200);
            stroke(255);
            noFill();

            beginShape();

            vertex(-82.27,0,47.5); vertex(0,0,-23.75);
            vertex(82.27,0,47.5); vertex(-82.27,0,47.5);


            vertex(-270,0,0); vertex(-65,397.5,0);
            vertex(32.5,397.5,-56.3); vertex(32.5,397.5,56.3);

            vertex(-65,397.5,0); vertex(32.5,397.5,56.3);
            vertex(135,0,233.827); vertex(82.27,0,47.5);

            vertex(0,0,-23.75); vertex(135,0,-233.827);
            vertex(32.5,397.5,-56.3);
            endShape();
          }
        }

        void setup() {
          size(1000,800);
          frameRate(25);

          controlP5 = new ControlP5(this);
          controlP5.setAutoInitialization(false);

          /* Setups of the gui elements ...
              -----------------------*/

          SecondApplet sa = new SecondApplet();
          String[] args = {"TwoFrameTest"};
          PApplet.runSketch(args, sa);
          updateGuiElements();
        }
</code></pre>

<p>So, the situation is the size problem on the two windows that I wanted to see when I run the sketch. The main window, which is on the "void setup()" section, is smaller than the second window.</p>

<p>I tried to find out the solution, but I couldn't overcome this problem. What I have to do in order to solve this situation ?</p>

<p>( I tried to explain the problem as well as I can).</p>

<p>I am looking forward to your suggestions. Thanks in advanced.</p>

<p>Have a nice works to all..</p>
]]></description>
   </item>
   <item>
      <title>error disabling serialEvent ?</title>
      <link>https://forum.processing.org/two/discussion/23123/error-disabling-serialevent</link>
      <pubDate>Sun, 18 Jun 2017 19:18:37 +0000</pubDate>
      <dc:creator>drocobeth</dc:creator>
      <guid isPermaLink="false">23123@/two/discussions</guid>
      <description><![CDATA[<p>i am trying to talk both way round from processing to arduino as well as from arduino to processing. while processing to arduino link is absolutely fine but i guess it shows the error for arduino to processing and it reads somewhat this:
"error disabling serialEvent() for COM3 null". well i have posted my code below please tell me where i am going wrong.the prime idea is to create a GUI for bluetooth controlled bot and to send feeback from arduino to processing regarding the motor encoder to plot the movement graph(closed loop drive).</p>

<pre><code>processing:
        import processing.serial.*;
        Serial port;
             int index=0;
            String lmotor,rmotor,data,status;
            float lm=0,rm=0,xpos=0,ypos=height;
            void settings()
            {
              size(550,600);
            }
            void setup()
            {
               SecondApplet sa= new SecondApplet();
              String[] args = {"MY Sketch"};
              PApplet.runSketch(args, sa);
              port= new Serial(this, "COM3", 9600);
               port.bufferUntil('.');

        }

        void serialEvent (Serial port)
        {
          println(data);
           data=port.readStringUntil('.');
           data=data.substring(0,data.length()-1);
           index=data.indexOf(",");
           lmotor= data.substring(0, index);
           rmotor= data.substring(index+1 , data.length());
           lm=float(lmotor);
           rm=float(rmotor);
           lm=map(lm,0,9999,0,width);
           rm=map(rm,0,9999,0,height);



        }

        void octagon(int x, int y, int radius)
        {
          float angle= TWO_PI/ 8;
          beginShape();
          for(float a=0; a&lt;TWO_PI; a+= angle)
          {
            float sx= x + cos(a) * radius;
            float sy= y + sin(a) * radius;
            vertex(sx,sy);
          }
          endShape(CLOSE);
        }
        void draw() {
          background(245, 255, 245);
          fill(20 , 160, 133);
          stroke(33);
          strokeWeight(3);
          rect(50, 150, 200, 100, 10);
          rect(300, 150, 200, 100, 10);
          fill(255);
          textSize(34);
          text("FORWARD" , 70,205);
          text("BACKWARD", 305, 205);
          textSize(28);
          fill(33);
          text("CURRENT STATUS:", 180, 300);
          //stop button
          fill(176, 28, 46);
          octagon(60,60, 50);
          fill(255);
          rect(30,50,60,17);
          textSize(24);
          fill(33);
          text("STOP", 30,135);
          //left arrow
           ellipseMode(CORNER);
          fill(255,77,0);
          ellipse(35,440,220,120);
          fill(255);
          beginShape();
          {
            vertex(40, 500);
            vertex(100, 450);
            vertex(100, 475 );
            vertex(240,475 );
            vertex(240,525);
            vertex(100, 525);
            vertex(100,550);
          }
          endShape(CLOSE);
           // right arrow
           ellipseMode(CORNER);
           fill(255,77,0);
           ellipse(295,440,220,120);
           fill(255);
           beginShape();
          {
            vertex(510, 500);
            vertex(450, 450);
            vertex(450, 475 );
            vertex(310,475 );
            vertex(310,525);
            vertex(450, 525);
            vertex(450,550);
          }
          endShape(CLOSE);
          if(mousePressed &amp;&amp; mouseX&gt;10 &amp;&amp; mouseX&lt;110 &amp;&amp; mouseY&gt;10 &amp;&amp; mouseY&lt;110)
          {
             port.write('0');
             stroke(255,0,0);
            strokeWeight(2);
            noFill();
            octagon(60,60, 50);
            status="STOP";
          }
          if(mousePressed &amp;&amp; mouseX&gt;50 &amp;&amp; mouseX&lt;250 &amp;&amp; mouseY&gt;150 &amp;&amp; mouseY&lt;250)
          {
            port.write('F');
             stroke(255,0,0);
            strokeWeight(2);
            fill(255);
            rect(50,150,200,100,10);
            status="FORWARD";
            }
           if(mousePressed &amp;&amp; mouseX&gt;300 &amp;&amp; mouseX&lt;500 &amp;&amp; mouseY&gt;150 &amp;&amp; mouseY&lt;250)
          {
             port.write('B');
             stroke(255,0,0);
            strokeWeight(2);
            fill(255);
            rect(300,150,200,100,10);
            status="BACKWARD";
          }
           if(mousePressed &amp;&amp; mouseX&gt;35 &amp;&amp; mouseX&lt;255 &amp;&amp; mouseY&gt;440 &amp;&amp; mouseY&lt;560)
          {
              port.write('L');
             stroke(255,0,0);
            strokeWeight(2); 
           ellipseMode(CORNER);
             fill(255);
          ellipse(35,440,220,120);  
          status="LEFT";
         }
           if(mousePressed &amp;&amp; mouseX&gt;295 &amp;&amp; mouseX&lt;515 &amp;&amp; mouseY&gt;440 &amp;&amp; mouseY&lt;560)
          {
             port.write('R');
             stroke(255,0,0);
            strokeWeight(2); 
           ellipseMode(CORNER);
             fill(255);
         ellipse(295,440,220,120);
         status="RIGHT";
         }
          if(status=="FORWARD")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,140,380);
          }
          if(status=="BACKWARD")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,120,380);
          }
          if(status=="RIGHT")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,200,380);
          }
          if(status=="LEFT")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,230,380);
          }
          if(status=="STOP")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,210,380);
          }



        }
        public class SecondApplet extends PApplet {




          public void settings() {
            size(550, 600);
          }
          public void setup()
          {
            background(0);
          }
          public void draw()
          {
             stroke(255);
          strokeWeight(5);
           line(xpos,ypos,lm,height-rm);
          xpos=lm;
          ypos=height-rm;
          if(lm&gt;=width-1)
          {
            xpos=0;
            lm=0;
            background(0);
          }
          if(rm&gt;=height-1)
          {
            ypos=0;
            rm=0;
            background(0);
          }



      }
    }
</code></pre>

<p>arduino code:
        #include &lt;avr/io.h&gt;
        #include &lt;util/delay.h&gt;</p>

<pre><code>#define SETBIT(ADDRESS, BIT) (ADDRESS|=(1&lt;&lt;BIT));
#define CLEARBIT(ADDRESS, BIT) (ADDRESS&amp;=~(1&lt;&lt;BIT));
#define CHECKBIT(ADDRESS, BIT) (ADDRESS &amp; (1&lt;&lt;BIT));
char val,c;
int sfl=0,sfr=0,temp,y=0;

void interrupt_init()
{
  cli();
  EIMSK=0x03;
  EICRA=0x0A;
  sei();

}
void encoder_pin_config_init()
{
  DDRD=DDRD &amp; 0xF3;
  //INTERNALPULLUPS
  SETBIT(PORTD, PD3);
  SETBIT(PORTD, PD2);
}
void byte_init (int baud)
{
    UBRR0H = (baud&gt;&gt;8);                      // shift the register right by 8 bits
    UBRR0L = baud;                           // set baud rate
    UCSR0B|= (1&lt;&lt;TXEN0)|(1&lt;&lt;RXEN0);                // enable receiver and transmitter
    UCSR0C|= (1&lt;&lt;UCSZ00)|(1&lt;&lt;UCSZ01);   // 8bit data format
}
void byte_transmit (unsigned char data)
{
    while (!( UCSR0A &amp; (1&lt;&lt;UDRE0)));                // wait while register is free
    UDR0 = data;                                   // load data in the register
}
unsigned char byte_receive (void)
{
    while(!(UCSR0A) &amp; (1&lt;&lt;RXC0));                   // wait while data is being received
    return UDR0;                                   // return 8-bit data
}


int main(void)
{
  byte_init(103);
  interrupt_init();
  encoder_pin_config_init();
  DDRB = (1&lt;&lt;PB1) | (1&lt;&lt;PB2); // PWM pins &amp;&amp; Enable pins
DDRD = (1&lt;&lt;PD4) | (1&lt;&lt;PD5) | (1&lt;&lt;PD6) | (1&lt;&lt;PD7) ; //Motor Pins

SETBIT(PORTB, PB1);
SETBIT(PORTB,PB2);
while(1)
{
val=byte_receive();
if(val=='0')
{
  Stop();
}
if(val=='F')
{
  Forward();
}
if(val=='B')
{
  Backward();
}
if(val=='R')
{
  right();
} 
if(val=='L')
{
  left();
}
temp=sfl;
while(temp&gt;0)
{
  y=temp%10;
  c=y+'0';
  byte_transmit(c);
  temp=temp/10;

}
temp=sfr;
while(temp&gt;0)
{
  y=temp%10;
  c=y+'0';
  byte_transmit(c);
  temp=temp/10;
}
byte_transmit('.');
if(sfl==9999)
{
  sfl=0;
}
if(sfr==9999)
{
  sfr=0;
}
}

}
void Stop()
{
  CLEARBIT(PORTD,PD4);
  CLEARBIT(PORTD, PD5);
  CLEARBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD7);
}
void Forward()
{
  SETBIT(PORTD, PD4);
  CLEARBIT(PORTD, PD5);
  SETBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD7);
}
void Backward()
{
  SETBIT(PORTD, PD5);
  CLEARBIT(PORTD, PD4);
  SETBIT(PORTD, PD7);
  CLEARBIT(PORTD, PD6);
}
void left()
{
  CLEARBIT(PORTD, PD4);
  CLEARBIT(PORTD, PD5);
  SETBIT(PORTD, PD7);
  CLEARBIT(PORTD, PD6);
}

    void right()
    {
  SETBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD4);
  CLEARBIT(PORTD, PD5);
}

ISR(INT0_vect)
{
  sfl++;
}
ISR(INT1_vect)
{
  sfr++;
}`
</code></pre>
]]></description>
   </item>
   <item>
      <title>Opening a new P3D window from a 2d main window</title>
      <link>https://forum.processing.org/two/discussion/18419/opening-a-new-p3d-window-from-a-2d-main-window</link>
      <pubDate>Wed, 05 Oct 2016 14:42:21 +0000</pubDate>
      <dc:creator>mala</dc:creator>
      <guid isPermaLink="false">18419@/two/discussions</guid>
      <description><![CDATA[<p>The main part of my sketch is a control window with 4 tabs all consisting of CP5 sliders and buttons, I  also have a separate 3D view window using Proscene which the user interacts with.
Each of these elements I have working on thier own, i.e. if I just have a sketch with the (2D) Control window all works fine, If I have a sketch with just the 3D view interactive view then that works fine.</p>

<p>The problem is combining the two, I can't seem to find the correct way to "start up" the second window which is the P3D window. 
Are there any simple examples anywhere that show this sort of multi window mixed 2d and 3d setup ? 
I have tried to follow the ControlP5Frame example, whilst that kind of works in that it draws my controls, none of the functions connected to those controls continue to work.
Sure I'm missing something very basic here :)</p>
]]></description>
   </item>
   <item>
      <title>How can I detect a custom event while the draw method is still running?(See Description)</title>
      <link>https://forum.processing.org/two/discussion/22007/how-can-i-detect-a-custom-event-while-the-draw-method-is-still-running-see-description</link>
      <pubDate>Sat, 15 Apr 2017 07:18:19 +0000</pubDate>
      <dc:creator>mezbah</dc:creator>
      <guid isPermaLink="false">22007@/two/discussions</guid>
      <description><![CDATA[<p>I am using processing 2.2.1 with minim and writing code in java with netbeans. I have a situation where my processing sketch is running that means the draw method is running. While it is running an event is triggered by other class. For that I wrote a custom event handler and registered it in the class which is running the sketch..But the class is unable to detect the event..Any help..TIA</p>
]]></description>
   </item>
   <item>
      <title>Exit sketch but preserve parent process</title>
      <link>https://forum.processing.org/two/discussion/13467/exit-sketch-but-preserve-parent-process</link>
      <pubDate>Tue, 10 Nov 2015 11:54:38 +0000</pubDate>
      <dc:creator>munkey</dc:creator>
      <guid isPermaLink="false">13467@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
Im new to processing and I have just got started using it with java. At the minute I have a java swing application which spawns a separate sketch window using PApplet.runSketch(). When the window is closed either by pressing escape, pressing the X or calling .exit() on the PApplet, the entire program including the swing main program closes with it.</p>

<p>Is there a way I can make it so when sketch is closed it does not kill off my entire program and just closes the sketch window?</p>

<p>Thanks.</p>
]]></description>
   </item>
   <item>
      <title>Close second window and reopen example.</title>
      <link>https://forum.processing.org/two/discussion/21331/close-second-window-and-reopen-example</link>
      <pubDate>Sat, 11 Mar 2017 11:23:03 +0000</pubDate>
      <dc:creator>jas0501</dc:creator>
      <guid isPermaLink="false">21331@/two/discussions</guid>
      <description><![CDATA[<p>I couldn't find any examples showing 2nd window close without exiting the first. Using <strong><code>exitActual()</code></strong> seems to do the trick. Any comments on this approach versus some alternative?</p>

<p>Note <code>settings()</code> is needed to correctly set the <code>size(500, 500)</code> of the first window. Also  <code>mousePressed()</code> is used to reopen the window.</p>

<pre><code>boolean frame2Exit;
String[] args = {"TwoFrameTest"};
SecondApplet sa;

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

void draw() {
  background(0);
  ellipse(50, 50, 10, 10);
}     

void mousePressed() {    
  if (frame2Exit)
  {
    frame2Start();
  }
}
void frame2Start() {
  sa = new SecondApplet();
  PApplet.runSketch(args, sa);
  frame2Exit = false;
}

public class SecondApplet extends PApplet {

  public void settings() {
    size(300, 300);
   }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
  public void exitActual() {
    frame2Exit = true; 
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>thread vs papplet.runsketch</title>
      <link>https://forum.processing.org/two/discussion/20898/thread-vs-papplet-runsketch</link>
      <pubDate>Mon, 20 Feb 2017 12:44:19 +0000</pubDate>
      <dc:creator>secondsky</dc:creator>
      <guid isPermaLink="false">20898@/two/discussions</guid>
      <description><![CDATA[<p>Hi all, sorry if the question sounds silly, but I noticed that if I put someting in the PApplet.runsketch() extended void draw(), it works as a parallel thread.
Does the second frame means having a multithreading applet?
Thank you</p>
]]></description>
   </item>
   <item>
      <title>"Could not run the sketch (Target VM failed to initialize)."</title>
      <link>https://forum.processing.org/two/discussion/20398/could-not-run-the-sketch-target-vm-failed-to-initialize</link>
      <pubDate>Sat, 21 Jan 2017 19:04:37 +0000</pubDate>
      <dc:creator>drewhamilton</dc:creator>
      <guid isPermaLink="false">20398@/two/discussions</guid>
      <description><![CDATA[<p>Hi All,
   I've been writing a program for projection mapping. I'm using PApplet.runSketch to run a program for each projector I have attached. Everything was working fantastically well for about a month, but just recently I started getting the error: "Could not run the sketch (Target VM failed to initialize)." Most of the changes I've made to the code recently are pretty simple little methods for scaling objects etc. I haven't fiddled much with how the Applets themselves are loaded etc.</p>

<p>If it is relevant, the sketch uses the following libraries:
        import deadpixel.keystone.*;
        import java.util.*;
        import controlP5.*;
        import processing.video.*;
        import spout.*;
        import javax.swing.JFileChooser;
        import point2line.*;</p>

<p>I would post the entire code, but it is really quite long.</p>

<p>Interestingly, things work fine for a second; the error usually occurs around 45 seconds to 2 minutes into running the sketch, at which point it crashes and dumps the following information:</p>

<p>_#</p>

<h1>A fatal error has been detected by the Java Runtime Environment:</h1>

<p>#</p>

<h1>EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007fff26083def, pid=12912, tid=0x000000000000341c</h1>

<p>#</p>

<h1>JRE version: Java(TM) SE Runtime Environment (8.0_102-b14) (build 1.8.0_102-b14)</h1>

<h1>Java VM: Java HotSpot(TM) 64-Bit Server VM (25.102-b14 mixed mode windows-amd64 compressed oops)</h1>

<h1>Problematic frame:</h1>

<h1>C  [msvcrt.dll+0x73def]</h1>

<p>#</p>

<h1>Failed to write core dump. Minidumps are not enabled by default on client versions of Windows</h1>

<p>#</p>

<h1>An error report file with more information is saved as:</h1>

<h1>C:\Users\DREWHA~1\AppData\Local\Temp&#92;hs_err_pid12912.log</h1>

<p>#</p>

<h1>If you would like to submit a bug report, please visit:</h1>

<h1><a href="http://bugreport.java.com/bugreport/crash.jsp" target="_blank" rel="nofollow">http://bugreport.java.com/bugreport/crash.jsp</a></h1>

<h1>The crash happened outside the Java Virtual Machine in native code.</h1>

<h1>See problematic frame for where to report the bug.</h1>

<p>#
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting._</p>
]]></description>
   </item>
   <item>
      <title>How can I control my particles in one window from another window via the mouse?</title>
      <link>https://forum.processing.org/two/discussion/19895/how-can-i-control-my-particles-in-one-window-from-another-window-via-the-mouse</link>
      <pubDate>Sat, 24 Dec 2016 02:10:25 +0000</pubDate>
      <dc:creator>slow_izzm</dc:creator>
      <guid isPermaLink="false">19895@/two/discussions</guid>
      <description><![CDATA[<p>I am not sure if I am missing something specific to the toxi library, but I keep getting a <strong>ConcurrentModificationException</strong> when I try to control my particles in my secondary window via the mouse in my primary window. The crash seems to be random, sometimes it crashes on one click, sometimes I can drag the particles around for a second or two either way I can;t seem to figure it out. Can anyone help, please?</p>

<pre><code>Particles p;
AttractionBehavior mouseAttractorP;
Vec2D mousePos;
FinalPanel tp;

void setup() {
  size(1024, 768, P3D);
  frameRate(60);
  tp = new FinalPanel(400,400);
  surface.setTitle("Touch Panel");

}

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



void mousePressed() {
  mousePos = new Vec2D(mouseX, mouseY);

  if (mouseButton == LEFT) {
    // create a new attraction force field around the mouse position
    mouseAttractorP = new AttractionBehavior(mousePos, 250, 7);
    p.physics.addBehavior(mouseAttractorP);
  }

  if (mouseButton == RIGHT) {
    // create a new repulsion force field around the mouse position
    mouseAttractorP = new AttractionBehavior(mousePos, -33, -1);
    p.physics.addBehavior(mouseAttractorP);
  }
}

void mouseDragged() {
  // update mouse attraction focal point
  mousePos.set(mouseX, mouseY);
}

void mouseReleased() {
  // remove the mouse attraction when button has been released
  p.physics.removeBehavior(mouseAttractorP);
}


import toxi.geom.*;
import toxi.physics2d.*;
import toxi.physics2d.behaviors.*;
import toxi.math.*;
import megamu.mesh.*;



class Particles {
  final PApplet g;
  int NUM_PARTICLES;
  VerletPhysics2D physics;
  AttractionBehavior mouseAttractor;
  float [][] pos;
  float eSize;
  float xOff;

  Delaunay delaunay;
  int [] polygons;


  Particles(PApplet _p) {
    g = _p;
    xOff = 0;


    NUM_PARTICLES = 666;
    eSize = 1;
    physics = new VerletPhysics2D();
    physics.setDrag(0.7);
    physics.setWorldBounds(new Rect(0, 0, width, height));
    physics.addBehavior(new GravityBehavior(new Vec2D(-0.00007, -0.0003f)));
    for (int i = 0; i&lt;NUM_PARTICLES; i++) {
      addParticle();
    }
  }


  void addParticle() {
    VerletParticle2D p = new VerletParticle2D(Vec2D.randomVector().scale(133).addSelf(width / 2, height/2));
    physics.addParticle(p);
    // add a negative attraction force field around the new particle
    physics.addBehavior(new AttractionBehavior(p, 13, 0.3f, 3f));
  }

  void drawParticles() {
    // store particles delaunayitions to do delaunay triangulation
    pos = new float[NUM_PARTICLES][2];

    for ( int i=0; i&lt;NUM_PARTICLES; i++) {
      // particle system using verlet integration
      VerletParticle2D p = physics.particles.get(i);
      g.pushStyle();
      g.fill(255, 33);
      g.ellipse(p.x, p.y, g.noise(xOff) * 13, g.noise(xOff) * 13);
      g.popStyle();

      pos[i][0] = physics.particles.get(i).x;
      pos[i][1] = physics.particles.get(i).y;
    }
  }


  // delaunay triangulation logic taken from here : 
  // <a href="http://www.openprocessing.org/sketch/43503" target="_blank" rel="nofollow">http://www.openprocessing.org/sketch/43503</a>
  void drawLines() {
    // delaunay triangulation
    delaunay = new Delaunay(pos);
    // getEdges returns a 2 dimensional array for the lines
    float[][] edges = delaunay.getEdges();
    for (int i=0; i&lt;edges.length; i++)
    {
      // use the edges values to draw the lines
      float startX = edges[i][0];
      float startY = edges[i][1];
      float endX = edges[i][2];
      float endY = edges[i][3];
      float distance = dist(startX, startY, endX, endY);
      // remap the distance to opacity values
      float trans = 255-map(distance, 0, 33, 33, 0);
      // stroke weight based on distance
      // fast invert square root helps for performance
      float sw = 3f/sqrt(distance*2);
      g.ellipseMode(CENTER);

      g.pushStyle();
      g.strokeWeight(sw);
      g.stroke(g.noise(1)*233);
      g.fill(g.random(255), g.random(255), g.random(255));
      g.noFill();
      g.ellipse(startX, startY, eSize, eSize);
      g.popStyle();
      //pushStyle();
      //stroke(200, 3);
      //noFill();
      //bezier(startX, startY, endX, mouseY, width/2, mouseY, width/2, height/2);
      //popStyle();
    }
  }
}



class FinalPanel extends PApplet {
  int w, h;

  public FinalPanel(int _w, int _h) {
    super(); 
    w = _w;
    h = _h;
    PApplet.runSketch(new String[]{this.getClass().getName()}, this);
  }

  public void settings() {
    size(w, h, P3D);
  }

  public void setup() {
    blendMode(ADD);
    surface.setTitle("Final Panel");
    surface.setLocation(0, 0);
    p = new Particles(this);
  }

  void draw() {
    background(0);
    p.physics.update();
    p.drawParticles();
    p.drawLines();
  }
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>