<?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 #classes - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23classes</link>
      <pubDate>Sun, 08 Aug 2021 20:36:00 +0000</pubDate>
         <description>Tagged with #classes - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23classes/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Newby question :Null Pointer Exception Error</title>
      <link>https://forum.processing.org/two/discussion/23673/newby-question-null-pointer-exception-error</link>
      <pubDate>Wed, 02 Aug 2017 10:19:15 +0000</pubDate>
      <dc:creator>Rouzbelious</dc:creator>
      <guid isPermaLink="false">23673@/two/discussions</guid>
      <description><![CDATA[<p>Hey folks, 
I am trying to write a code that draws a circle on every point that mouse is pressed and when mouse is released the circle moves to center of screen and merges with a big circle in the center. I wrote its code without any class objects and it works fine( 1st code) but when I try to write it with class objects(2nd code in comments) I face <strong>Null Pointer Exception</strong>  error and I am almost sure that I have initialized all variables. I would appreciate if you tell me what is wrong.</p>

<pre><code>int r;
int R = 100;
int RL = 100;
int x;
int y;
void setup() {
  size(800, 800);
  smooth();
  background(255);
  noStroke();
  frameRate(30);
  ellipseMode(CENTER);
}
void draw() {
  background(255);
  fill(80);
  ellipse(width/2, height/2, R, R);
  if (mousePressed) {
    fill(0);
    r++;
    x = mouseX;
    y = mouseY;
    ellipse(x, y, r, r);
  } else {
    fill(80);
    x += (width/2-x)*.05;
    y += (height/2-y)*.05;
    ellipse(x, y, r, r);
    if (abs(x-(width/2))&lt;20 &amp;&amp; abs(y-(height/2))&lt;20 &amp;&amp; r&gt;0) {
      R++;
      ellipse(width/2, height/2, R, R);
      if (R == RL+r) {
        RL = R;
        r = 0;
      }
    }
  }
  println(r);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Collision Detection with Squares/Rectangles</title>
      <link>https://forum.processing.org/two/discussion/22630/collision-detection-with-squares-rectangles</link>
      <pubDate>Wed, 17 May 2017 06:11:18 +0000</pubDate>
      <dc:creator>Dreeww</dc:creator>
      <guid isPermaLink="false">22630@/two/discussions</guid>
      <description><![CDATA[<p>Hello, trying to figure out how to do collision detection with squares/Rectangles unsure how to figure out. I have a base idea on how to find the distance, however i'm unsure on what to compare it to.</p>

<pre><code>void collisionDetection(){
  for(int i = Walls.size()-1; i&gt;=0 ; i--){
    Wall current = Walls.get(i);

    for(int b1 = tank1Bullet.size()-1; b1&gt;=0; b1--){
      tank1Bullet currentBullet = tank1Bullet.get(b1);
      //this is problem the problem
      if(dist(currentBullet.x,currentBullet.y,current.X,current.Y)&lt;(current.Width)){
      tank1Bullet.remove(b1);
      //Walls.remove(i);
      }
    }

class Wall{

  float Width;
  float Height;
  float X;
  float Y;
  Wall(float x,float y,float w, float h){
    Width = w;
    Height = h;
    X = x;
    Y = y;

  }
  void display(){
   fill(0);
   rect(X,Y,Width,Height);
  }

}

  class tank1Bullet extends PVector{
    PVector location;
    float rotation, bullet_Speed;

    tank1Bullet(){
        location = new PVector(tank1Location.x, tank1Location.y);
        rotation = tank1Rotate;
        bullet_Speed = 20;
    }
    void update(){

    location.x = location.x  + sin(rotation)*bullet_Speed;
    location.y = location.y  - cos(rotation)*bullet_Speed;

    //condition to removes the bullet from the arrayList if it is off the screen
    if (location.x &gt; 0 &amp;&amp; location.x &lt; width+500 &amp;&amp; location.y &gt; 0 &amp;&amp; location.x &lt; height+500) {

    }
    else {
      tank1Bullet.remove(b1);
    }

  }
    void draw_Bullet(){
      ellipse(location.x,location.y , 10, 10);
    }
  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>efficient referencing between classes</title>
      <link>https://forum.processing.org/two/discussion/19805/efficient-referencing-between-classes</link>
      <pubDate>Sun, 18 Dec 2016 13:43:27 +0000</pubDate>
      <dc:creator>nnenov</dc:creator>
      <guid isPermaLink="false">19805@/two/discussions</guid>
      <description><![CDATA[<p>Hello, Ive been working on a sketch for a while now, tragically without a clear plan from the start.</p>

<p>Naturally everything is becoming messy now and out of hand.</p>

<p>I have 4 classes/objects, <strong>interface</strong>, <strong>grids</strong>, <strong>matchBox</strong>, <strong>control</strong>.</p>

<p><strong>interface</strong> contains an arrayList of <strong>grids</strong> objects, <strong>matchBox</strong> contains a fixed size array of <strong>control</strong> objects, 
each <strong>control</strong> object in the array needs info on some, but not all of the parameters of the <strong>grids</strong> arrayList objects..</p>

<p>My question is, is it more efficient to make IntLists (they can vary in size) of the specific <strong>grids</strong> properties, and pass them on to the <strong>control</strong> objects via <strong>matchBox</strong>, 
or is it better(more cpu efficient) to send the whole <strong>grids</strong> arrayList to <strong>matchBox</strong> then to each <strong>control</strong>?</p>
]]></description>
   </item>
   <item>
      <title>How to use the current coordinates of an object outside its display function</title>
      <link>https://forum.processing.org/two/discussion/19662/how-to-use-the-current-coordinates-of-an-object-outside-its-display-function</link>
      <pubDate>Sun, 11 Dec 2016 15:08:18 +0000</pubDate>
      <dc:creator>rickymarto</dc:creator>
      <guid isPermaLink="false">19662@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody,</p>

<p>I want to drew a graphical interface to control the parameters of few oscillators that I'm going to build through the Minim library. I created a class which consists of a circle with three other little circles inside and this object rotates around itself. (let's say a wheel with three points on it). With the <em>display()</em> function inside the class I drew in <em>draw()</em> three of these wheels.</p>

<p>Now, what I want to do is to get the current position on the screen of the smaller rotating circles of each wheel, in order to calculate the distance between each one of them and the other small circles of the other wheels. The aim is to map each value of the distance with a parameter of my oscillators.</p>

<p>If I calculate the distance in the <em>void display()</em> I cannot use it outside this function and I cannot do it  in draw() for example, because the coordinates of the points are valid only in display().</p>

<p>How can I get and use the current position od each small circle?</p>

<pre><code>Wheel wheelA;
Wheel wheelB;
Wheel wheelC;


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

  wheelA = new Wheel();
  wheelB = new Wheel();
  wheelC = new Wheel();
}

void draw() {
  background(255);

  pushMatrix();
  wheelA.display(180, 180, 0.02); 
  popMatrix();

  pushMatrix();
  wheelB.display(620, 180, 0.03); 
  popMatrix();

  pushMatrix();
  wheelC.display(400, 620, 0.01);  
  popMatrix();
}

class Wheel { 
  float posX;
  float posY;
  float ang= 0;
  float aVel;

  float xA;
  float yA;
  float xB;
  float yB;
  float xC;
  float yC;

  // The constructor defined
  Wheel() {
  }

  void  display(float posX, float posY, float aVel) {
    xA = 0;
    yA = 80;
    xB= 55;
    yB = -55;
    xC = -55;    
    yC = -55;


    //Wheel - big circle
    stroke(0);
    strokeWeight(3);
    fill(255);
    ellipseMode(CENTER);
    translate(posX, posY);  
    rotate(ang);
    ellipse(0, 0, 200, 200);

    //small circles
    ellipse(xA, yA, 10, 10);
    ellipse(xB, yB, 10, 10);
    ellipse(xC, yC, 10, 10);

    ang=ang+aVel;

  }
}
</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>Pool ball jitters when hit by the cue ball</title>
      <link>https://forum.processing.org/two/discussion/19543/pool-ball-jitters-when-hit-by-the-cue-ball</link>
      <pubDate>Mon, 05 Dec 2016 22:54:25 +0000</pubDate>
      <dc:creator>BootlegFireworks</dc:creator>
      <guid isPermaLink="false">19543@/two/discussions</guid>
      <description><![CDATA[<p>I am new to Processing and new to programming in general and I am making a pool table as an end of term project. I managed to get the cue ball to hit another ball, but the cue ball only hits successfully once. When I try to hit the cue ball again, whenever it passes by the original position of the ball it jitters.</p>

<p>`class Point
{
  float x, y;
  Point (float a, float b)
  {
    x = a;
    y = b;
  }
  Point()
  {
    x = 0;
    y = 0;
  }
}</p>

<p>class Ball
{
  float rad;
  Point center;
  Point contact_point;
  color col;
  Point speed;</p>

<p>int[][] ballColor =
    {
    {255, 255, 255}, // 0 = cue ball
    {255, 255, 0}, //1 ball, 9 ball
    {0, 0, 255}, //2 ball, 10 ball
    {255, 0, 0}, //3 ball, 11 ball
    {128, 0, 128}, //4 ball, 12 ball
    {255, 165, 0}, //5 ball, 13 ball
    {0, 150, 0}, //6 ball, 14 ball
    {153, 76, 0}, //7 ball, 15 ball
    {50, 50, 50} //8 ball
  };</p>

<p>Ball (float x, float y, float r, int i)
  {
    speed = new Point();
    center = new Point (x, y);
    contact_point = new Point (mouseX, mouseY);
    rad = r;
    col = color (ballColor[i][0], ballColor[i][1], ballColor[i][2]);
  }
  void circle()
  {
    ellipse(0, 0, rad, rad);
  }
}</p>

<p>class Stick
{
  Point start_p;
  Point end_p;
  color col;
  int length;
  float distance;</p>

<p>Stick (float x1, float y1, float x2, float y2, int R, int G, int B, int L)
  {
    length = L;
    start_p = new Point (x1, y1);
    end_p = new Point (x2, y2);
    col = color(R, G, B);
    distance = 0;
  }
}</p>

<p>class Table
{
  Ball [] b_arr;
  Ball [] stripe_arr;
  Ball cue_ball;
  Stick st;
  Ball eightBall;</p>

<p>Table()
  {
    cue_ball = new Ball (500, 500, 15, 0);
    eightBall = new Ball (1060, 500, 15, 8);</p>

<pre><code>float [][] position = 
  {
  {1000, 500}, 
  {1030, 484}, 
  {1030, 516}, 
  {1060, 469}, 
  //{1060, 500},
  {1060, 531}, 
  {1090, 484}, 
  {1090, 516}, 
};

b_arr = new Ball [7];
for (int i = 0; i &lt; b_arr.length; i++)
{
  b_arr[i] = new Ball (position[i][0], position[i][1], 15, i+1);
  //println(b_arr[i]);
}

//stripe_arr =
st = new Stick (cue_ball.center.x, cue_ball.center.y, mouseX, mouseY, 0, 0, 0, 50);
</code></pre>

<p>}
}</p>

<p>PImage floor, background;
float deceleration = 0.89;
int power, gamemode = 0;
Table table = new Table();
boolean ballInHole = false, ballWall = false, cueBall = false;</p>

<p>import ddf.minim.*;
AudioSnippet wall, cue, ballBounce;
Minim minim;</p>

<p>void setup()
{
  size(1500, 1000);
  floor = loadImage("floor.jpg");
  ellipseMode(CENTER);
  frameRate(24);</p>

<p>minim = new Minim(this);
  wall = minim.loadSnippet("sport_miniture_snooker_pool_ball_hit_table_wall.mp3");
  cue = minim.loadSnippet("sport_pool_snooker_cue_strike_ball.mp3");
}</p>

<p>void draw()
{
  if (gamemode == 0)
  {
    background(255);
    fill(0);
    textSize(200);
    text("BILLIARDS", 100, 300);
    textSize(24);
    text("INSTRUCTIONS", 100, 400);
    text("Press arrow keys to change power of shot", 100, 450);
    text("Press Shift in order to choose the direction of shot", 100, 500);
    text("Click to shoot", 100, 550);
    textSize(50);
    text("Click anywhere to continue", 400, 900);
  }</p>

<p>if (gamemode == 2)
  {
    image(floor, 0, 0);
    table.st.end_p.x = mouseX;
    table.st.end_p.y = mouseY;
    poolTable();
    drawCueBall();
    tempBall(0);
    //drawBalls();
    //drawEightBall();
    drawPole();
    checkBall();
    //checkBallCollision(table.b_arr, table.cue_ball);
    checkCueBallCollision (table.b_arr);</p>

<pre><code>power = powerControl(power);
DisplayPower();

if (ballWall == true)
{
  wall.rewind();
  wall.play();
  ballWall = false;
}

if (cueBall == true)
{
  cue.rewind();
  cue.play();
  cueBall = false;
}
</code></pre>

<p>}</p>

<p>if (gamemode == 3)
  {
    background(255);
    textSize(200);
    fill(0);
    text("GAME OVER", 200, 500);
    textSize(50);
    text("The cue ball went into the pocket!", 300, 750);
    //text("Click Anywhere to continue", 400, 900);
  }
}</p>

<p>void mousePressed()
{
  if (gamemode == 0)
    gamemode = 1;
  if (gamemode == 1)
    gamemode = 2;
  if (gamemode == 3)
  {
    gamemode = 0;
    ballInHole = false;
  }
}</p>

<p>void drawCueBall()
{
  stroke(0);
  strokeWeight(1);
  fill(table.cue_ball.col);
  ellipse(table.cue_ball.center.x, table.cue_ball.center.y, table.cue_ball.rad<em>2, table.cue_ball.rad</em>2);
  table.cue_ball.center.x += table.cue_ball.speed.x;
  table.st.start_p.x += table.cue_ball.speed.x;
  table.cue_ball.center.y += table.cue_ball.speed.y;
  table.st.start_p.y += table.cue_ball.speed.y;
  table.cue_ball.speed.x *= deceleration;
  table.cue_ball.speed.y *= deceleration;</p>

<p>if (ballInHole == false)
    checkBoundaryCollision(table.cue_ball);</p>

<p>if (abs(table.cue_ball.speed.x) &lt; 0.1)
  {
    table.cue_ball.speed.x = 0;
  }
  if (abs(table.cue_ball.speed.y) &lt; 0.1)
  {
    table.cue_ball.speed.y = 0;
  }
}</p>

<p>void drawEightBall()
{
  stroke(0);
  strokeWeight(1);
  fill(table.eightBall.col);
  ellipse(table.eightBall.center.x, table.eightBall.center.y, table.eightBall.rad<em>2, table.eightBall.rad</em>2);
}</p>

<p>void tempBall (int i)
{
  stroke(0);
  strokeWeight(1);
  fill(table.b_arr[i].col);
  ellipse(table.b_arr[i].center.x, table.b_arr[i].center.y, table.b_arr[i].rad<em>2, table.b_arr[i].rad</em>2);</p>

<p>table.b_arr[i].center.x += table.b_arr[i].speed.x;
  table.b_arr[i].center.y += table.b_arr[i].speed.y;
  table.b_arr[i].speed.x *= deceleration;
  table.b_arr[i].speed.y *= deceleration;</p>

<p>checkBoundaryCollision(table.b_arr[i]);</p>

<p>if (abs(table.b_arr[i].speed.x) &lt; 0.1)
    table.b_arr[i].speed.x = 0;
  if (abs(table.b_arr[i].speed.y) &lt; 0.1)
    table.b_arr[i].speed.y = 0;
}</p>

<p>void drawBalls()
{
  stroke(0);
  strokeWeight(1);
  for (int i = 0; i &lt; table.b_arr.length; i++)
  {
    fill(table.b_arr[i].col);
    ellipse(table.b_arr[i].center.x, table.b_arr[i].center.y, table.b_arr[i].rad<em>2, table.b_arr[i].rad</em>2);
  }
}</p>

<p>void drawPole()
{
  if (keyCode == SHIFT &amp;&amp; table.cue_ball.speed.x == 0 &amp;&amp; table.cue_ball.speed.y == 0)
  {
    PVector mouse = new PVector (mouseX, mouseY);
    PVector center = new PVector (table.cue_ball.center.x, table.cue_ball.center.y);
    mouse.sub(center);
    mouse.normalize();
    mouse.mult(150);
    translate (center.x, center.y);
    stroke(table.st.col);
    line(0, 0, mouse.x, mouse.y);
    mouse.mult(0.067);
    stroke(255);
    strokeWeight(5);
    line(0, 0, mouse.x, mouse.y);
  }
}</p>

<p>void mouseClicked()
{
  if (table.cue_ball.speed.x == 0 &amp;&amp; table.cue_ball.speed.y == 0)
  {
    PVector mouse = new PVector(mouseX, mouseY);
    PVector center = new PVector(table.cue_ball.center.x, table.cue_ball.center.y);
    mouse.sub(center);
    println(mouse); //temporary
    mouse.normalize();
    mouse.mult(power);
    table.cue_ball.speed.x = -mouse.x;
    table.cue_ball.speed.y = -mouse.y;
    if (table.cue_ball.speed.x != 0 || table.cue_ball.speed.y != 0)
      cueBall = true;
  }
}</p>

<p>int powerControl (int power)
{
  if (keyCode == UP)
  {
    if (power &lt;= 95)
    {
      power += 5;
    }
    keyCode = LEFT;
  }
  if (keyCode == DOWN)
  {
    if (power &gt;= 5)
    { 
      power -= 5;
    }
    keyCode = LEFT;
  }
  return power;
}</p>

<p>void DisplayPower()
{
  textSize(24);
  fill(0);
  text("Power", 750, 32);
  text(power, 750, 64);
}</p>

<p>void poolTable()
{
  int a = 1000, b = a/2, c = width/2, d = height/2;
  rectMode(CENTER);</p>

<p>fill(102, 51, 0);
  rect(c, d, a+125, b+125, 32, 32, 32, 32);</p>

<p>fill(0, 200, 0);
  rect(c, d, a, b);</p>

<p>fill(255);
  for (int i = 0; i &lt;= a; i += (a/8))
  {
    if (i != a/2 &amp;&amp; 1 != 0 &amp;&amp; i != a)
    {
      ellipse((c-b) + i, (d/2)-23, 10, 10);
      ellipse((c-b) + i, (d+(d/2))+23, 10, 10);
    }
  }
  for (int j = 0; j &lt;= b; j += (b/4))
  {
    if (j != 0 &amp;&amp; j != b)
    {
      ellipse((c-b)-23, (d/2)+j, 10, 10);
      ellipse((c+b)+23, (d/2)+j, 10, 10);
    }
  }</p>

<p>fill(0);
  for (int k = 0; k &lt;= a; k += (a/2))
  {
    ellipse((c-b) + k, d/2, 64, 64);
    ellipse((c-b) + k, d+(d/2), 64, 64);
  }
}</p>

<p>void checkBoundaryCollision(Ball ball)
{
  if (ball.center.x &gt; 1250-ball.rad)
  {
    ball.center.x = 1250-ball.rad;
    ball.speed.x *= -1;<br />
    ballWall = true;
  } else if (table.cue_ball.center.x &lt; 250+table.cue_ball.rad)
  {
    ball.center.x = 250+ball.rad;
    ball.speed.x *=-1;
    ballWall = true;
  } else if (table.cue_ball.center.y &gt; 750-table.cue_ball.rad)
  {
    ball.center.y = 750-ball.rad;
    ball.speed.y *= -1;
    ballWall = true;
  } else if (table.cue_ball.center.y &lt; 250+table.cue_ball.rad)
  {
    ball.center.y = 250+ball.rad;
    ball.speed.y *= -1;
    ballWall = true;
  }
}</p>

<p>void checkBall()
{
  if (table.cue_ball.center.x &lt; 250+24 &amp;&amp; table.cue_ball.center.y &lt; 250+24)
  {
    ballInHole = true;
    if (ballInHole == true)
    {
      table.cue_ball.speed.x = 0;
      table.cue_ball.speed.y = 0;
      table.cue_ball.center.x = 250;
      table.cue_ball.center.y = 250;
      gamemode = 3;
    }
  }
  if ((table.cue_ball.center.x &gt; 750-24 &amp;&amp; table.cue_ball.center.x &lt; 750+24) &amp;&amp; table.cue_ball.center.y &lt; 250+24)
  {
    ballInHole = true;
    if (ballInHole == true)
    {
      table.cue_ball.speed.x = 0;
      table.cue_ball.speed.y = 0;
      table.cue_ball.center.x = 750;
      table.cue_ball.center.y = 250;
      gamemode = 3;
    }
  }
  if (table.cue_ball.center.x &gt; 1250-24 &amp;&amp; table.cue_ball.center.y &lt; 250+24)
  {
    ballInHole = true;
    if (ballInHole == true)
    {
      table.cue_ball.speed.x = 0;
      table.cue_ball.speed.y = 0;
      table.cue_ball.center.x = 1250;
      table.cue_ball.center.y = 250;
      gamemode = 3;
    }
  }
  if (table.cue_ball.center.x &lt; 250+24 &amp;&amp; table.cue_ball.center.y &gt; 750-24)
  {
    ballInHole = true;
    if (ballInHole == true)
    {
      table.cue_ball.speed.x = 0;
      table.cue_ball.speed.y = 0;
      table.cue_ball.center.x = 250;
      table.cue_ball.center.y = 750;
      gamemode = 3;
    }
  }
  if ((table.cue_ball.center.x &gt; 750-24 &amp;&amp; table.cue_ball.center.x &lt; 750+24) &amp;&amp; table.cue_ball.center.y &gt; 750-24)
  {
    ballInHole = true;
    if (ballInHole == true)
    {
      table.cue_ball.speed.x = 0;
      table.cue_ball.speed.y = 0;
      table.cue_ball.center.x = 750;
      table.cue_ball.center.y = 750;
      gamemode = 3;
    }
  }
  if (table.cue_ball.center.x &gt; 1250-24 &amp;&amp; table.cue_ball.center.y &gt; 750-24)
  {
    ballInHole = true;
    if (ballInHole == true)
    {
      table.cue_ball.speed.x = 0;
      table.cue_ball.speed.y = 0;
      table.cue_ball.center.x = 1250;
      table.cue_ball.center.y = 750;
      gamemode = 3;
    }
  }
}</p>

<p>float distance (float a, float b)
{
  float temp = sqrt(sq(a)+sq(b));
  return temp;
}</p>

<p>void checkCueBallCollision(Ball[] ball)
{
  for (int i = 0; i &lt; ball.length; i++)
  {
    float difx = ball[i].center.x - table.cue_ball.center.x;
    float dify = ball[i].center.y - table.cue_ball.center.y;
    float totalDistance = distance (difx, dify);
    if (table.cue_ball.speed.x == 0 &amp;&amp; table.cue_ball.speed.y == 0)
      println(totalDistance);</p>

<pre><code>if (totalDistance &lt;= table.cue_ball.rad*2+ball[i].rad*2)
{
  float knum = ((table.cue_ball.speed.x-ball[i].speed.x)*(table.cue_ball.center.x-ball[i].center.x))+((table.cue_ball.speed.y-ball[i].speed.y)*(table.cue_ball.center.y-ball[i].center.y));
  float kden = sq(table.cue_ball.center.x-ball[i].center.x)+sq(table.cue_ball.center.y-ball[i].center.y);
  float k = knum/kden;
  float x = table.cue_ball.center.x-ball[i].center.x;
  float y = table.cue_ball.center.y-ball[i].center.y;

  table.cue_ball.speed.x -= (k*x);
  table.cue_ball.speed.y -= (k*y);
  ball[i].speed.x += (k*x);
  ball[i].speed.y += (k*y);
}
</code></pre>

<p>}
}`</p>

<p>On an unrelated note, did I format this code right on this forum?</p>
]]></description>
   </item>
   <item>
      <title>Can any one show me why this code does not work as I think it should (creating ellipses in a class)</title>
      <link>https://forum.processing.org/two/discussion/19301/can-any-one-show-me-why-this-code-does-not-work-as-i-think-it-should-creating-ellipses-in-a-class</link>
      <pubDate>Sat, 26 Nov 2016 04:05:42 +0000</pubDate>
      <dc:creator>dneilan</dc:creator>
      <guid isPermaLink="false">19301@/two/discussions</guid>
      <description><![CDATA[<pre><code>        `int LedColor[][] = { { #ffcccd, #ff1924 },            // Red off and on
                             { #bbffb5, #14ff00 },            //Green off and on
                             { #fce9a9, #ffc400 } };          // Yellow off and on
        int LabelVpos = 165;
        String LedName[] = { "Active", "Green", "Yellow" };
        int LedHpos[] = {60, 120, 180, 240, 320, 380};
        int LedVpos = 140;

        LEDs Led;

        void setup() {
          surface.setTitle("LED class test");
          size(476, 300);

          Led = new LEDs(0,"Red",LedColor[0],1,LedHpos[0],LedVpos,20,20); 
        }

        void draw() {
          delay(2000);
          Led.LEDon();
          delay(2000);
          Led.LEDoff();

        }


        class LEDs {

          String LEDname;
          int LEDid;
          int LEDcolor[]; // receiving an passed array
          int LEDstat;
          int Horiz;
          int Vert;
          int Wide;
          int Tall;

         LEDs(int A,String B,int C[],int D,int E,int F,int G,int H) {
            LEDid = A;
            LEDname = B;
            LEDcolor = C;   // LEDcolor[0]=off - LEDcolor[1]=on
            LEDstat = D;
            Horiz = E;
            Vert = F;
            Wide = G;
            Tall = H;
            if(LEDstat==1) fill(LEDcolor[1]); else fill(LEDcolor[0]);
            ellipse(Horiz,Vert,Wide,Tall);
          }

        void LEDswitch() {
          println("switch");
            if(LEDstat==1) { 
              LEDstat=0;
              fill(LEDcolor[0]);
              ellipse(Horiz,Vert,Wide,Tall);
              return;
            }
              LEDstat=1;
              fill(LEDcolor[1]);  
              ellipse(Horiz,Vert,Wide,Tall);
          }

         void LEDon() {                                     // Turn on LED
             LEDstat=1; 
             fill(LEDcolor[1]);
             ellipse(Horiz,Vert,Wide,Tall);
             println("on");
            }

         void LEDoff() {                                     // Turn off LED
             LEDstat=0;
              fill(LEDcolor[0]);
              ellipse(Horiz,Vert,Wide,Tall);
             println("off");
            }                           

         int LEDstatus() { return(LEDstat); }                   // Return LED status

        }`
</code></pre>
]]></description>
   </item>
   <item>
      <title>pass a global variable to a class</title>
      <link>https://forum.processing.org/two/discussion/19187/pass-a-global-variable-to-a-class</link>
      <pubDate>Mon, 21 Nov 2016 11:30:28 +0000</pubDate>
      <dc:creator>digitalmartyn</dc:creator>
      <guid isPermaLink="false">19187@/two/discussions</guid>
      <description><![CDATA[<p>I have a particle system over a live video feed with an implementation of OpenCV OpticalFlow.</p>

<p>I need the particles to be affected by opticalflow values - i.e. move left and a right with the person in the video.</p>

<p>I can get the variable aveFlow.x each frame but can't run it through to each particle and change the vector x</p>

<p>full code:</p>

<pre><code>import gab.opencv.*;
import processing.video.*;
import java.awt.*;

//Movie video;
Capture video;
OpenCV opencv;

// DECLARE
ArrayList ballCollection;

float numBalls = 2;

void setup() {
  size(640, 480);
  video = new Capture(this, width/4, height/4);
  opencv = new OpenCV(this, width/4, height/4);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  //INITIALIZE
  ballCollection = new ArrayList();

  video.start();
}

void draw() {
  //background(0);
  //scale(2);
  opencv.loadImage(video);
  opencv.calculateOpticalFlow();

  image(video, 0, 0, width, height);

  //translate(video.width, 0);
  stroke(255, 0, 0);
  //opencv.drawOpticalFlow();

  PVector aveFlow = opencv.getAverageFlow();
  int flowScale = 100;
  //float optX = aveFlow.x;

  stroke(255);
  strokeWeight(2);
  //line(video.width/2, video.height/2, video.width/2 + aveFlow.x*flowScale, video.height/2 + aveFlow.y*flowScale);
  line(width/2, height/2, width/2 + aveFlow.x*flowScale, height/2 + aveFlow.y*flowScale);

  //numberofballs
  if (ballCollection.size()&lt;numBalls) {
    Ball myBall = new Ball(random(width), 0);
    ballCollection.add(myBall);
  }  

  //CALL FUNCTIONALITY
  for (int i = 0; i &lt; ballCollection.size(); i++) {
    Ball mb = (Ball) ballCollection.get(i);
    mb.run();
  }
}

//void movieEvent(Movie m) {
//  m.read();
//}

void captureEvent(Capture c) {
  c.read();
}

class Ball {

  //global variables
  float x=0;
  float y=0;
  //float speedX = random(-2, 2);
  float speedX = 0;

  float speedY = random(-2, 2);

  //float optY = 0;

  //constructor
  Ball(float _x, float _y) {
    x= _x;
    y= _y;
    //optX = _optX*50;
  }

  //functions
  void run() {
    if (y&lt;height) {
      display();
      move();
      //bounce();
      gravity();
      opticalFlow();
    }
  }

  void opticalFlow() {
    //speedX += aveFlow.x*flowScale;
  }

  void gravity() {
    speedY += 0.01;
  }

  void bounce() {
    if (x &gt; width ) {
      speedX *= -1;
    }
    if (x &lt; 0 ) {
      speedX *= -1;
    }
    if (y &gt; height ) {
      speedY *= -1;
    }
    if (y &lt; 0 ) {
      speedY *= -1;
    }
  }

  void move() {
    x += speedX;
    y += speedY;
  }

  void display() {
    ellipse (x, y, 20, 20);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Parameters in classes</title>
      <link>https://forum.processing.org/two/discussion/19024/parameters-in-classes</link>
      <pubDate>Mon, 14 Nov 2016 03:02:31 +0000</pubDate>
      <dc:creator>Anachronist</dc:creator>
      <guid isPermaLink="false">19024@/two/discussions</guid>
      <description><![CDATA[<p>So my code is below. The assignment was to make 3 bouncing balls, the intent was to do it with one class and float x,y,size, and color. I tried our book, online tutorials, and trial and error. But every time I used a parameter, the ball(s) wouldn't move. I had to relent and use 3 different classes. Could anyone explain how to do it with just 1+parameters? (I only included the code for one class to keep it simple, but you get the idea). Thanks in advance.</p>

<pre><code>Ball b;
Ball2 b2;
Ball3 b3;
void setup(){
  size(600,700);
  background(255);
  b= new Ball();
  b2= new Ball2();
  b3= new Ball3();
}//end setup

void draw(){
  background(255);
  b.ball();
  b.bounce();
  b2.ball2();
  b2.bounce();
  b3.ball3();
  b3.bounce();
}//end draw

class Ball{
  float x=50;
  float y=0;
  float gravity=0.1;
  float speed=0;
  void ball(){
    fill (0,0,255);
    ellipse(x,y,50,50);
  }//end constructor
  void bounce(){
    y=y+speed;
    speed=speed+gravity;
    if (y&gt;height){
    speed=speed*(-0.95);
    y=height;
   }//end if  
  }//end bounce
}//end class
</code></pre>
]]></description>
   </item>
   <item>
      <title>"Class does not exists" but it does!</title>
      <link>https://forum.processing.org/two/discussion/17243/class-does-not-exists-but-it-does</link>
      <pubDate>Tue, 21 Jun 2016 07:09:36 +0000</pubDate>
      <dc:creator>fwentz</dc:creator>
      <guid isPermaLink="false">17243@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I looked around but didn't find any help, maybe it isn't even Processing itself but my Mac. I noticed this after pulling a project from git but it also occurs when creating a new sketch.</p>

<p>Processing does not find any classes I create. Neither if they are in a separate tab nor if I write them down in the main file.
My old sketches work though, it seems to only to affect new sketches.</p>

<p>I am using a Mac with the latest OS (10.11.5), latest Java and latest Processing. I tried reinstalling Processing and restarting my Mac.</p>

<p>Hope someone can help me.</p>

<p><em>removed the image as it was not helping</em></p>
]]></description>
   </item>
   <item>
      <title>Creating an infinite number of instances of the same class.</title>
      <link>https://forum.processing.org/two/discussion/16827/creating-an-infinite-number-of-instances-of-the-same-class</link>
      <pubDate>Wed, 25 May 2016 18:11:43 +0000</pubDate>
      <dc:creator>Jhdgkss</dc:creator>
      <guid isPermaLink="false">16827@/two/discussions</guid>
      <description><![CDATA[<p>Hi there.
First of I am new here so hello.
I am working on a bit of code that requires a large number of classes.
Is it possible to generate new instances of a class while the program is running?
I.e. is it possible too create an infinite number of instances of the same class?
I am sure that there is a solution too this problem, how does processing generate particles for example.</p>

<p>Thanks John</p>
]]></description>
   </item>
   <item>
      <title>How do I do another two levels?</title>
      <link>https://forum.processing.org/two/discussion/16431/how-do-i-do-another-two-levels</link>
      <pubDate>Thu, 05 May 2016 00:53:55 +0000</pubDate>
      <dc:creator>DanaH</dc:creator>
      <guid isPermaLink="false">16431@/two/discussions</guid>
      <description><![CDATA[<p>Is it possible to add another two levels to this code?</p>

<p>`Peces[] pecesValores = new Peces[30]; //Por -clases-
PImage inicio;
PImage fondo;
PImage pez1;
int puntos = 0;
int MejorPuntaje = 0;
boolean introScreen = true; //Saber si es verdadero o falso, crea dos estados del juego.
int savedTime; //Se almacena el tiempo en el juego.
int totalTime = 15000; // El tiempo que queremos que dure el juego por segundos.
float x1;
float y1;
float easing = .7;</p>

<p>void setup() {
  size(504, 502); //Tamaño de pantalla.
  smooth(); //Suavizar los trazos.
  // Cargar las imagenes.
  inicio = loadImage("totalfish.jpg");
  fondo = loadImage("fondo1.jpg");
  pez1 = loadImage("pez1ya.png");
  textSize(20);
  savedTime = millis();</p>

<p>for (int p=0; p&lt;pecesValores.length; p++) {
    pecesValores[p] = new Peces(250, 20, 30);
  }
}</p>

<p>void draw() {
  background(#FFFFF2);</p>

<p>// Caña de pesca.
  float targetX = mouseX; 
  float x = targetX - x1;
  x1 += x * easing;</p>

<p>float targetY = mouseY;
  float y = targetY - y1;
  y1 += y * easing;</p>

<p>rectMode(CENTER);
  ellipseMode(CENTER);
  ellipse(x1, y1, 10, 10);
  rect(x1, y1-250, 1, 500);</p>

<p>//Esta parte es para que se abra la pantalla del juego al pulsar la tecla z.
  if (keyPressed) {
    if (key == 'z' || key == 'Z') {
      introScreen = false;
    }
  }
  if (introScreen==true) {
    background(#E7F005);
    text("Press z", 160, 440);
    text("Ùltima puntuación: "+MejorPuntaje, 160, 460);
  } else {
    for (int p=0; p&lt;pecesValores.length; p++) {
      pecesValores[p].speed();
      pecesValores[p].display();
      pecesValores[p].colision();
      pecesValores[p].pezcar();
      pecesValores[p].puntaje();
      pecesValores[p].GameOver();
    }
  }
}</p>

<p>class Peces {
  float x;
  float y;
  float t;
  float xSpeed;
  float ySpeed;</p>

<p>Peces(float posiX, float posiY, float tam) {
    x = posiX;
    y = posiY;
    t = tam;</p>

<pre><code>xSpeed = random(-5, 5); //Los peces tienen velocidades random, se moverán de diferentes formas.
ySpeed = random(-5, 5);
</code></pre>

<p>}</p>

<p>void speed() { //Estagblecer parámetros de lo que genera el movimiento.
    x += xSpeed;
    y += ySpeed; //Al generarse los peces, cada uno se va a mover en x y y de acuerdo a la velocidad de -5 y 5.
  }
  void display() {
    ellipse(x,y,30,30);
  }
  void colision() {
    if ((x&lt;0) || (x&gt;width-t)) {<br />
      xSpeed = -xSpeed; //Se invierte la velocidad en x.
    }
    if ((y&lt;0) || (y&gt;width-t)) {
      ySpeed = -ySpeed; //Se invierte la velocidad en y.
    }
  }</p>

<p>void pezcar() {
    if (mousePressed) {
      float distance = dist(mouseX, mouseY, x, y); //Calcula una distancia entre dos objetos y dice si se están "tocando", o sea, posicionandose.
      if (distance&lt;t) {
        x=-1000;
        xSpeed = 0;
        ySpeed = 0;
        puntos++;
        MejorPuntaje = max(puntos, MejorPuntaje); // "max" Establece un valor máximo entre dos valores.
      }
    }
  }
  void puntaje() { //Almacenar textos del puntaje.
    fill(#050000);
    text("Puntos: "+puntos, 10, 20);
  }
  void GameOver() {
    int passedTime = millis() - savedTime; //Es el tiempo que transcurre.</p>

<pre><code>if (passedTime &gt; totalTime) {
  introScreen = true;
  puntos = 0;
  savedTime = millis();
  for (int p=0; p&lt;pecesValores.length; p++) {
    pecesValores[p] = new Peces(250, 20, 30);
  }
  //Para que se resetee el puntaje.
}
</code></pre>

<p>}
}</p>

<p>//Para hacer el otro pez, el class contiene los void.`</p>
]]></description>
   </item>
   </channel>
</rss>