<?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 #help - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23help</link>
      <pubDate>Sun, 08 Aug 2021 20:35:54 +0000</pubDate>
         <description>Tagged with #help - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23help/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>I need to know how to make dice with dots and randomly roll the dice.</title>
      <link>https://forum.processing.org/two/discussion/24780/i-need-to-know-how-to-make-dice-with-dots-and-randomly-roll-the-dice</link>
      <pubDate>Sat, 28 Oct 2017 18:34:34 +0000</pubDate>
      <dc:creator>coding94</dc:creator>
      <guid isPermaLink="false">24780@/two/discussions</guid>
      <description><![CDATA[<pre><code>boolean a = false;
boolean b = false;
boolean c= false;
boolean d= false;
boolean e=false;
int di1 = 0;
int di2 = 0;

void setup() {
  size(800, 800);
  textSize(17);
}
void draw() {
  background(0, 255, 255);
  fill(0, 0, 0);
  text("Chō-Han", 400, 100);
  text("Instructions:", 400, 150);
  text("1. There are two die. Click to roll and receive a random number between 1 and 6 per dice.", 400, 200);
  text("2. To win, predict whether the sum of the two numbers will be even or odd.", 400, 250);
  fill(255, 255, 255);
  rectMode(CENTER);
  rect(400, 600, 200, 100);
  fill(0, 0, 0);
  textAlign(CENTER);
  text("START", 400, 600);
  if (a ==true) {
    background(150, 0, 255);
    rect(300, 400, 100, 100);
    rect(500, 400, 100, 100);
    fill(255, 255, 255);
    text("even", 300, 400);
    text("odd", 500, 400);
  }
  if (b == true) {
    background (0, 150, 255);
    fill (255, 255, 255);
    rect (150, 150, 200, 200);
    rect (650, 150, 200, 200);
  }
  if (c==true) {
    background (0, 0, 255);
    fill (255, 255, 255);
    rect (150, 550, 200, 200);
    rect (650, 550, 200, 200);
  }
  if (d==true) {
    rectMode(CENTER);
    rect(400, 400, 100, 100);
    fill(0, 0, 0);
    textSize (20);
    text ("Roll", 400, 400);
    text (di1 + "and " + di2, 700, 100);
  }
  if (b== true &amp;&amp; a== false &amp;&amp; (di1 +di2) % 2 == 0) {
    text("You Win", 400, 600);
  }
   else{
    text( "You Lose", 400, 600);
  }
}


void mouseClicked() {
  if (a == false &amp;&amp; b == false &amp;&amp; mouseX&gt;300 &amp;&amp; mouseX&lt;500 &amp;&amp; mouseY&gt;550 &amp;&amp; mouseY&lt;650) {
    a=true;
  }
  if (a == true &amp;&amp; b == false &amp;&amp; mouseX&gt;250 &amp;&amp; mouseX&lt;350 &amp;&amp; mouseY&gt;350 &amp;&amp; mouseY&lt;450) {
    b =true;
    a = false;
    //true
  }
  if (a== true &amp;&amp; b==false &amp;&amp; c==false &amp;&amp;mouseX&gt;450 &amp;&amp; mouseX&lt;550 &amp;&amp; mouseY&gt;350 &amp;&amp; mouseY&lt;450) {
    b=false;
    a =false;
    c=true;
    //false
  }
  if (b==true || c==true) {
    d= true;
  }
  if (mouseX&gt;350 &amp;&amp; mouseX&lt;450 &amp;&amp; mouseY&gt;350 &amp;&amp; mouseY&lt;450) {
    e=true;
    di1 = floor(random(1, 7));
    di2 = floor (random(1, 7));
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Capacitive Sensor Within Processing</title>
      <link>https://forum.processing.org/two/discussion/21205/capacitive-sensor-within-processing</link>
      <pubDate>Mon, 06 Mar 2017 18:44:13 +0000</pubDate>
      <dc:creator>harrisonh555</dc:creator>
      <guid isPermaLink="false">21205@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I'm novice at using Processing.</p>

<p>In my code I want to change the background to white when the capacitive sensor is held down, and then back to black when the sensor is released.</p>

<p>I have attempted at writing this code in both capacitive sensor code in Arduino, however when I run my code in Processing nothing is shown or changes.</p>

<p>Any help would be greatly appreciated.</p>

<p>MY ARDUINO CODE IS BELLOW</p>

<pre><code>#include &lt;CapacitiveSensor.h&gt;

CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);             

void setup(){

  cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     
  Serial.begin(9600);
}

void loop(){

  long start = millis();
  long total1 =  cs_4_2.capacitiveSensor(30);

  Serial.println(total1); 
  Serial.print(",");                

  delay(10);                              
}
</code></pre>

<p>MY PROCESSING CODE IS BELLOW</p>

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

int touch1Value = 0;

int threshold = 30;

Serial myPort;

void setup(){

  size (500,500);

  myPort = new Serial(this, Serial.list()[1], 9600);

  myPort.bufferUntil('\n');
}

void draw(){

  background (0);

  println("touch1Value:"+touch1Value);

  if (touch1Value == 1){

    background (255,255,255);
  }
}

void serialEvent(Serial myPort){

  String inString = myPort.readStringUntil('\n');

  if (inString != null){

    inString = trim (inString);

    float[] touches = float (split(inString, ","));

    if (touches.length &gt;=1){

      touch1Value = touches[0] &gt;= threshold ? 1: 0;
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Could someone help me with my tetris game?</title>
      <link>https://forum.processing.org/two/discussion/19506/could-someone-help-me-with-my-tetris-game</link>
      <pubDate>Sun, 04 Dec 2016 15:32:57 +0000</pubDate>
      <dc:creator>Rophi</dc:creator>
      <guid isPermaLink="false">19506@/two/discussions</guid>
      <description><![CDATA[<p>I fixed the problem myself now, don't need help anymore. (Don't know hot to delete it)</p>
]]></description>
   </item>
   <item>
      <title>Treating each circle separate</title>
      <link>https://forum.processing.org/two/discussion/11159/treating-each-circle-separate</link>
      <pubDate>Thu, 04 Jun 2015 21:05:06 +0000</pubDate>
      <dc:creator>J_LAM</dc:creator>
      <guid isPermaLink="false">11159@/two/discussions</guid>
      <description><![CDATA[<pre><code>    float dotx , dotx2 , dotx3;
    float doty;
    float dspeed, dspeed2, dspeed3; 
    void setup(){
      size(600,600);
      background(255);
      frameRate(40);
      dotx = 0;
      dotx2 = 0;
      dotx3 = 0;
      dspeed = random(6, 10);
      dspeed2 = random(7, 11);
      dspeed3 = random(6, 10);
      doty = height/2;
    }
    void draw(){
      background(255);
      fill(#FF56AA);
      ellipse(dotx,doty+125, 50,50);
      ellipse(dotx,doty, 50,50);
      ellipse(dotx,doty-140, 50,50);
      if (dotx &gt;= width || dotx &lt; 0){
        dspeed = -dspeed;
      }
      if (dotx2 &gt;= width || dotx &lt;0){
        dspeed2 = -dspeed2;
      }  
      if (dotx3 &gt;= width || dotx &lt;0){
        dspeed3 = -dspeed3;
      }  
      dotx = dotx + dspeed;
    }
</code></pre>

<p>How can I make these circles move as individual functions? I tried using different variables for each circle, and still no good!</p>
]]></description>
   </item>
   <item>
      <title>Make a clock</title>
      <link>https://forum.processing.org/two/discussion/10736/make-a-clock</link>
      <pubDate>Sun, 10 May 2015 17:39:46 +0000</pubDate>
      <dc:creator>angelfire101</dc:creator>
      <guid isPermaLink="false">10736@/two/discussions</guid>
      <description><![CDATA[<p>Make a clock face consisting on a big white circle. Give it just one hand, the "seconds" hand. Make it a black line. Make it tick in the way a seconds hand ticks. Number the 12, 3, 6 and 9 points on your clock. Don't worry about the minutes and hours hands.</p>
]]></description>
   </item>
   <item>
      <title>Problem with trails</title>
      <link>https://forum.processing.org/two/discussion/10722/problem-with-trails</link>
      <pubDate>Sat, 09 May 2015 18:28:28 +0000</pubDate>
      <dc:creator>gustavo_hitscherich</dc:creator>
      <guid isPermaLink="false">10722@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, I am new at Processing. The question is that I have a homework and I have been given some code and asked to finished by creating a ball wich leaves a trail while moving. I have been trying for days without success. I will be really glad if someone can help me. It is supposed that from two classes I have to call a fucntion in the main program. I will leave here the code that I have been given. I hope someone can help me!! Thanks in advance!!</p>

<p>----------main program (dont trust in what is inside, it have been the result os my attempts)-------------------------</p>

<pre><code>float x;
float y;
Trail trail = new Trail();
Trails trails = new Trails();
PVector startPoint;



void setup() {

  size(500, 500);

  for (int i = 0; i &lt; trail.trailSize; i++) {  
     trails.Trails();
  }
}

void draw() {
  background(255);
  ellipse(x, y, 50, 50);



  if (mousePressed) {

    for (int i = 0; i &lt; trails.maxTrails; i++) {
      trails.drawTrails();
    }
    x = mouseX;
    y = mouseY;
  }
}
</code></pre>

<p>------------------first class-----------------------------------------</p>

<pre><code>class Trail {
  final int DEAD = 0;
  final int ALIVE = 1;
  final int ZOMBIE = 2;

  ArrayList&lt;PVector&gt; aTrail;
  color trailColor;
  int state;
  int tnumber;

  int trailSize = 1000;
  int totalTrails = 0;

  Trail() {
    aTrail = new ArrayList&lt;PVector&gt;(trailSize);
    trailColor = #6F480D;
    state = DEAD;
    tnumber = totalTrails + 1;
    totalTrails++;
  }

  int getTrailNumber() {
    return tnumber;
  }

  void addPointTrail(PVector p) {
    if (aTrail.size() &gt; trailSize)
      aTrail.remove(0);
    aTrail.add(p);
  }

  void setColorTrail(color c) {
    trailColor = c;
  }

  void drawTrail() {
    float shade;

    if (aTrail.size() &gt; 1) {
      shade = 256.0 / aTrail.size();
      for (int i=0; i &lt; aTrail.size ()-1; i++) {
        strokeWeight(10);
        stroke(trailColor, shade*(i+1) );
        line(aTrail.get(i).x, aTrail.get(i).y, aTrail.get(i+1).x, aTrail.get(i+1).y);
      }
    }
  }

  void reduceTrail() {
    aTrail.remove(0);
    if (aTrail.size() == 0) setDeadTrail();
  }

  void setAliveTrail() {
    state = ALIVE;
  }

  void setDeadTrail() {
    state = DEAD;
  }

  void setZombieTrail() {
    state = ZOMBIE;
  }

  boolean isZombie() {
    return state == ZOMBIE;
  }

  boolean isDead() {
    return state == DEAD;
  }
}
</code></pre>

<p>---------- and the other class given is -------------------------------</p>

<pre><code>class Trails {
  int maxTrails = 1000;
  ArrayList&lt;Trail&gt; aTrails;

  Trails() {
    aTrails = new ArrayList&lt;Trail&gt;(maxTrails);
  }

  int newTrail(PVector startPoint, color c) {
    Trail t = new Trail();

    aTrails.add(t);
    t.setColorTrail(c);
    t.addPointTrail(startPoint);
    t.setAliveTrail();
    return t.getTrailNumber();
  }

  void drawTrails() {
    Trail t;
    for (int i = 0; i &lt; aTrails.size (); i++) {
      t = aTrails.get(i);
      t.drawTrail();
      if (t.isZombie()) t.reduceTrail();
      if (t.isDead()) aTrails.remove(i);
    }
  }

  void setZombieTrail(int tn) {
    Trail t;
    int i = 0;
    boolean found = false;

    t = aTrails.get(0);
    while ( i &lt; aTrails.size() || !found) {
      t = aTrails.get(i);
      found = (t.getTrailNumber() == tn);
      i++;
    }

    t.setZombieTrail();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do I make these objects loop?</title>
      <link>https://forum.processing.org/two/discussion/10693/how-do-i-make-these-objects-loop</link>
      <pubDate>Thu, 07 May 2015 19:11:19 +0000</pubDate>
      <dc:creator>AlfieChillar</dc:creator>
      <guid isPermaLink="false">10693@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I am currently working on a simple sketch of a piano keyboard moving infinitely across the screen. I've plotted the keys, and using xPos I've made them all move across screen together. I've put a line saying that if xPos is less than -70 (off screen) it should then become 1860 (just off screen on the right but ready to move back on screen), but when I do this it moves all of the objects off screen to the right.</p>

<p>I sort of understand what I'm doing wrong, but I don't know how to fix it. What should I do?</p>

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

<pre><code>int xPos=0;

void setup(){
  size(1800, 900);
  background(194, 237, 222);
}

void draw(){
  background(194, 237, 222);

  xPos=xPos-1;

  noStroke();
  fill(255, 100);

  rect (xPos-40, 10, 50, 200);
  rect (xPos+20, 10, 50, 200);
  rect (xPos+80, 10, 50, 200);
  rect (xPos+140, 10, 50, 200);
  rect (xPos+200, 10, 50, 200);
  rect (xPos+260, 10, 50, 200);
  rect (xPos+320, 10, 50, 200);
  rect (xPos+380, 10, 50, 200);
  rect (xPos+440, 10, 50, 200);
  rect (xPos+500, 10, 50, 200);
  rect (xPos+560, 10, 50, 200);
  rect (xPos+620, 10, 50, 200);
  rect (xPos+680, 10, 50, 200);
  rect (xPos+740, 10, 50, 200);
  rect (xPos+800, 10, 50, 200);
  rect (xPos+860, 10, 50, 200);
  rect (xPos+920, 10, 50, 200);
  rect (xPos+980, 10, 50, 200);
  rect (xPos+1040, 10, 50, 200);
  rect (xPos+1100, 10, 50, 200);
  rect (xPos+1160, 10, 50, 200);
  rect (xPos+1220, 10, 50, 200);
  rect (xPos+1280, 10, 50, 200);
  rect (xPos+1340, 10, 50, 200);
  rect (xPos+1400, 10, 50, 200);
  rect (xPos+1460, 10, 50, 200);
  rect (xPos+1520, 10, 50, 200);
  rect (xPos+1580, 10, 50, 200);
  rect (xPos+1640, 10, 50, 200);
  rect (xPos+1700, 10, 50, 200);
  rect (xPos+1760, 10, 50, 200);
  rect (xPos+1820, 10, 50, 200);


  fill(0);
  rect (xPos+64,10,30,120);
  rect (xPos+124,10,30,120);
  rect (xPos+244,10,30,120);
  rect (xPos+304,10,30,120);
  rect (xPos+364,10,30,120);
  rect (xPos+364,10,30,120);
  rect (xPos+484,10,30,120);
  rect (xPos+544,10,30,120);
  rect (xPos+664,10,30,120);
  rect (xPos+724,10,30,120);
  rect (xPos+784,10,30,120);
  rect (xPos+904,10,30,120);
  rect (xPos+964,10,30,120);
  rect (xPos+1024,10,30,120);
  rect (xPos+1144,10,30,120);
  rect (xPos+1204,10,30,120);
  rect (xPos+1324,10,30,120);
  rect (xPos+1384,10,30,120);
  rect (xPos+1444,10,30,120);
  rect (xPos+1564,10,30,120);
  rect (xPos+1624,10,30,120);

  if (xPos &lt; -60) xPos = 1860;

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to change the opacity with movement</title>
      <link>https://forum.processing.org/two/discussion/10484/how-to-change-the-opacity-with-movement</link>
      <pubDate>Fri, 24 Apr 2015 00:16:50 +0000</pubDate>
      <dc:creator>emilysadie</dc:creator>
      <guid isPermaLink="false">10484@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys! I am creating a prototype for an idea of an art history game. My idea is to have a piece of artwork behind a blank screen (in this case a white image) and as you move (movement coming from the laptop camera) will erase the white image to reveal the art piece. I am currently using frame differencing to accomplish this, but my code isn't working at all. The image is distorted somehow and what is happening is quite odd. If anyone has any ideas on how to improve or change the code to accomplish my idea, I would greatly appreciate it! Here is my code:</p>

<p>import processing.video.*;
// Variable for capture device
Capture video;
// Previous Frame
PImage prevFrame;
// How different must a pixel be to be a "motion" pixel
float threshold = 50;</p>

<p>PImage img;
PImage img1;</p>

<p>void setup() {
  size(1200,700);
  //tint(200);
  img = loadImage( "van.jpg" );
  size(1200,700);</p>

<p>video = new Capture(this, width, height, 30);
  prevFrame = createImage(video.width,video.height,RGB);
  video.start();</p>

<p>//size(1200, 700);
 // tint(255);
//  img1 = loadImage ( "white.png" );</p>

<p>}</p>

<p>void draw(){
//  img.loadPixels();
 // size(1200, 700);
 // tint(0);
 // img1 = loadImage ( "index.png" );
  if (video.available()) {
    // Save previous frame for motion detection!!
    prevFrame.copy(video,0,0,video.width,video.height,0,0,video.width,video.height); // Before we read the new frame, we always save the previous frame for comparison!
    prevFrame.updatePixels();
    video.read();</p>

<p>}</p>

<p>loadPixels();
  video.loadPixels();
  prevFrame.loadPixels();
  //img1.loadPixels();</p>

<p>// Begin loop to walk through every pixel
  for (int x = 0; x &lt; video.width; x ++ ) {
    for (int y = 0; y &lt; video.height; y ++ ) {</p>

<pre><code>  int loc = x + y*video.width;            // Step 1, what is the 1D pixel location
  //int loc = (video.width - x - 1) + y*video.width;
  color current =  prevFrame.pixels[loc]; //video.pixels[loc];      // Step 2, what is the current color
  color previous = video.pixels[loc]; //prevFrame.pixels[loc]; // Step 3, what is the previous color

  // Step 4, compare colors (previous vs. current)
  float r1 = red(previous); float g1 = green(previous); float b1 = blue(previous);
  float r2 = red(current); float g2 = green(current); float b2 = blue(current);
 float diff = dist(r1,g1,b1,r2,g2,b2);

  // Step 5, How different are the colors?
  // If the color at that pixel has changed, then there is motion at that pixel.
  if (diff &gt; threshold) { 
    // If motion, display black  
//    img.pixels[prevFrame.pixels[loc]] = color( 0, 0, 0, 300 );
    pixels[(video.width - x - 1) + y*video.width] = color(0);
 // } else {
    // If not, display white
    pixels[(video.width - x - 1) + y*video.width] = img.pixels[loc];
  }
}
</code></pre>

<p>}
  updatePixels();
}</p>
]]></description>
   </item>
   <item>
      <title>Full screen? Help please!</title>
      <link>https://forum.processing.org/two/discussion/10516/full-screen-help-please</link>
      <pubDate>Sat, 25 Apr 2015 23:53:16 +0000</pubDate>
      <dc:creator>jarmr</dc:creator>
      <guid isPermaLink="false">10516@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys, I'm pretty new to processing. Can someone help me make this code go full screen? Thanks!</p>

<p>//WHITE w/ blk</p>

<p>import processing.video.*;
// Variable for capture device
Capture video;
// Previous Frame
PImage prevFrame;
// How different must a pixel be to be a "motion" pixel
float threshold = 40;</p>

<p>void setup() {
  size(640,480);
  video = new Capture(this, width, height, 30);
  // Create an empty image the same size as the video
  prevFrame = createImage(video.width,video.height,RGB);
  video.start();
}</p>

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

<p>// Capture video
  if (video.available()) {
    // Save previous frame for motion detection!!
    prevFrame.copy(video,0,0,video.width,video.height,0,0,video.width,video.height); // Before we read the new frame, we always save the previous frame for comparison!
    prevFrame.updatePixels();
    video.read();
  }</p>

<p>loadPixels();
  video.loadPixels();
  prevFrame.loadPixels();</p>

<p>// Begin loop to walk through every pixel
  for (int x = 0; x &lt; video.width; x ++ ) {
    for (int y = 0; y &lt; video.height; y ++ ) {</p>

<pre><code>  int loc = (video.width - x - 1) + y*video.width;            // Step 1, what is the 1D pixel location
  color current = video.pixels[loc];      // Step 2, what is the current color
  color previous = prevFrame.pixels[loc]; // Step 3, what is the previous color

  // Step 4, compare colors (previous vs. current)
  float r1 = red(current); float g1 = green(current); float b1 = blue(current);
  float r2 = red(previous); float g2 = green(previous); float b2 = blue(previous);
  float diff = dist(r1,g1,b1,r2,g2,b2);

  // Step 5, How different are the colors?
  // If the color at that pixel has changed, then there is motion at that pixel.
  if (diff &gt; threshold) { 
    // If motion, display white
    pixels[loc] = color(0);
  } else {
    // If not, display black
    pixels[loc] = color(250);
  }
}
</code></pre>

<p>}
  updatePixels();
}</p>
]]></description>
   </item>
   <item>
      <title>Please help! Drawing on a background</title>
      <link>https://forum.processing.org/two/discussion/10118/please-help-drawing-on-a-background</link>
      <pubDate>Tue, 31 Mar 2015 02:36:49 +0000</pubDate>
      <dc:creator>bsmith28</dc:creator>
      <guid isPermaLink="false">10118@/two/discussions</guid>
      <description><![CDATA[<p>I have this code (with a given set of data imported from Excel):
////////////////////////////////////////////////////////</p>

<pre><code> int   nbr_circles = 500; //total number of runs
  float angle_incr = 2*PI / nbr_circles;

  void setup() {
    size(600,600);
    smooth();
    frameRate(20);
  }

  void draw() {
    background(255);

    fill(0);

    float elapsedSeconds = millis()*.001;
    float angle_incr = radians(2 + frameCount/12.0);

    float cx = width/2;
    float cy = height/2;
    float outer_rad = width*.45;

    String[] lines = loadStrings("distances.csv"); //this will become the diameter
    int[] sm_diameter =  int(split(lines[0],","));

    for (int i = 1; i &lt;= nbr_circles; ++i) {
      float ratio = i/(float)nbr_circles;
      float spiral_rad = ratio * outer_rad;
      float angle = i*angle_incr;
      float x = cx + cos(angle) * spiral_rad;
      float y = cy + sin(angle) * spiral_rad;

      // draw tiny circle at x,y
      noFill();
      ellipse(x, y, sm_diameter[i], sm_diameter[i]);
    }
    noLoop();
  }
</code></pre>

<p>////////////////////////////////////////////////////////</p>

<p>And I want to draw on it with this code:</p>

<p>////////////////////////////////////////////////////////</p>

<pre><code>void setup() {
size(500, 500);
    background(0);
}
void draw() {
    float r = random(0, 255);
    float g = random(0, 255);
    float b = random(0, 255);
    color lineColor = color(r,g,b);
    stroke(lineColor);
    if(mousePressed){

line(width/2, height/2,
    mouseX, mouseY);
}}
</code></pre>

<p>////////////////////////////////////////////////////////</p>

<p>Even if this means taking a screenshot of the first part and adding it in as a background. Please help!</p>
]]></description>
   </item>
   <item>
      <title>G4P- Clearing Text Boxes.</title>
      <link>https://forum.processing.org/two/discussion/10070/g4p-clearing-text-boxes</link>
      <pubDate>Fri, 27 Mar 2015 17:59:44 +0000</pubDate>
      <dc:creator>TechWiz777</dc:creator>
      <guid isPermaLink="false">10070@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys, so I'm working on a project that uses G4P, now the problem is that I am making a sign in page, and well that means I will have different states. Now the problem is that when I change from the sign in page (using G4P) to the next page, the textboxes still stay. Now I know that is because the textboxes are called in void setup(){}. So I tried putting them in void draw(){} but that did not work because draw kept on calling that function, so it would keep on resetting. Like if I click on the textbox, I set the focus, but then it would reset and act like I never clicked it at all. So is there a way that I can somehow remove those textboxes on the next state? Thank you in advance.</p>
]]></description>
   </item>
   <item>
      <title>Make an indicator from button ControlP5</title>
      <link>https://forum.processing.org/two/discussion/10045/make-an-indicator-from-button-controlp5</link>
      <pubDate>Thu, 26 Mar 2015 09:49:26 +0000</pubDate>
      <dc:creator>Fiansyah</dc:creator>
      <guid isPermaLink="false">10045@/two/discussions</guid>
      <description><![CDATA[<p>I want to create an indicator for the two buttons , which if the button " A " controlled will change the color of the ellipse of color 1 to color 2 , and if the button " B " controlled will change the color of the ellipse of color 2 to 1. I think the color of the variable ' x ' can represent value for color ellipse , but it does not work well , please help me resolve this. Thank You.</p>

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



    ControlP5 cP5a;
    ControlP5 cP5b;


    color [] colors = new color[x]; 

    void setup() {
      size(100,100);
      println(Serial.list());
      cP5a = new ControlP5(this);
      cP5a.addButton("A",1,10,10,30,30);
      cP5b = new ControlP5(this);
      cP5b.addButton("B",1,10,50,30,30);

    }

    void draw() {
      background(#614DED);
      fill('x');
      ellipse(56, 46, 20, 20);

    }
    void controlEvent(ControlEvent theEvent) {
      if(theEvent.isController()) {

      print("control event from : "+theEvent.controller().name());
      println(", value : "+theEvent.controller().value());

     if(theEvent.controller().name()=="A") {
       colors[x] = color(#3CF705);

     }
      if(theEvent.controller().name()=="B") {
        colors[x] = color(#FA0A0E);
    }
    }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to send saved frames as attachments with processing's JAVAMAIL library?</title>
      <link>https://forum.processing.org/two/discussion/9970/how-to-send-saved-frames-as-attachments-with-processing-s-javamail-library</link>
      <pubDate>Sat, 21 Mar 2015 22:37:02 +0000</pubDate>
      <dc:creator>TechWiz777</dc:creator>
      <guid isPermaLink="false">9970@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys so I got this so far, the website  is there, also this is from: <a href="https://processing.org/discourse/beta/num_1204669725.html" target="_blank" rel="nofollow">https://processing.org/discourse/beta/num_1204669725.html</a></p>

<p>So how would I include my saved frames, that are in my data folder? I just want to send the whole folder, but I do not know what to do. When I do the code below, i get:</p>

<p>javax.mail.MessagingException: IOException while sending message;
  nested exception is:
    java.io.FileNotFoundException: c:\image.jpg.jpg (The system cannot find the file specified)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1244)
    at javax.mail.Transport.send0(Transport.java:254)
    at javax.mail.Transport.send(Transport.java:124)
    at Email.sendMail(Email.java:134)
    at Email.setup(Email.java:62)
    at processing.core.PApplet.handleDraw(PApplet.java:2361)
    at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
    at processing.core.PApplet.run(PApplet.java:2256)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: c:\image.jpg.jpg (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.(Unknown Source)
    at javax.activation.FileDataSource.getInputStream(Unknown Source)
    at javax.activation.DataHandler.writeTo(Unknown Source)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1608)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:961)
    at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:553)
    at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103)
    at javax.activation.ObjectDataContentHandler.writeTo(Unknown Source)
    at javax.activation.DataHandler.writeTo(Unknown Source)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1608)
    at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1849)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1196)
    ... 8 more</p>

<p>So please help me on what I need to do. Thanks in advance:
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||                      ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv CODE BELOW vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv</p>

<p>// Daniel Shiffman<br />
                                                // <a href="http://www.shiffman.net" target="_blank" rel="nofollow">http://www.shiffman.net</a></p>

<pre><code>                                            // Example functions that send mail (smtp)
                                            // You can also do imap, but that's not included here

                                            // A function to check a mail account


                                            // A function to send mail
                                            void sendMail() {
                                              // Create a session
                                              String host="smtp.gmail.com";
                                              Properties props=new Properties();

                                              // SMTP Session
                                              props.put("mail.transport.protocol", "smtp");
                                              props.put("mail.smtp.host", host);
                                              props.put("mail.smtp.port", "587");
                                              props.put("mail.smtp.auth", "true");
                                              // We need TTLS, which gmail requires
                                              props.put("mail.smtp.starttls.enable","true");

                                              // Create a session
                                              Session session = Session.getDefaultInstance(props, new Auth());

                                              try
                                              {
                                                MimeMessage msg=new MimeMessage(session);
                                                msg.setFrom(new InternetAddress("myemal@gmail.com", "Name"));
                                                msg.addRecipient(Message.RecipientType.TO,new InternetAddress("myemail@gmail.com"));
                                                msg.setSubject("Email with Processing");
                                                BodyPart messageBodyPart = new MimeBodyPart();
                                             // Fill the message
                                                messageBodyPart.setText("Email sent with Processing");
                                                Multipart multipart = new MimeMultipart();
                                                multipart.addBodyPart(messageBodyPart);
                                               // Part two is attachment
                                                messageBodyPart = new MimeBodyPart();
                                                DataSource source = new FileDataSource("c:\\image.jpg");
                                                messageBodyPart.setDataHandler(new DataHandler(source));
                                                messageBodyPart.setFileName("image.jpg");
                                                multipart.addBodyPart(messageBodyPart);
                                                msg.setContent(multipart);
                                                msg.setSentDate(new Date());
                                                Transport.send(msg);
                                                println("Mail sent!");
                                              }
                                              catch(Exception e)
                                              {
                                                println("this is the problem:");
                                                e.printStackTrace();
                                              }

                                            }
</code></pre>
]]></description>
   </item>
   <item>
      <title>image not working</title>
      <link>https://forum.processing.org/two/discussion/10007/image-not-working</link>
      <pubDate>Tue, 24 Mar 2015 10:11:29 +0000</pubDate>
      <dc:creator>hellomynameisfalling</dc:creator>
      <guid isPermaLink="false">10007@/two/discussions</guid>
      <description><![CDATA[<p>hi,
for my image, i want to be able to click on it and then have a white fill like an eraser
PLEASE help
below is my script as well as this keeps showing up, how to get rid of that?</p>

<pre><code>The file "Capture.PNG" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.


void setup(){
  size(800,600);
  background(255);
  noStroke();
  drawControls();
  fill(0); //black
}

{
  loadImage("Capture.PNG");
}

void draw() {

  if (mousePressed == true &amp;&amp; mouseY &lt; 500) {
    ellipse (mouseX, mouseY, 20,20);
  }
  if (mousePressed == true &amp;&amp; mouseY &gt; 500) {
    checkButtons();//run our function
  }
}

void drawControls() {
  fill (127);//grey
  rect(0,500,800,100);//bottom part of screen
  fill (255,0,0);//red
  rect (0,550,50,50);//botton left
  fill (0);//black
  rect (50,550,50,50);//botton 2nd left
  fill(0,255,0);//green
  rect (0,500,50,50);//top left
  fill(0,50,255);//blue
  rect (50,500,50,50);//top 2nd left
  fill(150,16,95); //Purple  
  rect(100,550,50,50); //purple
  fill(23,300,135); 
  rect(100,500,50,50); //light green
  image(loadImage("Capture.PNG"), 300,500);
  fill(0); //black
  rect (700,550,50,50);//reset button
  fill(255); //white
  rect (750,550,50,50);//reset button
}


void checkButtons(){

  if(mouseX &lt; 50 &amp;&amp; mouseY &gt; 550) {
    fill(255,0,0);
  }

  if(mouseX &gt; 0 &amp;&amp; mouseX &lt; 50 &amp;&amp; mouseY &lt; 550) {
    fill(0,255,0);
  }

  if(mouseX &gt; 50 &amp;&amp; mouseX &lt; 100 &amp;&amp; mouseY &lt; 550  ) {
    fill(0,50,255);
  }

  if(mouseX &gt; 50 &amp;&amp; mouseY &gt; 550 &amp;&amp; mouseX &lt; 100) {
    fill(0);
  }

  if(mouseX &gt; 700 &amp;&amp; mouseY &gt; 550 &amp;&amp; mouseX &lt; 750) { 
    fill(0);
    rect(0,0,800,500);
  }

  if(mouseX &gt; 750 &amp;&amp; mouseY &gt; 550 &amp;&amp; mouseX &lt; 800) { 
    fill(255);
    rect(0,0,800,500);
  }

  if (mouseX &lt; 150 &amp;&amp; mouseX &gt; 100 &amp;&amp; mouseY &lt; 550) { //clicked on light green
    fill (23,300,135); // light green
  }

  if (mouseX==300 &amp;&amp; mouseY == 500) 
    fill (255); // white

  if (mouseX &lt; 150 &amp;&amp; mouseX &gt; 100 &amp;&amp; mouseY &gt; 550) { //clicked on light blue
    fill (150,16,95); // purple
  }
} 
</code></pre>
]]></description>
   </item>
   <item>
      <title>Arduino+processing Image transfer</title>
      <link>https://forum.processing.org/two/discussion/4064/arduino-processing-image-transfer</link>
      <pubDate>Mon, 31 Mar 2014 17:06:48 +0000</pubDate>
      <dc:creator>ep0490</dc:creator>
      <guid isPermaLink="false">4064@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>I found some codes online to use the arduino uno and processing to transfer one image through the Arduino serial port (TX and RX). I need to transfer 6 images. How can i modify the processing code or arduino code to be able to transfer all images one after the other. Example: transfer image 1, then 2 etc.</p>

<p>Below is the Arduinocode:</p>

<pre><code>     #include &lt;SD.h&gt;   

     File photoFile;   



     void setup(){   

      Serial.begin(115200);   



      //Serial.println("initializing sd card");   
      pinMode(10,OUTPUT);     // CS pin of SD Card Shield   

      if (!SD.begin(10)) {   
       Serial.print("sd initialzation failed");   
       return;   
      }   

     }   


     void loop(){   

      while(1){   

       Serial.flush();     




         File photoFile = SD.open("IMAGE09.jpg");   

         if (photoFile) {   
          while (photoFile.position() &lt; photoFile.size()) {   


           Serial.write(photoFile.read());   
          }   

          photoFile.close();   

         }    

         else {   
          Serial.println("error sending photo");   
         }         
        }   

       }   
      }   
</code></pre>

<p>PROCESSING CODE:
    // READ: Upload arduino code then processing.File
    //will be created in processiong library under my documets
    //
    //image will begin to transfer. . Click on 
    //the grey processing box AFTER complete imgae size
    // has been reached... and press any button. 
    //Image should have transferred.Click stop.</p>

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

Serial myPort;

OutputStream output;  
//OutputStream output2;

void setup() 
{  

  size(320, 240);  

  //println( Serial.list() );  
  myPort = new Serial( this, Serial.list()[0], 115200);  
  myPort.clear();  
  output = createOutput("IMAGE09.jpg");

}  


void draw() 
{  

  try {   
    while ( myPort.available () &gt; 0 ) 
    {  
      output.write(myPort.read());
    }
  }   
  catch (IOException e) {  
    e.printStackTrace();
  }
}  


void keyPressed()
{  
  try 
  {   
    output.flush(); // Writes the remaining data to the file 
    output.close();  // Finishes the file 
  }   

  catch (IOException e)
  {  
    e.printStackTrace();
  }
}    
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can't figure out why this code doesn't work, need help</title>
      <link>https://forum.processing.org/two/discussion/9875/can-t-figure-out-why-this-code-doesn-t-work-need-help</link>
      <pubDate>Sun, 15 Mar 2015 17:45:16 +0000</pubDate>
      <dc:creator>darthliam</dc:creator>
      <guid isPermaLink="false">9875@/two/discussions</guid>
      <description><![CDATA[<p>I am not exporting to the Internet, hence the commented out Internet parts, but no matter what I try on line 304 when I compile the data or run it, it says unexpected token: void
I really need help with this ASAP it is for a school project.
The error code is right below, but the entire code is below that.</p>

<pre><code>// ============================================================
// this function catches a serial event when the Arduino board responds

void serialEvent(Serial p) { 
  // get the ASCII string:
 // String inString = myPort.readStringUntil('\n');  
  String inString = p.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    int[] rawValues = int(split(inString, ","));
    for(int i=0; i&lt;numOfSensors; i++){
      sensorValues[i] = rawValues[i];
      //sensorValues[i] = map(rawValues[i], 0, 100, 0, 1);
    }
  }
}
</code></pre>

<p>Here is the rest of the code.</p>

<pre><code>`/* ==================================================== 

GardenBot - computer module, local-connection sub-module

beta version 2 (2011-01)
written by Andrew Frueh
<a href="http://gardenbot.org/" target="_blank" rel="nofollow">http://gardenbot.org/</a>

This is the code for the local-connection sub-module of the computer module of GardenBot.
This code should be run in the Processing environment (www.processing.org).
This code communicates with the brain module (Arduino) and can record the data to a text file and/or the web.

==================================================== */



// ============================================================
// Here can setup the basic things you will need to change to be specific to your GardenBot setup

String dataFileName = "sensorData.csv";

// This is the header for the data file
String[] fileDataTemplate = {
  "y-m-d_hr:mn,moisture level (50-100mm),temperature 1,light level 1,waterIsOn)",
  "MIN VALUES,0,0,0,0",
  "MAX VALUES,1023,100,1023,1" // no comma on last item
};
/*
// List any URL that you want this script to report to
String[] listOfURLs = {
  "<a href="http://127.0.0.1/gardenbot/caseStudy/charts/convertSensorData.php" target="_blank" rel="nofollow">http://127.0.0.1/gardenbot/caseStudy/charts/convertSensorData.php</a>",
  "<a href="http://gardenbot.org/caseStudy/charts/convertSensorData.php" target="_blank" rel="nofollow">http://gardenbot.org/caseStudy/charts/convertSensorData.php</a>",
  "<a href="http://127.0.0.1/GardenBotCharts/convertSensorData.php" target="_blank" rel="nofollow">http://127.0.0.1/GardenBotCharts/convertSensorData.php</a>" // no comma on last item
};
*/



// ============================================================
// Initialize the variables

// to enable serial comunication
import processing.serial.*;


int stageMax = 600;
int stageWidth = stageMax;
int stageHeight = stageMax/2;
int numOfSensors = 4;
int[] sensorValues = new int[numOfSensors];
Serial myPort;

int sensorHistMarker = 0;
String[] sensorHistory = new String[1];
String[] sensorHistoryTrimmed = new String[1];
String[] URLexternalList = new String[1];


// messenging
 long messageTimerFreq = 60000;//60,000 = 1 min
 long logicTimerFreq = 900000;//900,000 = 15 min
 long currentTime, messageTimerLast, logicTimerLast;

//
PFont fontA;



// ============================================================
// this is a standard Processing function, it happens once on start up

void setup() {
  size(stageWidth, stageHeight);
  background(#ffffff);


  // List all the available serial ports
  println(Serial.list());

  // load the data
  sensorHistory = loadStrings(dataFileName);

  // get the URL(s) provided in an external file
  //listOfURLs = loadStrings("listOfURLs.txt");

  // if the file does not exist, then create it and initialize it with the header
  if(sensorHistory==null || sensorHistory.length==0){
    //sensorHistory[0] = append(sensorHistory, null);
    //
    saveStrings(dataFileName, fileDataTemplate); 
    // reload
    sensorHistory = loadStrings(dataFileName);
  }


  // write the data out to the files
  sendDataOut();

  println("sensorHistory[]: ");
  println(sensorHistory);
  println("STARTUP::  "+year()+"-"+month()+"-"+day()+"_"+hour()+":"+minute()+":"+second());
  // 


  myPort = new Serial(this, Serial.list()[2], 9600);
  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');

  // load the font for drawing
  fontA = loadFont("CourierNewPS-BoldMT-48.vlw");
  textAlign(CENTER);
  // Set the font and its size (in units of pixels)
  textFont(fontA, 16);
  /*
  */

}




// ============================================================
// this is a standard Processing function - it happens over and over again
//   note: draw() is equivalent to loop() on Arduino
// 

void draw() {

  // for all timers
  currentTime = millis();

  if ( abs(currentTime - messageTimerLast) &gt;= messageTimerFreq) {
    messageTimerLast = currentTime;
    //
    // 82 = 'R'; for Report levels
    myPort.write(82);

  }


  if ( abs(currentTime - logicTimerLast) &gt;= logicTimerFreq) {
    logicTimerLast = currentTime;
    //

    /*
    // load data if not already
    if(sensorFileData==null){
      sensorFileData = loadStrings(dataFileName);
    }
    */

    /*
    //int y = year(), m = month(), d = day(), hr = hour(), mn = minute(), sc = second();
    String timeStamp = year()+"-"+month()+"-"+day()+"_"+hour()+":"+minute();
    int moistureLevel1 = sensorValues[0];
    int temperature1 = sensorValues[1];
    int lightLevel1 = sensorValues[2];
    int waterIsOn = sensorValues[3];
    int moistureLevel2 = sensorValues[4];
    String stringTemp = timeStamp+","+moistureLevel1+","+temperature1+","+lightLevel1+","+waterIsOn+","+moistureLevel2;
    */

    String stringTemp = "";
    stringTemp += year()+"-"+month()+"-"+day()+"_"+hour()+":"+minute();
    stringTemp += ",";
    stringTemp += sensorValues[0]; // MS1
    stringTemp += ",";
    stringTemp += sensorValues[1]; // TP1
    stringTemp += ",";
    stringTemp += sensorValues[2]; // LI1
    stringTemp += ",";
    stringTemp += sensorValues[3]; // WIO

    println(stringTemp);

    //sensorHistory[sensorHistMarker] = stringTemp;
    if(sensorHistory[0]==null){
      sensorHistory[0] = stringTemp;
    }else{
      sensorHistory = append(sensorHistory, stringTemp);
    }
    sensorHistMarker++;

    // send data
    sendDataOut();

  }


  // &gt;&gt; draw the display
  //

  // draw the text
  int titlePosY = 20;
  int barTitlePosY = 50;

  fill(#222222);
  text("GardenBot - local communication sub-module", stageWidth/2, titlePosY);

  //int numOfBars = 3;
  int padding = round(stageWidth*.1);
  //float barWidth = (stageWidth/numOfBars)-(padding*(1+1/float(numOfBars)));
  int barWidth = int(stageWidth * .20);
  int barHeight = stageHeight-(padding*2);
  int i;
  float xTemp;
  float hTemp;
  // draw the bars

  // rect(x, y, width, height)
  // moisture sensor
  i = 0;
  xTemp = padding+(barWidth*i)+(padding*i);
  hTemp = barHeight*map(sensorValues[i],0,1023,0,1);
  fill(#aaaaaa);
  rect(xTemp, padding+(barHeight-hTemp), barWidth, padding+barHeight);
  fill(#555555);
  rect(xTemp, padding, barWidth, barHeight-hTemp);
  //
  fill(#222222);
  text("moisture", xTemp+(barWidth/2), barTitlePosY);

  // temp sensor
  i = 1;
  xTemp = padding+(barWidth*i)+(padding*i);
  hTemp = barHeight*map(sensorValues[i],0,1023,0,1);
  fill(#aaaaaa);
  rect(xTemp, padding+(barHeight-hTemp), barWidth, padding+barHeight);
  fill(#555555);
  rect(xTemp, padding, barWidth, barHeight-hTemp);
  //
  fill(#222222);
  text("temp", xTemp+(barWidth/2), barTitlePosY);

  // light sensor
  i = 2;
  xTemp = padding+(barWidth*i)+(padding*i);
  hTemp = barHeight*map(sensorValues[i],0,1023,0,1);
  fill(#aaaaaa);
  rect(xTemp, padding+(barHeight-hTemp), barWidth, padding+barHeight);
  fill(#555555);
  rect(xTemp, padding, barWidth, barHeight-hTemp);
  //
  fill(#222222);
  text("light", xTemp+(barWidth/2), barTitlePosY);


  /*
  int i;
  for(i=0;i&lt;numOfBars;i=i+1) {   
    float xTemp = padding+(barWidth*i)+(padding*i);
    float hTemp = barHeight*map(sensorValues[i],0,1023,0,1);
    fill(#aaaaff);
    rect(xTemp, padding+(barHeight-hTemp), barWidth, padding+barHeight);
    fill(#aa5500);
    rect(xTemp, padding, barWidth, barHeight-hTemp);
  }
  */
   // &lt;&lt; draw the display

}




// ============================================================
// this function sends the data out to a file and to the web

void sendDataOut(){

    // &gt;&gt; trim data
    String[] sensorHistoryHEAD = subset(sensorHistory, 0, 3);
    String[] sensorHistoryDATA = subset(sensorHistory, 3);
    // figure out the index of where to start reading the data
    int position = sensorHistoryDATA.length - 288; // 3 days worth = 288
    // aquire only the last x days worth of data
    sensorHistoryDATA = subset(sensorHistoryDATA, position);
    // splice the arrays back together
    sensorHistoryTrimmed = splice(sensorHistoryHEAD, sensorHistoryDATA, 3);
    // &lt;&lt; trim data



    // write data to the file, full data
    saveStrings(dataFileName, sensorHistory);
 /*   
    if(listOfURLs.length &gt; 0){
      // create a string for sending as POST var
      String srtTemp = join(sensorHistoryTrimmed,"\n");
      //
      for(int i=0; i&lt;listOfURLs.length; i++){
        // save data to the web 
        postNewItem(listOfURLs[i],"sensorData="+srtTemp);
      } 
    }
}
*/



****_// ============================================================
********
This is were the error code is located.
_****
// ============================================================
// 
// &gt;&gt; postNewItem()
//
// this function thanks to: Euskadi - from the Processing forum (pulled 2010-06-15)
// <a href="http://processing.org/discourse/yabb/YaBB.cgi?board=Integrate;action=display;num=1090838754" target="_blank" rel="nofollow">http://processing.org/discourse/yabb/YaBB.cgi?board=Integrate;action=display;num=1090838754</a>
/*
void postNewItem (String urlIN, String message) {  
  try {  

    URL      url;  
    URLConnection urlConn;  
    DataOutputStream   dos;  
    DataInputStream    dis;  

    url = new URL(urlIN);  
    urlConn = url.openConnection();  
    urlConn.setDoInput(true);  
    urlConn.setDoOutput(true);  
    urlConn.setUseCaches(false);  
    urlConn.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");  

    dos = new DataOutputStream (urlConn.getOutputStream());  

    dos.writeBytes(message);  
    dos.flush();  
    dos.close();  

    // the server responds by saying  
    // "SUCCESS" or "FAILURE"  
    dis = new DataInputStream(urlConn.getInputStream());  
    String s = dis.readLine();  
    dis.close();  

     /*
    if (s.equals("SUCCESS")) {  
 //toDoList.addItem(addTextField.getText());  
 ;//addTextField.setText("");  
    } else {  
 ; //addTextField.setText("Post Error!");  
    }  
    */
/* 
  } // end of "try"  

  catch (MalformedURLException mue) {  
    ; //addTextField.setText("mue error");  
  }  
  catch (IOException ioe) {  
    ; //addTextField.setText("IO Exception");  
  }  

}  
// &lt;&lt; postNewItem()
*/
`
</code></pre>
]]></description>
   </item>
   <item>
      <title>Problem with Collision</title>
      <link>https://forum.processing.org/two/discussion/9742/problem-with-collision</link>
      <pubDate>Sat, 07 Mar 2015 16:59:11 +0000</pubDate>
      <dc:creator>lsaffy</dc:creator>
      <guid isPermaLink="false">9742@/two/discussions</guid>
      <description><![CDATA[<p>HI! I'm very new to programming in general, and have been working on this project for quite a bit of time. As of right now, I cannot for the life of me figure out how to correctly create collision for my class EnemyShips. I've been working on this for an obscene amount of time, and have still not been able to get anything to work. If anyone can help, that would be an absolute lifesaver. This is a game that is based off of Space Invaders, and I need the collision of PlayerBullets to EnemyShips to work.</p>

<pre><code>class AddedScore {
  int score;

  AddedScore(int _score) {
    score = _score;
  }
}

abstract class Bullet {
  int bulletColor;

  float x;
  float y;
  float ySpeed;

    x = spawnX;
    y = spawnY;
    ySpeed = _ySpeed;
  }

  abstract void display();

    y = y+ySpeed;
  }
}

class EnemyShip
{
  float x;
  float y;

  float velocity;

  int shipType;

  PImage ship;

  int shootTimer = floor(random(0, 30));

  EnemyShip(float spawnX, float spawnY) {
    spawnX=x;
    spawnY=y;

    velocity =3;
  }

  void display() {
    translate(x, y);
    image(ship, -50, -50);
    resetMatrix();

    for (int i=0; i&lt;playerBullet.size(); i++) {
      PlayerBullet bullet = playerBullet.get(i);
      if (bullet.x &lt; (x+40) &amp;&amp; bullet.x &gt; (x-50) &amp;&amp; bullet.y &lt; (y+40) &amp;&amp; bullet.y &gt; (x-40)) {
        playerBullet.remove(bullet);
        currentScore = currentScore + 50;
        addedScore.add(new AddedScore(50));
        enemyShip.remove(this);
      }
      else{
      }
    }

    if (y&gt;625) {
      lives = lives -1;
      enemyShip.remove(this);
    }
  }

  void move() {
    this.x+=this.velocity;
    if (x&gt; width*.9) {
      this.x = width*.9;
      this.velocity *=-1;
      this.y+=70;
    }
    //The following is the same as above, but is for when x is less than width*.1
    if (x&lt; width*.1) {
      this.velocity*=-1;
      this.x = width*.1;
      this.y +=50;
    }
  }

  void shoot() {
    EnemyBullet enemyBullet = new EnemyBullet(this.x, this.y, 5);
  }
}

class PlayerBullet extends Bullet
{
  PlayerBullet(float spawnX, float spawnY, float ySpeed) {
    super(spawnX, spawnY, ySpeed);
  }

  void display() {
    fill(155, 237, 23);
    noStroke();
    rect(x,y,5,20);
    if (y&gt;-5) {
      playerBullet.remove(this);
    }
  }
}
</code></pre>

<p>Please let me know if you need to see my setup() or draw(), and any suggestions or help is absolutely welcome. Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Code will not work for me. Pretty sure I put things in the wrong spot. Please help.</title>
      <link>https://forum.processing.org/two/discussion/9736/code-will-not-work-for-me-pretty-sure-i-put-things-in-the-wrong-spot-please-help</link>
      <pubDate>Sat, 07 Mar 2015 06:41:49 +0000</pubDate>
      <dc:creator>AlliB22</dc:creator>
      <guid isPermaLink="false">9736@/two/discussions</guid>
      <description><![CDATA[<p>I can not figure why this isn't working for me. It won't load the player on the screen or the falling objects I have chosen. Can someone please help me fix this?</p>

<h2>Main Tab</h2>

<p>NightSky nightsky;</p>

<p>Player player;</p>

<p>Flower flower;</p>

<p>//Call variables for Flowers and Player.</p>

<p>int nX = 0;</p>

<p>int nY = 0;</p>

<p>float aY = 0;</p>

<p>int aX = 15;</p>

<p>float aV = 3;</p>

<p>//Variable to set up menu.</p>

<p>int stage;</p>

<p>//Images for 2 menu pages and main game page.</p>

<p>PImage Back_G,Fore_G,Direct,Title;</p>

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

<p>stage=1;</p>

<p>size(800,500);</p>

<p>nY = height - 25;</p>

<p>//Load images for menus.</p>

<p>Back_G = loadImage("Background.png");</p>

<p>Fore_G = loadImage("Ground.png");</p>

<p>Direct = loadImage("Directions.png");</p>

<p>Title = loadImage("Title_Screen.png");</p>

<p>flower = new Flower();;  player = new Player();</p>

<p>nightsky = new NightSky(50);</p>

<p>image(Title,0,0,width,height);</p>

<p>//How fast snow falls.</p>

<p>frameRate(7);</p>

<p>smooth();</p>

<p>}
void draw() {</p>

<p>if (stage==1) {</p>

<p>}
  else if (stage==2) {</p>

<pre><code>image(Direct, 0, 0, width, height);
</code></pre>

<p>}
  else if (stage==3) {</p>

<pre><code>background(0);

nightsky.draw();

image(Back_G, 0, 0);

image(Fore_G,0,0);

player.display();

flower.draw();
</code></pre>

<p>}
  //Collision for flowers and player.</p>

<p>if (aY + 10 &gt; nY &amp;&amp; aY - 10 &lt; nY + 20) {</p>

<pre><code>if (aX + 10 &gt; nX &amp;&amp; aX - 10 &lt; nX + 20) {

  fill(255, 0, 0);
</code></pre>

<p>}</p>

<p>//What happens when menu pages are clicked.</p>

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

<p>if (stage==1) {</p>

<pre><code>stage=2;
</code></pre>

<p>}
  else if (stage==2) {</p>

<pre><code>stage=3;
</code></pre>

<p>}
  else if (stage==3) {</p>

<p>}
}</p>

<h2>flowers tab</h2>

<p>class Flower{</p>

<p>//Variable to set up falling flowers and snow.</p>

<p>int aY = 0;</p>

<p>int aX = 15;</p>

<p>float aY = 0;</p>

<p>float aV = 3;</p>

<p>//Images of 2 flowers and 1 snowball.</p>

<p>PImage FF;</p>

<p>PImage PF;</p>

<p>PImage SF;</p>

<p>Flower(){</p>

<pre><code>//Load images for flowers and snowflake.

FF = loadImage("Fire_Flower.png");

PF = loadImage("Poison_Flower.png");

SF = loadImage("Snow_Flake.png");
</code></pre>

<p>}
void draw(){</p>

<p>//Position of flower,flakes.</p>

<p>aY = aY + aV;</p>

<p>if (aY &gt; height) {</p>

<pre><code>aY = 15;

aX = int(random(width - 20));
</code></pre>

<p>}</p>

<pre><code>image(FF,aY,50,50,0);

image(PF,aY,50,50,0);

image(SF,aY,50,50,0);
</code></pre>

<p>}
}</p>

<h2>Nightsky tab</h2>

<p>class Flower{</p>

<p>//Variable to set up falling flowers and snow.</p>

<p>int aY = 0;</p>

<p>int aX = 15;</p>

<p>float aY = 0;</p>

<p>float aV = 3;</p>

<p>//Images of 2 flowers and 1 snowball.</p>

<p>PImage FF;</p>

<p>PImage PF;</p>

<p>PImage SF;</p>

<p>Flower(){</p>

<pre><code>//Load images for flowers and snowflake.

FF = loadImage("Fire_Flower.png");

PF = loadImage("Poison_Flower.png");

SF = loadImage("Snow_Flake.png");
</code></pre>

<p>}
void draw(){</p>

<p>//Position of flower,flakes.</p>

<p>aY = aY + aV;</p>

<p>if (aY &gt; height) {</p>

<pre><code>aY = 15;

aX = int(random(width - 20));
</code></pre>

<p>}</p>

<pre><code>image(FF,aY,50,50,0);

image(PF,aY,50,50,0);

image(SF,aY,50,50,0);
</code></pre>

<p>}
}</p>

<h2>player tab</h2>

<p>class Player{</p>

<p>//Variable coordinate for player.</p>

<p>int nX = 0;</p>

<p>//Player image.</p>

<p>PImage Arie;</p>

<p>Player(){</p>

<pre><code>Arie = loadImage("Arie.png");
</code></pre>

<p>}</p>

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

<pre><code>//Setup coordinates for player.

image(Arie,nX, height - 25, 100, 100);
</code></pre>

<p>}</p>

<p>//Controls for player.</p>

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

<p>// Right arrow.</p>

<p>if (keyCode == RIGHT) {</p>

<pre><code>nX = nX + 3;
</code></pre>

<p>}</p>

<p>// Left arrow.</p>

<p>if (keyCode == LEFT) {</p>

<pre><code>nX = nX - 3;
</code></pre>

<p>}</p>

<p>//So the player doesn't travel outside border boundaries.</p>

<p>if (nX &lt; 0) {</p>

<pre><code>nX = 0;
</code></pre>

<p>}</p>

<p>if (nX &gt; width - 20) {</p>

<pre><code>nX = width - 20;
</code></pre>

<p>}
}
}
}</p>
]]></description>
   </item>
   <item>
      <title>Need help with a restart button for my Snake Game please</title>
      <link>https://forum.processing.org/two/discussion/9616/need-help-with-a-restart-button-for-my-snake-game-please</link>
      <pubDate>Fri, 27 Feb 2015 21:12:10 +0000</pubDate>
      <dc:creator>noraglover</dc:creator>
      <guid isPermaLink="false">9616@/two/discussions</guid>
      <description><![CDATA[<p>I need help understanding how to make a restart button on my snake game. I want it to be the Shift key but it won't allow me to so I made the restart key to be 'r' and it still doesn't work.</p>

<p>//MY CODE</p>

<p>int WIDTH = 700;</p>

<p>int HEIGHT = 600;</p>

<p>int SQSIZE = 10;</p>

<p>int x = 350;</p>

<p>int y = 300;</p>

<p>int foodx = 500;</p>

<p>int foody = 80;</p>

<p>int xspeed, yspeed;</p>

<p>int speed = SQSIZE;</p>

<p>int [] bodyx = new int [80];</p>

<p>int [] bodyy = new int [80];</p>

<p>int score = 0;</p>

<p>int endgame;</p>

<p>int r;</p>

<p>boolean restart = false;</p>

<p>void setup()</p>

<p>{</p>

<p>smooth();</p>

<p>frameRate(14);</p>

<p>size (WIDTH, HEIGHT);</p>

<p>x = 350;</p>

<p>y = 300;</p>

<p>for (int i = 0; i &lt; bodyx.length; i++)</p>

<p>{</p>

<pre><code>bodyx [i] = x;

bodyy [i] = y;
</code></pre>

<p>}</p>

<p>}</p>

<p>void draw()
{
  background(76, 142, 54, 105);</p>

<p>//lines</p>

<p>for (int i = 0; i &lt; 600; i = i+10)</p>

<p>{</p>

<pre><code>stroke(203, 240, 191, 105);

line(0, i, 700, i);
</code></pre>

<p>}</p>

<p>for (int i = 0; i &lt; 700; i = i+10)</p>

<p>{</p>

<pre><code>line(i, 0, i, 600);
</code></pre>

<p>}</p>

<p>//SNAKE</p>

<p>stroke(x, y, 0);</p>

<p>fill(x, y, 255);</p>

<p>rect(x, y, SQSIZE, SQSIZE);</p>

<p>//FOOD</p>

<p>fill(133, 33, 250, 267);</p>

<p>rect(foodx, foody, SQSIZE, SQSIZE);</p>

<p>//SCORE</p>

<p>textSize(30);</p>

<p>fill(255);</p>

<p>text("Score: "+ score, 500, 30);</p>

<p>//food</p>

<p>if ((x == foodx) &amp;&amp; (y == foody))</p>

<p>{</p>

<pre><code>foodx = int(random(2, 68))*SQSIZE;

foody = int(random(2, 58))*SQSIZE;

rect(foodx, foody, SQSIZE, SQSIZE);

score = score + 1;
</code></pre>

<p>}</p>

<p>bodyx[score+1] = x;</p>

<p>bodyy[score+1] = y;</p>

<p>//Body expanding every time food is eaten</p>

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

<p>{</p>

<pre><code>bodyx[i] = bodyx[i+1];

bodyy[i] = bodyy[i+1];

stroke(x, y, 0);

fill (x, y, 255);

rect(bodyx[i], bodyy[i], SQSIZE, SQSIZE);


if ((x == bodyx[i]) &amp;&amp; (y == bodyy[i]) &amp;&amp; i != score)

{ 

  noLoop();

  speed = 0;


  fill(157, 167, 255, 255);

  rect(100, 175, 500, 200);


  textSize(50);

  fill(0);

  text("GAME OVER", 225, 300);


  textSize(30);

  fill(0);

  text("Press Shift to resart", 225, 325);

}
</code></pre>

<p>}</p>

<p>/////////////////////</p>

<p>x = x + xspeed;</p>

<p>y = y + yspeed;</p>

<p>//ENDGAME</p>

<p>if ((x &gt; width-SQSIZE) || (x &lt; +0))</p>

<p>{</p>

<pre><code>xspeed = xspeed * 0;

speed = 0;

fill(157, 167, 255, 255);

rect(100, 175, 500, 200);

textSize(50);

fill(0);

text("GAME OVER", 225, 300);

textSize(30);

fill(0);

text("Press 'r' to resart", 225, 325);
</code></pre>

<p>}</p>

<p>if ((y &gt; height-SQSIZE) || (y &lt; +0))</p>

<p>{</p>

<pre><code>yspeed = yspeed * 0;

speed = 0;

fill(157, 167, 255, 255);

rect(100, 175, 500, 200);

textSize(50);

fill(0);

text("GAME OVER", 225, 300);

textSize(30);

fill(0);

text("Press 'r' to resart", 225, 325);
</code></pre>

<p>}</p>

<p>}</p>

<p>void restart()</p>

<p>{</p>

<p>if (restart == false)</p>

<p>{</p>

<p>//SNAKE</p>

<p>stroke(x, y, 0);</p>

<p>fill(x, y, 255);</p>

<p>rect(x, y, SQSIZE, SQSIZE);</p>

<p>//FOOD</p>

<p>fill(133, 33, 250, 267);</p>

<p>rect(foodx, foody, SQSIZE, SQSIZE);</p>

<p>//SCORE</p>

<p>textSize(30);</p>

<p>fill(255);</p>

<p>text("Score: "+ score, 500, 30);</p>

<p>}</p>

<p>else</p>

<p>{</p>

<pre><code>textSize(50);

fill(0);

text("GAME OVER", 225, 300);



textSize(30);

fill(0);

text("Press 'r' to resart", 225, 325);
</code></pre>

<p>}</p>

<p>}</p>

<p>void keyPressed()</p>

<p>{</p>

<p>if (keyCode == LEFT)</p>

<p>{</p>

<pre><code>xspeed = -speed;

yspeed = 0;
</code></pre>

<p>}</p>

<p>if (keyCode == RIGHT)</p>

<p>{</p>

<pre><code>xspeed = speed;

yspeed = 0;
</code></pre>

<p>}</p>

<p>if (keyCode == UP)</p>

<p>{</p>

<pre><code>yspeed = -speed;

xspeed = 0;
</code></pre>

<p>}</p>

<p>if (keyCode == DOWN)</p>

<p>{</p>

<pre><code>yspeed = speed;

xspeed = 0;
</code></pre>

<p>}</p>

<p>if(keyCode == 'r')</p>

<p>{</p>

<pre><code>restart();
</code></pre>

<p>}
}</p>
]]></description>
   </item>
   <item>
      <title>Help! Need help with Client &amp; Server!</title>
      <link>https://forum.processing.org/two/discussion/9617/help-need-help-with-client-server</link>
      <pubDate>Fri, 27 Feb 2015 21:37:11 +0000</pubDate>
      <dc:creator>oscar124</dc:creator>
      <guid isPermaLink="false">9617@/two/discussions</guid>
      <description><![CDATA[<p>Im trying to make a login client with a server.
this is the client code</p>

<p>problem is that when server sends answer to req it shows as null and not DNY which the server sent.</p>

<pre><code>import processing.net.*;
char LS = 'A';
String UN = "";
String PW = "";
String address = "localhost";
Client myClient;
void setup(){
size(600,620);
myClient = new Client(this,address,5205);
}
void draw(){
if (myClient != null) {
if (myClient.available() &gt; 0) {
println("Recieved");
if (myClient.readString() == "AGR") {
println("greed");
} else if (myClient.readString().startsWith("DNY") == true){
println("Denied");
} else {
println("Empty response");
println(myClient.readString());
}
}else{

}
}
background(0);
fill(200,0,0);
rect(width/2-200,height/2+5,400,-30);
rect(width/2-200,height/2+50,400,-30);
rect(width/2-50,height/2+100,100,-30);
fill(0,0,0);
textSize(18);
text("Login",width/2-22,height/2+90);
text(UN,105,305);
text(PW,105,350);
}
void keyReleased(){
if (keyCode == BACKSPACE){
switch (LS) {     
case 'A':
if (UN.length() &gt; 0) {
  UN = UN.substring(0, UN.length()-1);
}
break;
case 'B':
if (PW.length() &gt; 0) {
  PW = PW.substring(0, PW.length()-1);
}
break;
}}
if (keyCode != SHIFT &amp;&amp; keyCode != CONTROL &amp;&amp; keyCode != ALT &amp;&amp; keyCode != BACKSPACE){
switch (LS) {     
case 'A':
UN = UN + key;
break;
case 'B':
PW = PW + key;
break;
}}}
void mousePressed(){
if (mouseX &gt;= width/2-200 &amp;&amp; mouseY &lt;= height/2+5 &amp;&amp; mouseX &lt;= width/2+200 &amp;&amp; mouseY &gt;= height/2+5-30) {
LS = 'A';
} else if (mouseX &gt;= width/2-200 &amp;&amp; mouseY &lt;= 
height/2+50 &amp;&amp; mouseX &lt;= width/2+200 &amp;&amp; mouseY &gt;= height/2+50-30) {
LS = 'B';
} else if (mouseX &gt;= width/2-50 &amp;&amp; mouseY 
&lt;= height/2+100 &amp;&amp; mouseX &lt;= width/2-50+100 &amp;&amp; mouseY &gt;=    height/2+100-30) {
myClient.write("req"+" - "+UN+PW);
println("Sent REQ");
}}
</code></pre>

<hr />

<p>And this is the server code:</p>

<p>also there is a text document in sketch folder called users.txt and contains the word test123123test</p>

<pre><code>import processing.net.*;
boolean userExists = false;
Server myServer;
void setup(){
size(600,620);
myServer = new Server(this,5205);
}
void draw(){
Client myClient = myServer.available();
if (myClient != null) {
if (myClient.available() &gt; 0) {
println("Noticed Message Incoming");
String mess = myClient.readString();
String[] Smess = split(mess," - ");
if (Smess[0].startsWith("req") == true) {
println("noticed request");
println(Smess[1]+"Is The User");
String[] users = loadStrings("users.txt");
for(int i = 0; i &lt; users.length; i++){
if (users[i] == Smess[1]) {
println("userExists");
userExists = true;
}
}
if (userExists == true) {
myServer.write("AGR");
println("Sendin Agree");
} else if (userExists == false){
myServer.write("DNY");
println("Sendin Deny");
} else {
println("ERROR");  
}
}
}
}
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Need help with chat-server!!!</title>
      <link>https://forum.processing.org/two/discussion/9571/need-help-with-chat-server</link>
      <pubDate>Wed, 25 Feb 2015 08:38:57 +0000</pubDate>
      <dc:creator>oscar124</dc:creator>
      <guid isPermaLink="false">9571@/two/discussions</guid>
      <description><![CDATA[<pre><code>         The problem is here under draw :                FULL CODE IS BELOW!!!
         if (serverOn = true) {
         text(myText, 15, 550, width, height);
         Client thisClient = myServer.available();
         if (thisClient != null) {
         if (thisClient.available() &gt; 0) {
         if (msgCount == 13) {
         textLine = 60;
         background(0, 0, 0);
         msgCount = 0;
         }
         fill(0, 200, 0);
         myServer.write(""+thisClient.readString()); &lt;----- When i resend the message to all connected clients it says NULL
         instead of the message!

         text(thisClient.readString(), 15, textLine);
         msgCount++;
         textLine = textLine + 35;
</code></pre>

<hr />

<p>`</p>

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

      Server myServer; 

      Client myClient;
      int Z;
      int textLine = 60;
      boolean serverOn;
      PrintWriter output;
      int year = year();
      int month = month();
      int day = day();
      String y = ""+year;
      String m = ""+month;
      String d = ""+day;
      int msgCount = 0;
      String myText = "";
      boolean debug = true;
      int X, Y;

      void setup() {
      background(0, 0, 0);
      myServer = new Server(this, 5204); 
      //Initialize server
      size(300, 620);
      if (frame != null) {
      frame.setResizable(true);
      }
      }
     void draw() {
     if (debug == true) {
     println(mouseX, mouseY);
     }
     if (serverOn = true) {
     text(myText, 15, 550, width, height);
     Client thisClient = myServer.available();
      if (thisClient != null) {
       if (thisClient.available() &gt; 0) {
         if (msgCount == 13) {
         textLine = 60;
          background(0, 0, 0);
          msgCount = 0;
          }
         fill(0, 200, 0);
        myServer.write(""+thisClient.readStringUntil(1));
        text(thisClient.readString(), 15, textLine);
        msgCount++;
        textLine = textLine + 35;
       }
       }
      } else {
      text("server", 15, 45);
      text("stopped", 15, 65);
     }
     }
     void keyPressed() {
     if (keyCode == BACKSPACE) {
     if (myText.length() &gt; 0) {
    myText = myText.substring(0, myText.length()-1);
    }
    } else if (keyCode == DELETE) {
    myText = "";
   } else if (keyCode != SHIFT &amp;&amp; keyCode != CONTROL &amp;&amp; keyCode != ALT) {
  myText = myText + key;
  } else if (keyCode == ALT) {
 if (myText != "" || myText != " "){
   myServer.write("Server"+" : "+myText); 
 if (msgCount == 13) {
       textLine = 60;
       background(0, 0, 0);
       msgCount = 0;
 }
 text("Server"+" : "+myText, 15, textLine);
 msgCount++;
 textLine = textLine + 35;
 }
 myText = "                                                                                                                                                             ";
 fill(200, 0, 0);
 rect(0, 550, width, height);
 fill(0, 200, 0);
 myText = "";
 }
 }`
</code></pre>
]]></description>
   </item>
   <item>
      <title>Tic-Tac-Toe Help</title>
      <link>https://forum.processing.org/two/discussion/9577/tic-tac-toe-help</link>
      <pubDate>Wed, 25 Feb 2015 17:03:29 +0000</pubDate>
      <dc:creator>MikeSanGi</dc:creator>
      <guid isPermaLink="false">9577@/two/discussions</guid>
      <description><![CDATA[<p>So I'm working on a simple tic-tac-toe game and everything runs as inteded, except for one little thing.  The last move of a game doesn't show up properly on the board, it just shows the win/full board prompt and clears the board.  Maybe I'm just tired but I can'r for the life of me figure out why this is, no matter how much I experiment. I figured that since my displayCurrentBoard function is called before the prompt, it should appear but it seems not to be the case. Help is very much appreciated.</p>

<pre><code>import javax.swing.JOptionPane;
import ddf.minim.*;

PImage pencil;
PImage xMark;
PImage oMark;
PImage game;
PImage start;
PImage howto;
Minim minim;
AudioPlayer player1;
int penX = -400;
int penY = -400;
boolean Xturn = true;
int [][] board = new int[3][3];
int xState = 1;
int yState = 1;
int filledNum = 0;
int xNum = 0;
int yNum = 0;
int screen = 0;

void setup()
{
  size(600,600);
  minim = new Minim(this);
  player1 = minim.loadFile("bgmusic.mp3");
  start = loadImage("start.png");
  howto = loadImage("instruct.png");
  game = loadImage("board.png");
  pencil = loadImage("pointer.png");
  xMark = loadImage("x.png");
  oMark = loadImage("o.png");
  background(game);
  player1.play();
}

void draw()
{
  if(screen == 0)
  {
    image(start,0,0);
  }

  if(screen == 1)
  {
    image(howto,0,0);
  }

  if(screen == 2)
  {
  image(game,0,0);
  displayCurrentBoard();
  image(pencil,penX,penY);
  text("(" + xState + "," + yState + ")", 10, 593);
  if(Xturn)
  {
    text("It is X's turn.",500 , 593);
  }
  else
  {
    text("It is O's turn.",500 , 593);
  }
  }

  if(checkXwin())
  {
    displayResults(1);
  }

    if(checkOwin())
  {
    displayResults(2);
  }

  if(checkNoWin())
  {
    displayResults(3);
  }

}

void keyPressed()
{
  if(key == 'a')
  {
   if(Xturn  &amp;&amp; (board[xState - 1][yState - 1] != 1 &amp;&amp; board[xState - 1][yState - 1] != 2))
   {
       board[xState - 1][yState - 1] = 1;
       Xturn = false;
   }
   else if ((board[xState - 1][yState - 1] != 1 &amp;&amp; board[xState - 1][yState - 1] != 2))
   {
     board[xState - 1][yState - 1] = 2;
     Xturn = true;
   }
  }

  if(key == 's')
  {
    if(screen &lt; 2)
    {
      screen++;
    }
  }

  if(key == CODED)  //Used to take input from keyboard
  {
    if(keyCode == UP) //Moves cursor up if within proper boundaries
    {
      if(penY != -400)
      {
        penY = penY - 200;
          if(yState != 1) //registers new position
            {
             yState--; 
            }
      }
    }

    if(keyCode == DOWN)
    {
         if(penY != 0)
      {
        penY = penY + 200;
        if(yState != 3)
        {
          yState++;
        }
      }
    }

    if(keyCode == LEFT)
    {
         if(penX != -400)
      {
        penX = penX - 200;
        if( xState != 1)
        {
          xState--;
        }
      }
    }

    if(keyCode == RIGHT)
    {
         if(penX != 0)
      {
        penX = penX + 200;
        if (xState != 3)
        {
         xState++; 
        }
      }
    }

  }
}

void displayCurrentBoard()
{
  for(int i = 0; i &lt; 3; i++)
  {
    for(int j = 0; j &lt; 3; j++)
    {
      if(board[i][j] == 1)
      {
        image(xMark,(i * 200),(j * 200));
      }
      else if(board[i][j] == 2)
      {
        image(oMark, (i * 200), (j * 200));
      }
    }
  }
}

boolean checkXwin()
{
  if((board[0][0] == 1 &amp;&amp; board [1][0] == 1 &amp;&amp; board[2][0] == 1) ||
     (board[0][1] == 1 &amp;&amp; board [1][1] == 1 &amp;&amp; board[2][1] == 1) ||
     (board[0][2] == 1 &amp;&amp; board [1][2] == 1 &amp;&amp; board[2][2] == 1) ||
     (board[0][0] == 1 &amp;&amp; board [0][1] == 1 &amp;&amp; board[0][2] == 1) ||
     (board[1][0] == 1 &amp;&amp; board [1][1] == 1 &amp;&amp; board[1][2] == 1) ||
     (board[2][0] == 1 &amp;&amp; board [2][1] == 1 &amp;&amp; board[2][2] == 1) ||
     (board[0][0] == 1 &amp;&amp; board [1][1] == 1 &amp;&amp; board[2][2] == 1) ||
     (board[0][2] == 1 &amp;&amp; board [1][1] == 1 &amp;&amp; board[2][0] == 1))
     {
        return true;
      }
  else
  {
  return false;
  }
}


boolean checkOwin()
{
  if((board[0][0] == 2 &amp;&amp; board [1][0] == 2 &amp;&amp; board[2][0] == 2) ||
     (board[0][1] == 2 &amp;&amp; board [1][1] == 2 &amp;&amp; board[2][1] == 2) ||
     (board[0][2] == 2 &amp;&amp; board [1][2] == 2 &amp;&amp; board[2][2] == 2) ||
     (board[0][0] == 2 &amp;&amp; board [0][1] == 2 &amp;&amp; board[0][2] == 2) ||
     (board[1][0] == 2 &amp;&amp; board [1][1] == 2 &amp;&amp; board[1][2] == 2) ||
     (board[2][0] == 2 &amp;&amp; board [2][1] == 2 &amp;&amp; board[2][2] == 2) ||
     (board[0][0] == 2 &amp;&amp; board [1][1] == 2 &amp;&amp; board[2][2] == 2) ||
     (board[0][2] == 2 &amp;&amp; board [1][1] == 2 &amp;&amp; board[2][0] == 2))
     {
        return true;
      }
  else
  {
  return false;
  }
}

boolean checkNoWin()
{
  filledNum = 0;
  for(int i = 0; i &lt; 3; i++)
  {
    for(int j = 0; j &lt; 3; j++)
    {
      if(board[i][j] == 1 || board[i][j] == 2)
      {
        filledNum++;
      }
    }
  }
  if(filledNum == 9)
  {
    displayCurrentBoard();
    //clearBoard();
    return true;
  }
  else
  {
    return false;
  }
}

void clearBoard()
{
  displayCurrentBoard();
   for(int i = 0; i &lt; 3; i++)
  {
    for(int j = 0; j &lt; 3; j++)
    {
      board[i][j] = 0;     
    }
  }
}

void displayResults(int i)
{
  displayCurrentBoard();

  switch(i)
  {
    case 1: JOptionPane.showMessageDialog(null, "X Wins.  Restarting...");
            clearBoard();
            break;
    case 2: JOptionPane.showMessageDialog(null, "O Wins.  Restarting...");
            clearBoard();
            break;
    case 3: JOptionPane.showMessageDialog(null, "The board is full.  Restarting...");
            clearBoard();
            break;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>help with processing/eclipse creating an exportable window applet/aplication</title>
      <link>https://forum.processing.org/two/discussion/9466/help-with-processing-eclipse-creating-an-exportable-window-applet-aplication</link>
      <pubDate>Tue, 17 Feb 2015 14:15:20 +0000</pubDate>
      <dc:creator>Silverjust</dc:creator>
      <guid isPermaLink="false">9466@/two/discussions</guid>
      <description><![CDATA[<p>Hi,<br />
I´made a little programm in eclipse with the processing library.<br />
I tried to export everything as a runnable jar file, but I can´t select the launch configuration,<br />
because I was running it as a java applet.<br />
I read somewhere, that it´s not possible to create a runnable jar file from a java applet.</p>

<p>Does someone know how to create a runnable .jar or .exe file, that opens a window and not something in fullscreen?</p>
]]></description>
   </item>
   <item>
      <title>How to use array and for loop in my case?? please help</title>
      <link>https://forum.processing.org/two/discussion/9418/how-to-use-array-and-for-loop-in-my-case-please-help</link>
      <pubDate>Sat, 14 Feb 2015 04:39:20 +0000</pubDate>
      <dc:creator>chuckjai</dc:creator>
      <guid isPermaLink="false">9418@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys, i am bad at english, hope you guys understand what i'm talking about.
I am working on my assignment of processing, i would like to create a mini game like NS SHAFT.
I want 3 object move from the bottom to the top,</p>

<p>in my code , obsX is the x position, obsY is y position:</p>

<p>obsX=int(random(-50, width-200));</p>

<p>obsY=height-100;</p>

<p>obsX2=int(random(-50, width-200));</p>

<p>obsY2=height+200;</p>

<p>obsX3=int(random(-50, width-200));</p>

<p>obsY3=height+400;</p>

<p>obsWidth=200;</p>

<p>obsHeight=100;</p>

<p>obsSpeed=5;</p>

<p>and i write a function call wood to make it move those objects upward:</p>

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

<p>image(cloud,obsX, obsY, obsWidth, obsHeight);
  obsY=obsY-obsSpeed;</p>

<p>image(cloud,obsX2, obsY2, obsWidth, obsHeight);
  obsY2=obsY2-obsSpeed;</p>

<p>image(cloud,obsX3, obsY3, obsWidth, obsHeight);
  obsY3=obsY3-obsSpeed;</p>

<p>}</p>

<p>How could i use array and for loop to simplify the code??</p>
]]></description>
   </item>
   <item>
      <title>help with new game in processing/eclipse organizing resources</title>
      <link>https://forum.processing.org/two/discussion/9319/help-with-new-game-in-processing-eclipse-organizing-resources</link>
      <pubDate>Fri, 06 Feb 2015 19:25:28 +0000</pubDate>
      <dc:creator>Silverjust</dc:creator>
      <guid isPermaLink="false">9319@/two/discussions</guid>
      <description><![CDATA[<p>Hello<br />
I´m working on a big project in eclipse with the processing.core.* library.<br />
And at the moment I have some problems with organizing the resources.<br />
should I put them into a recource folder or into a package in src?<br />
How can I access the resources?<br />
at the moment, I´m using<br />
<code>app.getClass().getClassLoader().getResource("data");</code>  and<br />
<code>app.sketchPath("data")</code><br />
but when i export everything into a runnable jar file, it isn´t working caused by the resources.</p>

<p>can someone help?</p>
]]></description>
   </item>
   <item>
      <title>can't run this code in processing 2.2.1 for linux Ubuntu 14.04 32 bits</title>
      <link>https://forum.processing.org/two/discussion/9226/can-t-run-this-code-in-processing-2-2-1-for-linux-ubuntu-14-04-32-bits</link>
      <pubDate>Thu, 29 Jan 2015 09:07:38 +0000</pubDate>
      <dc:creator>j_ulload</dc:creator>
      <guid isPermaLink="false">9226@/two/discussions</guid>
      <description><![CDATA[<p>(sorry for my english)
well, i'm like a newbie in this and i was trying to make a sketch of my own, but had problems when i put in a nested loop, the code its not running, the console don't show me any error but don't show me the sketch. I tried with a example sketch that had a nested loop but the code run without problems.
so, this is the code, maybe there is something wrong with it:</p>

<pre><code>size(300, 600);
background(0);
fill(255);
noStroke();
for (int i = 150; i &lt;= height; i += 200) {
  for (int r = 200; r &lt;= width; r -= 50) {
    ellipse(150, i, r, r);
  }
}
</code></pre>

<p>help me please!!!</p>
]]></description>
   </item>
   <item>
      <title>Mimicking natural processes.</title>
      <link>https://forum.processing.org/two/discussion/8387/mimicking-natural-processes</link>
      <pubDate>Fri, 28 Nov 2014 15:28:45 +0000</pubDate>
      <dc:creator>aholtman</dc:creator>
      <guid isPermaLink="false">8387@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to mimic the processes of plant growth and was curious what are some codes that could help me in doing so. Im looking at branching patterns of trees and/or vines.</p>
]]></description>
   </item>
   <item>
      <title>In danger of failing my computer programing class</title>
      <link>https://forum.processing.org/two/discussion/8185/in-danger-of-failing-my-computer-programing-class</link>
      <pubDate>Sun, 16 Nov 2014 10:46:29 +0000</pubDate>
      <dc:creator>Azazel</dc:creator>
      <guid isPermaLink="false">8185@/two/discussions</guid>
      <description><![CDATA[<p>hello I was originally in a history class and i switched it out about 4 weeks int school for a intro to computer programing class, lets just say they were so far ahead of me already i knew there was no way of me catching up and learning the materiel to be able to do what i needed to. if anyone is willing to take time to help me get my projects finished i would be grateful. i have told my dad about this and there is no possible way to get a decent grade for me. i know i wont pass this course with out "help". I have asked the teacher for help and he simply does not supply the answers i need. we are already in the second term and i have the knowledge of someone who just started. Ive bull shited my way through the other projects, but now things are getting to test our knowledge on the course and i will fail with out some miracle. if there is anyway someone gets the time to help me with my problem like i said you would be a miracle.</p>
]]></description>
   </item>
   <item>
      <title>How do I crop these bezier curves?</title>
      <link>https://forum.processing.org/two/discussion/8046/how-do-i-crop-these-bezier-curves</link>
      <pubDate>Mon, 10 Nov 2014 08:01:01 +0000</pubDate>
      <dc:creator>Zeke</dc:creator>
      <guid isPermaLink="false">8046@/two/discussions</guid>
      <description><![CDATA[<p>Hey, so I have four bezier curves and I want to crop some parts of them. See <a rel="nofollow" href="http://cl.ly/YRjJ">this screenshot for explanation</a>. The highlighted parts of the curves should not be there. Is there anything that could make this easier? Here's my code:</p>

<pre><code>color bg = #010D30;
color lines = #AA50BD;

void setup() {
  frameRate(60);

  for (int i = 0; i &lt; height; i = i + 50) {
    stroke(255);
    line(0, i, width/2, 0);
  }

  size(700, 700);
  smooth();

  // Basic settings
  background(bg);
  strokeWeight(2);
  noFill();
  stroke(lines);

  // Left Bottom to Right Top: Down
  beginShape();
  vertex(0, width);
  bezierVertex(0, width, 0, width, 0, width);
  bezierVertex(0, width, width, width, width, 0);
  endShape();

  // Left Bottom to Right Top: Up
  beginShape();
  vertex(0, width);
  bezierVertex(0, width, 0, width, 0, width);
  bezierVertex(0, width, 0, 0, width, 0);
  endShape();

  // Left Top to Right Bottom: Up
  beginShape();
  vertex(0, 0);
  bezierVertex(0, 0, 0, 0, 0, 0);
  bezierVertex(0, 0, width, 0, width, width);
  endShape();

  // Left Top to Right Bottom: Down
  beginShape();
  vertex(0, 0);
  bezierVertex(0, 0, 0, 0, 0, 0);
  bezierVertex(0, 0, 0, width, width, width);
  endShape();
}
</code></pre>

<p>Cheers!</p>
]]></description>
   </item>
   <item>
      <title>Catching Raindrop Game Help</title>
      <link>https://forum.processing.org/two/discussion/7929/catching-raindrop-game-help</link>
      <pubDate>Sun, 02 Nov 2014 22:03:34 +0000</pubDate>
      <dc:creator>pipsqueak</dc:creator>
      <guid isPermaLink="false">7929@/two/discussions</guid>
      <description><![CDATA[<p>I need the raindrops to disappear once the mouse is rolled over them and the score to increase every time the raindrop is rolled over.</p>

<pre><code>    Main tab:
    Raindrop[] theRaindrops;
    int numberOfRaindrops = 30;
    Bucket bucket;
    int score = 0;

    void setup() {
      size(500, 500);
      background(225);
      theRaindrops = new Raindrop[numberOfRaindrops];
      for (int i=0; i&lt;numberOfRaindrops; i ++) {
        theRaindrops[i] = new Raindrop(random(0, 500), 0, random(-6, 6));
      }
      bucket = new Bucket(mouseX, mouseY);
    }

    void draw() {
      background(255);
      fill(0);
      textSize(30);
      text("Your Score is: " + score, 10, 30);
      for (int i =0; i&lt;numberOfRaindrops; i++) {
        theRaindrops[i].display();
        theRaindrops[i].rain();
      }
      bucket.display();
      bucket.setLocation(mouseX,mouseY);
    }

    //not working
    //void mousePressed() {
    //  for (int i=0; i&lt;numberOfRaindrops; i++) {
    //    if (theRaindrops[i].hasBeenClicked(mouseX-15, mouseY-25)) {
    //      if (theRaindrops[i].haveYouBeenClicked ()) {
    //        score++;
    //      }
    //      theRaindrops[i].haveYouBeenClicked();
    //    }
    //  }
    //}

    Bucket tab:
    class Bucket {
      float myX;
      float myY;

      Bucket(float mouseX, float mouseY) {
        myX = mouseX;
        myY = mouseY;
      }

      void display() {
        fill(0);
        rect(mouseX-15, mouseY-25, 30, 50);
      }

      void setLocation(float tempX,float tempY){
        myX = tempX;
        myY = tempY;
      }

      boolean intersect(Raindrop d){
       if((myX&lt;30) || (myY&lt;30)){
         return true;
       }
       else{
        return false;
      }
    }
    }

    Raindrop tab:
    class Raindrop {
      float myX;
      float myY;
      float myYVel;
      boolean no;

      Raindrop(float x, float y, float yVel) {
        myX = x;
        myY = y;
        myYVel = yVel;
      }

      boolean haveYouBeenClicked() {
        return no;
      }

      float getX() {
        return myX;
      }
      float getY() {
        return myY;
      }

      void display() {
        fill(0, 0, 255);
        ellipse(myX, myY, 20, 20);
      }

      boolean hasCollided(Raindrop otherRaindrop) {
        if (otherRaindrop.getX() +50 &gt; myX) {
          if (otherRaindrop.getX() &lt; myX + 50) {
            if (otherRaindrop.getY() +30 &gt; myY) {
              if (otherRaindrop.getY() &lt; myY +30) {
                return true;
              }
            }
          }
        }
        return false;
      }

      boolean hasBeenClicked(float mouseX, float mouseY) {
        if ((myX &lt; mouseX) &amp;&amp; (mouseX &lt; myX + 50)) {
          if ((myY &lt; mouseY) &amp;&amp; (mouseY &lt; myY + 30)) {
            return true;
            //myY=0;
          }
        }
        return false;
      }

      void rain() {
        myY = myY + myYVel;
        if (myY&gt;500) {
          myY=50;
          myX = random(0, 500);
        }
      }
    }
</code></pre>
]]></description>
   </item>
   </channel>
</rss>