<?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 ellipsemode() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=ellipsemode%28%29</link>
      <pubDate>Sun, 08 Aug 2021 19:58:46 +0000</pubDate>
         <description>Tagged with ellipsemode() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedellipsemode%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Send value to a object</title>
      <link>https://forum.processing.org/two/discussion/28037/send-value-to-a-object</link>
      <pubDate>Sun, 03 Jun 2018 00:49:55 +0000</pubDate>
      <dc:creator>vjjv</dc:creator>
      <guid isPermaLink="false">28037@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody. I`ve a problem:</p>

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

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

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

<pre><code>import controlP5.*;

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


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


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

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

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

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

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

void mousePressed() {

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

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

class Sphere {

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

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

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

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

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

  ControlP5 cp5;

  int vertices = 50;
  float ss;


  Slider abc;


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

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


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

  void draw() {
    background(0);

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

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

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do zoom relative to mouse?</title>
      <link>https://forum.processing.org/two/discussion/27927/how-do-zoom-relative-to-mouse</link>
      <pubDate>Sun, 06 May 2018 22:25:47 +0000</pubDate>
      <dc:creator>Vanthex</dc:creator>
      <guid isPermaLink="false">27927@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>My sketch basically draws objects from left to right. I implemented a zoom function with the mouse wheel with translation but it doesn't zoom relative to my mouse.</p>

<p>Any ideas how to fix this?</p>

<pre><code>float x = 100;
int y = 200;
int gap = 50;
float scale = 1.0;

ArrayList&lt;Body&gt; bodies = new ArrayList&lt;Body&gt;();

class Body {

  String name;
  int size;

  Body(String name, int size) {
    this.name = name;
    this.size = size;
  }

  float getSize() {
    return this.size * scale;
  }

  void draw(float x) {
    fill(255);
    noStroke();
    ellipse(x, y - this.getSize() / 2, this.getSize(), this.getSize());
    noFill();
    stroke(255,0,255);
    rect(x, y - this.getSize() / 2, this.getSize(), this.getSize());
  }
}

float getOffset() {
  int offset = 0;
  for (Body body : bodies) {
    offset += body.getSize();
    offset += gap;
  } 
  return offset;
}

void setup() {
  size(1600, 900);
  ellipseMode(CORNER);

  bodies.add(new Body("test", 100));
  bodies.add(new Body("2", 400));
  bodies.add(new Body("big", 1000));
}

void draw() {
  fill(0);
  noStroke();
  rect(0, 0, 1600, 900);

  pushMatrix();
  translate(x, y);

  float drawX = x;
  for (Body body : bodies) {
    body.draw(drawX);
    drawX += (body.getSize() + gap);
    fill(255,255,0);
    noStroke();
    rect(drawX - gap, y - gap / 2, gap, gap);
  }

  popMatrix();
}

void keyPressed() {
  float prevOffset = getOffset();
  if (keyCode == UP) {
    scale *= 1.1;
    float newOffset = getOffset();
    //x -= (newOffset - prevOffset) / 2;
    x -= mouseX * 0.1;
  } else if (keyCode == DOWN) {
    scale *= 0.9;
    float newOffset = getOffset();
    //x += (prevOffset - newOffset) / 2;
    x += mouseX * 0.1;
  } else if (keyCode == LEFT) {
    x += 10;
  } else if (keyCode == RIGHT) {
    x -= 10;
  }
  if (scale &lt; 0) {
    scale = 0;
  }
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  if (e &lt; 0) {
    scale *= 1.1;
  } else if (e &gt; 0) {
    scale *= 0.9;
  }
  x -= event.getCount() * mouseX / 1000;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to zoom Image?</title>
      <link>https://forum.processing.org/two/discussion/23110/how-to-zoom-image</link>
      <pubDate>Sun, 18 Jun 2017 07:43:19 +0000</pubDate>
      <dc:creator>JJJJJJ</dc:creator>
      <guid isPermaLink="false">23110@/two/discussions</guid>
      <description><![CDATA[<pre><code>int x = 120;
int y = 60;
int radius = 12;

void setup() {
  size(240, 120);
  ellipseMode(RADIUS);
}

void draw() {
  background(204);
  float d = dist(mouseX, mouseY, x, y);
  if (d &lt; radius) {
    radius++;
    fill(0);
  } else {
    fill(255);
  }
  ellipse(x, y, radius, radius);
}
</code></pre>

<p>Like this example,
how to zoom image?</p>
]]></description>
   </item>
   <item>
      <title>How would I be able to move a circle in different directions when the mouse is pressed?</title>
      <link>https://forum.processing.org/two/discussion/21511/how-would-i-be-able-to-move-a-circle-in-different-directions-when-the-mouse-is-pressed</link>
      <pubDate>Tue, 21 Mar 2017 01:09:18 +0000</pubDate>
      <dc:creator>harleylapuz</dc:creator>
      <guid isPermaLink="false">21511@/two/discussions</guid>
      <description><![CDATA[<p>Hey I am creating a simple application to move the a circle in multiple direction when the mouse is pressed. For example, I clicked the lower left part of the circle, so then it would move up going to the right. Same as if I tap the ball on the lower right, it would move the ball going up to the left.</p>

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

<hr />

<p>float ballX = 200;
float ballY = 0;
float h = 50;</p>

<p>float speedY = 2;</p>

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

<p>size(400,400);</p>

<p>ellipseMode(CORNER);</p>

<p>}</p>

<p>void draw() {
  background(0);
  fill(255);</p>

<p>ellipse(ballX, ballY, h,h);</p>

<p>speedY = speedY + 0.5;</p>

<p>ballY = ballY + speedY;</p>

<p>if (ballY &gt; height - h) 
  {
    ballY = height - h;
  //  speedY = speedY * -0.9;
  }</p>

<p>if (ballY &lt;=0)
  {
    speedY = -speedY;
  }
}</p>

<p>void mousePressed()
{
 speedY=-10;
}</p>

<hr />

<p>Thanks for any help in advance :D</p>
]]></description>
   </item>
   <item>
      <title>Does the PDF library only work in ellipseMode(CENTER)? Can you change it somehow</title>
      <link>https://forum.processing.org/two/discussion/21380/does-the-pdf-library-only-work-in-ellipsemode-center-can-you-change-it-somehow</link>
      <pubDate>Mon, 13 Mar 2017 17:39:05 +0000</pubDate>
      <dc:creator>jbounds6</dc:creator>
      <guid isPermaLink="false">21380@/two/discussions</guid>
      <description><![CDATA[<p>Hey I am trying to make a program that uses some vectors and I am having troubles using the ellipseMode(RADIUS)
with the PDF library it seems to change the draw function back to ellipseMode(CENTER). Or at least it appears to be doing that, any information would be helpful.</p>

<blockquote class="Quote">
  <p>import processing.pdf.*;</p>
  
  <p>boolean record;</p>
  
  <p>void setup() {<br />
    size(500, 500);<br />
    noSmooth();<br />
    noFill();<br />
    ellipseMode(RADIUS); // I believe this is where my problem is(?)<br />
  }</p>
  
  <p>void draw() {<br />
    if (record) {<br />
      beginRecord(PDF, "NotTheSameImage.pdf");<br />
    }</p>
  
  <p>arc(200, 200, 50, 50, 0, 40 * (TAU/64));<br />
    arc(200, 200, 20, 20, 40 * (TAU/64), TAU);<br />
    rect(10, 10, 400, 400);<br />
    ray(200,200,3 * TAU/4,50);<br />
  </p>
  
  <p>if (record) {<br />
      endRecord<img src="" alt="" />();<br />
      record = false;<br />
    }<br />
  }</p>
  
  <p>void keyPressed() {<br />
    // Use a key press so that it doesn't make a million files<br />
    if (key == 'r') {<br />
      record = true;<br />
    }<br />
  }</p>
  
  <p>void ray(float x, float y, float rad, float dist) {<br />
    float xx = x + (dist * cos(rad));<br />
    float yy = y + (dist * sin(rad));<br />
    line(x, y, xx, yy);<br />
  }</p>
</blockquote>

<p>P.S. I need to re-read the section on posting code sorry about the lack of indentions.</p>
]]></description>
   </item>
   <item>
      <title>What's wrong with my hue gradient?</title>
      <link>https://forum.processing.org/two/discussion/19913/what-s-wrong-with-my-hue-gradient</link>
      <pubDate>Sun, 25 Dec 2016 11:31:00 +0000</pubDate>
      <dc:creator>appas</dc:creator>
      <guid isPermaLink="false">19913@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I'm trying to make a gradient around a circle, so that one rotation around the circle would be one lap of the hue wheel. It seems to work fine when I try it out as a linear gradient (the rects in the following code), but I can't get it to wrap around the circle.</p>

<pre><code>    void setup()
    {
      colorMode(HSB, 360, 100, 100);
      background(100, 0, 100);
      ellipseMode(RADIUS);
      noFill();
      frame.setResizable(true);
    }

    void draw()
    {
      float R = 200;
      clear();
      for (int i = 0; i &lt; 360; i++)
      {
        stroke(i, 100, 100);
        rect(5*i, 50, 5, 5);
      }
      pushMatrix();
      translate(width/2, height/2);
      strokeWeight(5);
      int FINE = 360*3;
      for (int i = 0; i &lt; FINE; i++) {
        println(i + ", " + float(i)/FINE*360);
        stroke(float(i)/FINE*360, 100, 100);
        arc(-R/2, 0, R/2, R/2, 0, PI);
        rotate(2*PI*float(i)/FINE);  
      }
      popMatrix();
      //strokes
      strokeWeight(4);
      stroke(0, 0, 0);
      ellipse(width/2, height/2, R, R);
      translate(width/2, height/2);
      arc(-R/2, 0, R/2, R/2, 0, PI);
      rotate(2*PI/3);
      arc(-R/2, 0, R/2, R/2, 0, PI);
      rotate(2*PI/3);
      arc(-R/2, 0, R/2, R/2, 0, PI);

    }
</code></pre>

<p><img src="http://i.imgur.com/OyNJFWn.png" alt="" /></p>
]]></description>
   </item>
   <item>
      <title>Adding gravity or falling coins to my Connect 4 Game</title>
      <link>https://forum.processing.org/two/discussion/19744/adding-gravity-or-falling-coins-to-my-connect-4-game</link>
      <pubDate>Wed, 14 Dec 2016 14:33:16 +0000</pubDate>
      <dc:creator>Dobbo</dc:creator>
      <guid isPermaLink="false">19744@/two/discussions</guid>
      <description><![CDATA[<p><em>DELETED</em></p>
]]></description>
   </item>
   <item>
      <title>How do I get p5.js to remove certain objects within my program (e.g. button)?</title>
      <link>https://forum.processing.org/two/discussion/18789/how-do-i-get-p5-js-to-remove-certain-objects-within-my-program-e-g-button</link>
      <pubDate>Sun, 30 Oct 2016 15:13:12 +0000</pubDate>
      <dc:creator>ish2nv</dc:creator>
      <guid isPermaLink="false">18789@/two/discussions</guid>
      <description><![CDATA[<p>var img;
var buttonhover;
var buttonhover2;
var header = ["Pop the bubble game"]
var buttontext = ["START","HELP"]</p>

<p>function preload() {
  img = loadImage("bubbleimg.png")</p>

<p>}
function setup() {
  createCanvas(600,620)</p>

<p>}</p>

<p>function draw() {
 image(img,0,0)</p>

<p>img.resize(600,620)</p>

<p>stroke(0)
  strokeWeight(4);
  textFont("stencil")
  fill(255);
   textSize(46);
text(header[0],46,59);</p>

<p>ellipseMode(CENTER);
  stroke(5,0,0)
  fill(55,120,260)
  strokeWeight(5);</p>

<p>var space = dist(mouseX, mouseY,296,194)
  if (space&lt;100 ) {
    buttonhover = true;}
    else {
      buttonhover = false;
    }</p>

<pre><code>if (buttonhover === true) {
  fill(0,255,0);}

ellipse(300,200,200,200);
stroke(0)
  textFont("stencil")
</code></pre>

<p>strokeWeight(4);
  fill(255);
   textSize(45);
text(buttontext[0],230,211);</p>

<pre><code>draw2()
</code></pre>

<p>}</p>

<p>function draw2() {</p>

<p>ellipseMode(CENTER);
  stroke(5,0,0)
  fill(55,120,260)
  strokeWeight(5);</p>

<p>var space = dist(mouseX, mouseY,296,450)
  if (space&lt;100 ) {
    buttonhover2 = true;}
    else {
      buttonhover2 = false;
    }</p>

<pre><code>if (buttonhover2 === true) {
  fill(255,0,0);
}

ellipse(300,450,200,200);

stroke(0)
  textFont("stencil")
</code></pre>

<p>strokeWeight(4);
  fill(255);
   textSize(45);
text(buttontext[1],244,464);</p>

<p>}</p>

<p>function mousePressed() {
  if (buttonhover == true) {
   draw3()
  }</p>

<p>}</p>

<p>function draw3 () {
  remove()
}</p>
]]></description>
   </item>
   <item>
      <title>fix problems with setting cursor to an image; image pixely, contains colors that it shouldn't</title>
      <link>https://forum.processing.org/two/discussion/14498/fix-problems-with-setting-cursor-to-an-image-image-pixely-contains-colors-that-it-shouldn-t</link>
      <pubDate>Sat, 16 Jan 2016 16:29:19 +0000</pubDate>
      <dc:creator>Bodhidharma482</dc:creator>
      <guid isPermaLink="false">14498@/two/discussions</guid>
      <description><![CDATA[<p>Heey guys,</p>

<p>My program shows the picture I set the cursor to be, but the picture is pixely, contains colors that aren't in the original picture and gets distorted at times. Since, apparantly the mouse isn't visible when you take a screenshot I don't know how to show you. I thought I would just show you most of the code, since I'm a beginner and might leave stuff out that actually causes the problem.</p>

<pre><code>//Intialize picture aimingpoint
PImage aimingpoint;

//define class object
hare one;

//define boolean for pulling gun
boolean pull;

int width = 600;
int height = 600;

float middleX = width/2;
float middleY = height/2;

//Define values for position and size hunters
float xPosHunter1 = 0;
float yPosHunter1 = 0;
float xPosHunter2 = -200;
float yPosHunter2 = 0;
int radHunter = 10;

int deadlyDistance = 150;

//Define animalspeed
int animalSize = 10;
float hareSpeed = 1;

void setup() {
  size(width, height);
  smooth();
  //Define hare one
  one = new hare(100, 1);
  aimingpoint = loadImage("aimingpoint.png");
}

void draw() {
  //calculate angle between the line that goes fromthe origin to the mouse and postive x-axis
  //I posted a question about this on forum.processing.org: <a href="https://forum.processing.org/two/discussion/14433/rotate-line-in-such-a-way-that-one-point-is-in-the-middle-of-the-canvas-and-other-follows-the-mouse#latest" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/14433/rotate-line-in-such-a-way-that-one-point-is-in-the-middle-of-the-canvas-and-other-follows-the-mouse#latest</a>

  background(255);

  //Move origing to the middle of the canvas.
  translate(0.5 * width, 0.5 * height);

  //Flip the canvas in the x-axis so that the axis system is like a 'normal' one.
  scale(1, -1);

  //draw mouse as aimingpoint
  //<a href="http://stackoverflow.com/questions/12539840/change-mouse-cursor-in-processing" target="_blank" rel="nofollow">http://stackoverflow.com/questions/12539840/change-mouse-cursor-in-processing</a>
  cursor(aimingpoint, 16, 16);
  //  ellipseMode(CENTER);
  //  ellipse(mouseX, mouseY, 5, 5);
  //  noFill();
  //  ellipse(mouseX, mouseY, 30, 30);

     if ((keyPressed == true &amp;&amp; key == 'p' || key == 'P') &amp;&amp; mousePressed == true &amp;&amp; distanceOriginMouse() &lt;= deadlyDistance){
     background(0, 255, 0);
  } 
    else if ((keyPressed == true &amp;&amp; key == 'p' || key == 'P') &amp;&amp; mousePressed == true &amp;&amp; distanceOriginMouse() &gt; 0.5 * deadlyDistance){
      background(255,0,0);
  }

  //draw gun when p is pressed
  if (keyPressed == true &amp;&amp; key == 'p' || key == 'P') {
    pushMatrix();
    rotate(-angleMouse());
    line(0, 0, 40, 0);
    popMatrix();
  }

  ellipseMode(RADIUS);
  //draw deadly
  noFill();
  ellipse(0,0,deadlyDistance, deadlyDistance); 

  fill(255);
  //Draw Hare1
  one.show();
  one.move();

  pushMatrix();
  rotate(radians(135));
  line(0,0,500,0);
  popMatrix();

  stroke(0);
  //Hunter1
  ellipse(xPosHunter1, yPosHunter1, radHunter, radHunter);
  //Hunter2
  ellipse(xPosHunter2, yPosHunter2, radHunter, radHunter);
  //if (mousePressed == true &amp;&amp; mouseButton == LEFT &amp;&amp; mouseX &gt;=) {
}
</code></pre>

<p>The picture is 16 x 16 pixels, so that probably causes the pixelyness, but if I take a larger picture, processing won't show the entire picture anymore.</p>

<p>Hope you guys can help out!</p>

<p>-Bodhidharma482</p>
]]></description>
   </item>
   <item>
      <title>Nullpointer exception Array</title>
      <link>https://forum.processing.org/two/discussion/16106/nullpointer-exception-array</link>
      <pubDate>Tue, 19 Apr 2016 20:00:44 +0000</pubDate>
      <dc:creator>shirinmalina</dc:creator>
      <guid isPermaLink="false">16106@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody, 
I am pretty new to processing, and just ran into the following problem</p>

<p>I am importing values from a json file, and when I run the following code I get a Nullponter Exception error.
I googled and tried different things, but unfortunately I cannot solve the problem.
I am greatful for any help, here is my code:</p>

<pre><code>JSONObject json;
int max;
void setup() {
  size(841,594);

JSONArray jsonArray = loadJSONArray("january_2016.json");
JSONObject jsonObject = jsonArray.getJSONObject(0); 
JSONObject maxTemperature = json.getJSONObject("Max Temperature");
int max = maxTemperature.getInt("max");

  print(max);
}

void draw(){
//Max Temperature  
  textAlign(CENTER);
  text("Max Temperature",841/4, 594/2+100);

  ellipseMode(RADIUS);
  ellipse(841/4, 594/2, max, max); // max
  ellipse(841/4, 594/2, max, max); //avg
  ellipse(841/4, 594/2, max, max); //min

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Changing numbers in the text through the use of variables.</title>
      <link>https://forum.processing.org/two/discussion/15845/changing-numbers-in-the-text-through-the-use-of-variables</link>
      <pubDate>Tue, 05 Apr 2016 00:26:28 +0000</pubDate>
      <dc:creator>74204916</dc:creator>
      <guid isPermaLink="false">15845@/two/discussions</guid>
      <description><![CDATA[<p>I try to put a variable in the text () to have a changing number for the scores{}, but the program debugger gives me an error.</p>

<p>Please help.</p>

<p>float lX;
float lY;
float lW;
float lH;
float lS;
float rX;
float rY;
float rW;
float rH;
float rS;
boolean up, down;
boolean v1, h1;
boolean started = true;
int mate = 9;
int xPos;
int yPos;
int incDec =4;<br />
int bVal=0;
int gVal=0;
int rVal=250;
int w = 40;
int h = 40;
int speedx = 2;
int speedy = 3;</p>

<p>void setup(){
  //I h8 U Java!!!
  size (600,600); 
  rectMode (CENTER);
  ellipseMode (CENTER);
  lX = 30;
  lY = height/2;
  lW = 40;
  lH=100;
  lS = 5;
  rX=570;
  rY = height/2;
  rW = 40;
  rH=100;
  rS=5;
  xPos = 250;
  yPos = 250;
}</p>

<p>void draw (){
  background(0);
  drawlpad();
  drawrpad();
  movelpad();
  moverpad();
  drawball();
  moveball();
  restrictpaddle();
  contactpad();
  contactr();
}</p>

<p>void drawlpad(){
  fill(0,250,0);
  rect(lX,lY,lW,lH);
}</p>

<p>void drawrpad(){
  fill(0,0,250);
  rect(rX,rY,rW,rH);
}</p>

<p>void movelpad(){
if (up){
  lY=lY-lS;
}
if (down){
  lY=lY+lS;
}
}</p>

<p>void moverpad(){
  if(v1){
    rY=rY-rS;
  }
  if(h1){
    rY=rY+lS;
  }
}</p>

<p>void drawball(){<br />
fill(rVal,gVal,bVal);
ellipse(xPos,yPos,w,h);          //bsize
}</p>

<p>void moveball(){
  xPos = xPos +incDec;</p>

<p>if (xPos &gt;600-w/2){
    incDec=-incDec;
    setup();
}
if (xPos&lt;10+w/2){
      incDec=-incDec;
      setup();
}
    yPos = yPos + mate;
if (yPos&gt;600){
      mate=-mate;</p>

<p>}
if (yPos &lt; 0){
      mate=-mate;</p>

<pre><code>}
</code></pre>

<p>}</p>

<p>void restrictpaddle(){
if (lY - lH/2 &lt; 0) {
    lY = lY + lS;
}
  if (lY + lH/2 &gt; height) {
    lY= lY - lS;
}
  if (rY - rH/2 &lt; 0) {
    rY = rY + rS;
}
  if (rY + rH/2 &gt; height) {
    rY = rY - rS;
}
}</p>

<p>void contactpad() {
  if (xPos-w/2 &lt; lX + lW/2 &amp;&amp; yPos-h/2 &lt; lY +lH/2 &amp;&amp; yPos +lH/2 &gt; lY - lH/2){
    if (incDec&lt;0){
      incDec = -incDec;
}
}
}</p>

<p>void contactr() {
  if(xPos+w/2 &gt;  rX - rW/2 &amp;&amp; yPos-h/2 &lt; rY + rH/2 &amp;&amp; yPos+h/2 &gt; rY -rH/2){
    if (incDec&gt;0){
       incDec = -incDec;
    }
  }
}</p>

<p>void keyPressed(){
if(started = true){
if (key=='w' || key=='W'){
   up=true;
}
if (key=='s'||key=='S'){
    down=true;
}
if (keyCode==UP){
    v1=true;
}
if(keyCode ==DOWN){
    h1=true;
}
}
}</p>

<p>void keyReleased(){
if (key=='w' || key=='W'){
    up=false;
}</p>

<p>if (key=='s'||key=='S'){
  down=false;
}</p>

<p>if (keyCode==UP){
  v1=false;
}</p>

<p>if(keyCode ==DOWN){
  h1=false;
}
}</p>

<p>void mousePressed (){   //for change color
  int temp;
  temp=bVal;
  bVal=gVal;
  gVal=rVal;
  rVal=temp;
}</p>

<p>/*void scores () {
fill(255);
text (scorer1, 100, 50);
text (scorer, width-100,50);
}</p>
]]></description>
   </item>
   <item>
      <title>rotate an ellipse without rotating code below? (new to this)</title>
      <link>https://forum.processing.org/two/discussion/14712/rotate-an-ellipse-without-rotating-code-below-new-to-this</link>
      <pubDate>Mon, 01 Feb 2016 18:08:07 +0000</pubDate>
      <dc:creator>gregdaleg</dc:creator>
      <guid isPermaLink="false">14712@/two/discussions</guid>
      <description><![CDATA[<p>I want to rotate the above ellipse without rotating the ellipse beneath it. I know that i can put the first set of code below the other but there has to be another way right? I know its messy :)</p>

<pre><code>fill(77, 43, 39, 255);
rotate(radians(30));
ellipseMode(CORNER);
ellipse(90, 90, 50, 80);

ellipseMode(CENTER);
fill(225, 206, 183);
arc(200, 160, 200, 200, -PI, 0);
</code></pre>
]]></description>
   </item>
   <item>
      <title>Thanks</title>
      <link>https://forum.processing.org/two/discussion/14189/thanks</link>
      <pubDate>Wed, 30 Dec 2015 00:37:36 +0000</pubDate>
      <dc:creator>cabaks</dc:creator>
      <guid isPermaLink="false">14189@/two/discussions</guid>
      <description><![CDATA[<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>v0.4.20 translate() bug?</title>
      <link>https://forum.processing.org/two/discussion/14133/v0-4-20-translate-bug</link>
      <pubDate>Thu, 24 Dec 2015 02:36:54 +0000</pubDate>
      <dc:creator>schuelaw</dc:creator>
      <guid isPermaLink="false">14133@/two/discussions</guid>
      <description><![CDATA[<p>Not sure if you want bug reports here, or if this even is a bug.  In the <a rel="nofollow" href="http://p5js.org/reference/#/p5/translate">reference for the translate function</a>, it states that translations are cumulative, but that they are reset after each draw().  This is certainly the behavior that I was seeing up until I updated my lib this afternoon to v0.4.20.  This <a rel="nofollow" href="http://carrot.whitman.edu/P5JS/Test-0.4.20/">simple sketch</a>, indicates that the translations are cumulative even between draw()'s (i.e. the translation is not reset after each draw()).</p>

<pre><code>var i;
function setup() {
 // put setup code here
 createCanvas(600,600);
 ellipseMode(RADIUS);
 i=0;
}

function draw() {
 translate(i,i);
 ellipse(0,0,20,20);
 i+=1;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Various subclasses instanciated in an Arraylist?</title>
      <link>https://forum.processing.org/two/discussion/13648/various-subclasses-instanciated-in-an-arraylist</link>
      <pubDate>Wed, 25 Nov 2015 12:52:45 +0000</pubDate>
      <dc:creator>luxregina</dc:creator>
      <guid isPermaLink="false">13648@/two/discussions</guid>
      <description><![CDATA[<p>Hello! I'm relatively new to Processing and OOP.</p>

<p>I'm currently developing a shoot'em'up and I'm using Arraylists to 'control' my enemies. So far, everything has been working fine.
I'm starting to get problems when I try to mix different sub-classes in the same arraylist. I can access the methods of all my childs, but I keep getting the fields of my parent.</p>

<p>I've done a fair amount of research, but without success: for clarity's sake, instead of posting my code that is quite lengthy, here's an example of what I'm trying to achieve:</p>

<pre>
ArrayList shapes = new ArrayList();
 
void setup() {
  shapes.add(new Rect());
  shapes.add(new Circle());
 
  for(Shape s : shapes) {
    if(s instanceof Rect) {
      println("type is rect");
      s.show();
      println("my ID is: "+s.ID);
    } 
    else if (s instanceof Circle) {
      println("type is circle");
      s.display();
      println("my ID is: "+s.ID);
    }
  }
}
 
 
class Rect extends Shape {
  String ID="I'm a rectangle";
  void show(){
   rect(5,5,10,10); 
  }
}
 
class Circle extends Shape {
  String ID="I'm a circle";
  void display(){
   ellipseMode(CORNER);
    ellipse(20,5,10,10); 
  }
}
 
class Shape {
  String ID="I'm nothing";
  void display(){};
  void show(){};
}
</pre>

<p>So, 2 questions:</p>

<p>1) how can I access the ID value of my subclass? I keep reaching for its parent value? I'm obviously missing something important...
2) I've read that using 'instanceof' is a bad bad thing: can someone explain why, and what I should do instead?</p>

<p>Thanks by advance!</p>
]]></description>
   </item>
   <item>
      <title>Collision &amp; Colors</title>
      <link>https://forum.processing.org/two/discussion/10680/collision-colors</link>
      <pubDate>Thu, 07 May 2015 00:39:20 +0000</pubDate>
      <dc:creator>Rareware0192</dc:creator>
      <guid isPermaLink="false">10680@/two/discussions</guid>
      <description><![CDATA[<p>I wanted to change the aspects of a previous game I posted on here before but this time I built it again from the ground up (code below) and managed to get classes working this time.</p>

<p>I wanted to have it so that when a ball connects with a colored box, the ball changes to the color of the box (e.g. ball touches blue box, ball becomes blue, then if it touches green box, blue ball becomes green, etc.)</p>

<p>This is the code I have:</p>

<pre><code>Ball b1 = new Ball();
Ball b2 = new Ball();
Ball b3 = new Ball();
Ball b4 = new Ball();

Chamber c1 = new Chamber();
Chamber c2 = new Chamber();
Chamber c3 = new Chamber();
Chamber c4 = new Chamber();
Chamber c5 = new Chamber();
Chamber c6 = new Chamber();

void setup() {
  size(640, 440);
  smooth();
  b2.ballY = 80;
  b2.ballXV = 3;
  b2.ballYV = 5;
  b3.ballX = 100;
  b3.ballY = 150;
  b3.ballYV = 5;
  b4.ballX = 300;
  b4.ballY = 300;
  b4.ballXV = 6;

  //red
  c1.chamberX = 0;
  c1.chamberY = 0;
  //blue
  c2.chamberX = 600;
  c2.chamberY = 0;
  //green
  c3.chamberX = 0;
  c3.chamberY = 400;
  //purple
  c4.chamberX = 600;
  c4.chamberY = 400;
  //yellow
  c5.chamberX = 300;
  c5.chamberY = 0;
  //cyan
  c6.chamberX = 300;
  c6.chamberY = 400;
}

void draw() {
  background(240);
  b1.drawAndMoveBall();
  b2.drawAndMoveBall();
  b3.drawAndMoveBall();
  b4.drawAndMoveBall();
  //red
  c1.drawChamber1();
  //blue
  c2.drawChamber2();
  //green
  c3.drawChamber3();
  //purple
  c4.drawChamber4();
  //yellow
  c5.drawChamber5();
  //cyan
  c6.drawChamber6();
}

class Ball {

  int ballX = 50;
  int ballY = 50;
  int ballXV = 4;
  int ballYV = 2;
  int ballDimension = 25;
  int ballRadius = ballDimension/2;
  color c;

  void drawAndMoveBall() {
    ballX += ballXV;
    ballY += ballYV;

    //checks to see if ball touches edges and bounces back
    if (ballX + ballRadius &gt; width) {
      ballXV = -ballXV;
    }
    if (ballX - ballRadius &lt; 0) {
      ballXV = -ballXV;
    }
    if (ballY + ballRadius &gt; height) {
      ballYV = -ballYV;
    }
    if (ballY - ballRadius &lt; 0) {
      ballYV = -ballYV;
    }

    c = color(255);
    strokeWeight(2);
    fill(c);
    ellipse(ballX, ballY, ballDimension, ballDimension);
  }
}

class Chamber {

  int chamberX = 0;
  int chamberY = 0;

  void drawChamber1() {
    fill(255, 0, 0);
    rect(chamberX, chamberY, 40, 40);
  }

  void drawChamber2() {
    fill(0, 255, 0);
    rect(chamberX, chamberY, 40, 40);
  }

  void drawChamber3() {
    fill(0, 0, 255);
    rect(chamberX, chamberY, 40, 40);
  }

  void drawChamber4() {
    fill(255, 0, 255);
    rect(chamberX, chamberY, 40, 40);
  }

  void drawChamber5() {
    fill(255, 255, 0);
    rect(chamberX, chamberY, 40, 40);
  }

  void drawChamber6() {
    fill(0, 255, 255);
    rect(chamberX, chamberY, 40, 40);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>HELP ME PLEASE! How to make an array of shapes callable individually?</title>
      <link>https://forum.processing.org/two/discussion/3664/help-me-please-how-to-make-an-array-of-shapes-callable-individually</link>
      <pubDate>Wed, 12 Mar 2014 23:34:54 +0000</pubDate>
      <dc:creator>misty</dc:creator>
      <guid isPermaLink="false">3664@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>I am trying to create a matrix of circle (5 rows x 9 columns), and I need to make each of this circle callable so that I can interact with each circle individually. The objective of my program is to be able to change the color of the circle based on a certain input.
For example when countA =1, I need to be able to change only the grid[0][0] to light yellow, and when count A = 2, I need to be able to change the grid[0][0] to yellow. But when count A = 3 instead of changing grid[0][0], I need to change the grid[0][1] to light yellow, and so on so forth.</p>

<p>My question is:
1. How do I make all these circles callable individually.
2. How do I color all these circles individually.</p>

<p>Below is my code so far:</p>

<pre><code>    class Bubbles{
      int x, y, d;

      Bubbles(int tempX, int tempY, int tempD){
        x = tempX;
        y = tempY;
        d = tempD;
      }

      void display(){
        ellipse(x,y,d,d);
        ellipseMode(CORNER);
      }

      void fColors(int hex){
        fill(hex);
      }
    }

    color[] colors =
    {
      #A2C1C9,
      #0E7796,
      #6FFCCF,
      #FD7169,
      #C95F80

    };

    final int x_axis = 3840/10;
    final int y_axis = 2112/10;
    final int diameter = 340/10;
    final int gap = 75/10;

    Bubbles[][] grid;

    int cols = 9;
    int rows = 5;

    void setup() {
      size(x_axis, y_axis);
      background(255);
      grid = new Bubbles[cols][rows];
      for (int i = 0; i &lt; cols; i++) {
        for (int j = 0; j &lt; rows; j++) {
          grid[i][j] = new Bubbles(i*(x_axis/cols),j*(y_axis/rows),diameter);
        }
      }
    }

    void draw() {
      for (int i = 0; i &lt; cols; i++) {
        for (int j = 0; j &lt; rows; j++) {
          grid[i][j].display();
        }
      }  
     // grid[0][0].fColors(colors[0]);

    }
</code></pre>
]]></description>
   </item>
   </channel>
</rss>