<?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 #bounce - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23bounce</link>
      <pubDate>Sun, 08 Aug 2021 17:52:36 +0000</pubDate>
         <description>Tagged with #bounce - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23bounce/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Help with spheres bouncing off each other</title>
      <link>https://forum.processing.org/two/discussion/27948/help-with-spheres-bouncing-off-each-other</link>
      <pubDate>Wed, 09 May 2018 21:26:56 +0000</pubDate>
      <dc:creator>Mojo</dc:creator>
      <guid isPermaLink="false">27948@/two/discussions</guid>
      <description><![CDATA[<p>Hey everyone, 
I created this sketch for a bunch of emojis orbiting around one emoji and I am trying to make them bounce off each other when they touch, can someone please help me on how to do that?
Here is the code I am using:</p>

<pre><code>// importing the Peasy Cam library
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;

// declaring the main emoji
Planet sun;
//declairing the Peasy Cam 
PeasyCam cam;
// declaring the PImage function
PImage img;
// declairing the the texture
PImage[] textures = new PImage[7];
// declaring the particle system

void setup() {

  size(displayWidth, displayHeight, P3D);


  img = loadImage("1.jpg");
  textures[0]= loadImage("2.jpg");
  textures[1]= loadImage("3.jpg");
  textures[2]= loadImage("4.jpg");
  textures[3]= loadImage("5.jpg");
  textures[4]= loadImage("6.jpg");
  textures[5]= loadImage("7.jpg");
  cam = new PeasyCam(this, 500);
  sun = new Planet (100, 0, 0, img);
  sun.spawnMoons(10, 4);
}

void draw() {

  background(0);
  lights();
  ambientLight(129, 62, 0);
  //translate(displayWidth, displayHeight);
  noFill();
  stroke(255);
  strokeWeight(1);
  //rotateY(frameCount/200.0);
  box(4000);

  lights();
  ambientLight(129, 62, 0);
  directionalLight(51, 102, 126, 0, -1, 0);
  spotLight(255, 0, 0, width/2, height/2, 400, 0, 0, -1, PI/4, 2);

  sun.show();
  sun.orbit();
}

class Planet {
  float radius;
  float angle;
  float distance;
  Planet [] planets;
  float orbitSpeed;
  PVector v;
  PShape globe;
  float mass=1;


  Planet(float r, float d, float o, PImage img ) {
    v = PVector. random3D();
    radius = r;
    angle = random(20);
    distance= d;
    v.mult(distance);
    orbitSpeed = o;

    noStroke();
    noFill();
    globe = createShape(SPHERE, radius);
    globe.setTexture(img);
  }
  void spawnMoons(int total, int level) {
    planets = new Planet[total];
    for (int  i = 0; i&lt;planets.length; i++) {

      float r= random(level*10);

      float d = random(100, 1000);

      float o = random (-0.01, 0.02);

      int index = int(random (textures.length));
      planets[i]= new Planet (r, d, o, textures[index]);

      if (level&lt;1) {
        int num = int(random(0, 5));
        planets[i].spawnMoons(num, level+1);
      }
    }
  }

  void orbit() {
    angle =  angle + orbitSpeed/mass;
    if (planets !=null) {
      for (int  i = 0; i&lt;planets.length; i++) {
        planets[i].orbit();
      }
    }
  }
  void show() {
    pushMatrix();
    noStroke();
    PVector v2 = new PVector(1, 0, 1);
    PVector p = v.cross(v2);
    rotate (angle, p.x, p.y, p.z);

    translate(v.x, v.y, v.z);
    shape(globe);
    if (planets !=null) {
      for (int  i = 0; i&lt;planets.length; i++) {
        planets[i].show();
      }
    }
    popMatrix();
  }
  void bounce() {
  }
}
</code></pre>

<p>I would really appreciate your help
Thanks</p>
]]></description>
   </item>
   <item>
      <title>How can adjust the directions?</title>
      <link>https://forum.processing.org/two/discussion/27075/how-can-adjust-the-directions</link>
      <pubDate>Fri, 23 Mar 2018 10:09:48 +0000</pubDate>
      <dc:creator>moaaz</dc:creator>
      <guid isPermaLink="false">27075@/two/discussions</guid>
      <description><![CDATA[<p>Hi everybody, 
I am new to processing language programming, I have an example of bouncing the ball and when executing the program the system gave me (sometimes) wrong directions as output:
Ex. if xmove = 1and ymove =1the default direction = south_East</p>

<p>the code :</p>

<p>// initial position for our circle</p>

<p>float circle_x = 300;</p>

<p>float circle_y = 20;</p>

<p>// how much to move the circle on each frame
float move_x = 2;</p>

<p>float move_y = -2;</p>

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

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

<p>stroke(#D60DFF);</p>

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

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

<p>background(#21EA73);</p>

<p>ellipse(circle_x, circle_y, 40, 40);</p>

<p>circle_x = circle_x + move_x;</p>

<p>circle_y = circle_y + move_y;</p>

<p>if(circle_x &gt; width) {</p>

<pre><code>circle_x = width;

move_x = -move_x;

println(" north_east");
</code></pre>

<p>}</p>

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

<pre><code>circle_y = height;

move_y = -move_y;

println(" south_west");
</code></pre>

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

<pre><code>circle_x = 0;

move_x = -move_x;

println(" north_west");
</code></pre>

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

<pre><code>circle_y = 0;

move_y = -move_y;

println(" south_east");
</code></pre>

<p>}
}</p>
]]></description>
   </item>
   <item>
      <title>how to change balls that are falling from big to a smaller size gradually  ?</title>
      <link>https://forum.processing.org/two/discussion/26908/how-to-change-balls-that-are-falling-from-big-to-a-smaller-size-gradually</link>
      <pubDate>Sun, 18 Mar 2018 17:44:11 +0000</pubDate>
      <dc:creator>michyg</dc:creator>
      <guid isPermaLink="false">26908@/two/discussions</guid>
      <description><![CDATA[<p>help</p>

<p>(from here: <a href="https://forum.processing.org/two/discussion/26841/falling-balls" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/26841/falling-balls</a> )</p>
]]></description>
   </item>
   <item>
      <title>How can I get multiple iterations of the same object to independently change colour?</title>
      <link>https://forum.processing.org/two/discussion/26724/how-can-i-get-multiple-iterations-of-the-same-object-to-independently-change-colour</link>
      <pubDate>Fri, 09 Mar 2018 03:48:55 +0000</pubDate>
      <dc:creator>petlil</dc:creator>
      <guid isPermaLink="false">26724@/two/discussions</guid>
      <description><![CDATA[<p>I'm an absolute beginner with Processing. I'm attempting to create a simple window with squares that cruise around and bounce off the sides, and change colour when they collide with the sides. I've got the moving and bouncing, but for a reason I can't determine, every single square changes colour when one of them collides with the side. I assume this has something to do with the way Processing's fill() method operates. Can someone help me get the squares to change colour independently (i.e. retain their own colour when another square strikes the side)? Code below. Thank you!</p>

<p>//<strong>main code</strong></p>

<pre><code>int number = 100;
BallBounce[] balls = new BallBounce[number];

void setup() {
size(500,500);
frameRate(100);
for(int i = 0; i&lt;number; i++)
{
balls[i] = new BallBounce();
}
}

void draw(){
background(255);
for(int i = 0; i&lt;number; i++)
{
balls[i].update();
}
}
</code></pre>

<p>//<strong>square object</strong></p>

<pre><code>class BallBounce {

 //length and height of the squares
 float x = 20;
 float y = 20;

//x and y locations of the squares
float xPos = random(0,width-x);
float yPos = random(0,height-x);

//direction and velocity of squares
//(negatives determine which direction)
float xDirection = random(-1,1);
float yDirection = random(-1,1);


void update() {
  rect (xPos,yPos,x,y);
  noStroke();

float randomColour1 = random(50,255);
float randomColour2 = random(0,255);
float randomColour3 = random(254,255);

//updating the original position by the user-defined
//distance or travel (speed)
xPos = xPos + xDirection;
yPos = yPos + yDirection;

//telling the square to reverse its x or y value
//if its edge collides with the edge of the screen
//and change colour when it does
if(xPos &gt; width-x)
{
  xDirection = -1;
  fill(randomColour1, randomColour2, randomColour3);
}

if(xPos &lt; 0)
{
  xDirection = 1;
  fill(randomColour1, randomColour2, randomColour3);
}

if(yPos &gt; width-x)
{
  yDirection = -.5;
  fill(randomColour1, randomColour2, randomColour3);
}

if(yPos &lt; 0)
{
  yDirection = .5;
  fill(randomColour1, randomColour2, randomColour3);
}
}

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Problems with the figure´s movements - buttons.</title>
      <link>https://forum.processing.org/two/discussion/26572/problems-with-the-figure-s-movements-buttons</link>
      <pubDate>Wed, 28 Feb 2018 07:04:12 +0000</pubDate>
      <dc:creator>DDv2FF</dc:creator>
      <guid isPermaLink="false">26572@/two/discussions</guid>
      <description><![CDATA[<p>Hi, i made this program with buttons that change the size and the speed of the figure among other things. The problem is that if I increase the size of the figure when it is close from any edge, it stop. I think the problem is related with the way I wrote the "move" method, but I dont know how to fix it. Can anyone help me ?<br />
I should comment the functions of the end, but I didn´t so you can see what functions do properly.</p>

<pre><code>let canvas;
//canvas interaction
let Color;
let bgColor;
let x = 200;
let y = 200;
let button = [];
let buttoName = ["Ellipse Color", "backgroundColor", "Size+", "Size-", "Speed++", "Speed--","ChangeToRect", "Reset", "ShacoCreator"];
let buttonFunction = [
{ heh : function changeColor(){
    theColor = color(random(255), random(255), random(255));} },

{ heh : function changeBGCol(){
        bgColor = color(random(255), random(255), random(255));} },

{ heh : function sizePLUS(){
    piece.s+= 5;} },

{ heh : function sizeMINUS(){
    piece.s-= 5;} },

{ heh : function speedPLUS(){
    if(piece.yspeed &lt; 0){
        piece.yspeed-= 5;
    } else if(piece.yspeed &gt; 0){
        piece.yspeed+= 5;
    }
    if(piece.xspeed &lt; 0){
        piece.xspeed-= 5;
    } else if(piece.xspeed &gt; 0){
        piece.xspeed+= 5;
    }} },

{ heh : function speedMINUS(){
    if(piece.yspeed &lt; 0){
        piece.yspeed+= 5;
    } else if(piece.yspeed &gt; 0){
        piece.yspeed-= 5;
    }
    if(piece.xspeed &lt; 0){
        piece.xspeed+= 5;
    } else if(piece.xspeed &gt; 0){
        piece.xspeed-= 5;
    }} },

{ heh : function changeFig(){
    piece.state = !piece.state;} },

{ heh : function Reset(){
    piece.x = 250;
    piece.y = 200;
    piece.xspeed = 3;
    piece.yspeed = 3;
    piece.s = 25;
    piece.state = false;} },

{ heh : function CreateShac(){
    Shaco = createElement("p", "Shaco");
    Shaco.position(random(1000),random(1000));} } ];

let piece;
let state = false;

let Shaco;



function setup() {
    canvas = createCanvas(500, 400);

//Canvas Interaction
    theColor = color(100, 0, 100);
    bgColor = color(200, 0, 120);
    piece = new Figure(x, y, 25);
    for(var i = 0; i &lt; buttoName.length; i++){
        button[i] = createButton(buttoName[i]);
        button[i].position(510, 150 + i * 25);
        button[i].mousePressed(buttonFunction[i].heh);
    }

}

function draw() {
    background(bgColor);
    fill(theColor);
    piece.show();
    piece.move();
}


class Figure {
    constructor(x, y, s){
        this.x = x;
        this.y = y;
        this.s = s;
        this.xspeed = 3;
        this.yspeed = 3;
        this.state = false;
    }
    show(){
        if(this.state){
            rectMode(CENTER)
            rect(this.x, this.y, this.s * 2, this.s * 2);
        } else { ellipse(this.x, this.y, this.s * 2 ) }
    }
    move(){
        this.x+= this.xspeed;
        this.y+= this.yspeed;
        if(this.x &lt; this.s || this.x &gt; width - this.s){
            this.xspeed*= -1;
        }
        if(this.y &lt; this.s || this.y &gt; height - this.s){
            this.yspeed*= -1;
        }
    }
}
</code></pre>

<p>Thanks !!</p>
]]></description>
   </item>
   <item>
      <title>How do I make my bouncing ball gradually get bigger?</title>
      <link>https://forum.processing.org/two/discussion/26540/how-do-i-make-my-bouncing-ball-gradually-get-bigger</link>
      <pubDate>Mon, 26 Feb 2018 16:14:53 +0000</pubDate>
      <dc:creator>hellomaryland</dc:creator>
      <guid isPermaLink="false">26540@/two/discussions</guid>
      <description><![CDATA[<p>I'm having a hard time</p>
]]></description>
   </item>
   <item>
      <title>Bouncing ball losing height without drag force?</title>
      <link>https://forum.processing.org/two/discussion/25871/bouncing-ball-losing-height-without-drag-force</link>
      <pubDate>Mon, 08 Jan 2018 19:13:10 +0000</pubDate>
      <dc:creator>SquareUnit</dc:creator>
      <guid isPermaLink="false">25871@/two/discussions</guid>
      <description><![CDATA[<p>Hello world!</p>

<p>I'm currently going through the 9 chapters of Nature of Code and I have an issue with one exercise.
In the "2.4 Intro to friction forces" video, I did everything properly, understood the script and changed
it to a single dropping ball with constant gravity being the only factor changing the ball PVector acceleration. 
Strangely, in both my and Daniel Shiffman sketch, the bouncing ball lose max height at each 2 rebound. He does
not adress this issue.</p>

<p>This is very weird and should not happen?!? since there is nothing that should make the ball lose
velocity on each 2 rebounds. My guess is that there is something I don't know about the edgeBounce()
I made and how it interact with the window borders, maybe chipping away a pixel of height in 
the process of reverting the ball velocity when it touches the ground.</p>

<p>The code below work properly, but I think the fault reside somewhere in it
or in how it interact with the ball.</p>

<pre><code>void edgeBounce() {
  if (location.x &gt; width) {
    location.x = width;
    velocity.x *= -1;
  }
  if (location.x &lt; 0) {
    location.x = 0;
    velocity.x *= -1;
  }
  if (location.y &gt; height) {
    location.y = height;
    velocity.y *= -1;
  }
  if (location.y &lt; 0) {
    location.y = 0;
    velocity.y *= -1;
  }
</code></pre>

<p>Can anyone help me on this? Why is the ball losing velocity at each secound bounce?
Google drive link to my sketch, you can visualise the problem yourself!</p>

<p><a href="https://drive.google.com/open?id=1yrXe4HzpJoNk_WAZoUy24jcRY_TjHli4" target="_blank" rel="nofollow">https://drive.google.com/open?id=1yrXe4HzpJoNk_WAZoUy24jcRY_TjHli4</a></p>

<p>Any help very appreciated!</p>
]]></description>
   </item>
   <item>
      <title>How can i get the ball to bounce properly</title>
      <link>https://forum.processing.org/two/discussion/26329/how-can-i-get-the-ball-to-bounce-properly</link>
      <pubDate>Tue, 13 Feb 2018 04:18:42 +0000</pubDate>
      <dc:creator>indigopolo</dc:creator>
      <guid isPermaLink="false">26329@/two/discussions</guid>
      <description><![CDATA[<p>Hello! Im trying to get the ball to bounce off the center circle and the edges of the canvas. I've been successful with the edges but i'm having some issues with the circle in the center. Cant figure out how to get the ball to bounce off naturally then right back to where it was. I see that examples that are somewhat similar to this use vectors. I do not want to use vectors because i am very new to programming and haven't been taught how to use them. I would like to figure this out using trig but don't know how to approach it</p>

<p>GIF: <a href="https://gyazo.com/ffe4cffa5decbbb162c5ef06dfa5c1bb" target="_blank" rel="nofollow">https://gyazo.com/ffe4cffa5decbbb162c5ef06dfa5c1bb</a></p>

<p>code: <a href="https://pastebin.com/DFHYA1wM" target="_blank" rel="nofollow">https://pastebin.com/DFHYA1wM</a></p>
]]></description>
   </item>
   <item>
      <title>How to randomize background color, bouncing ball</title>
      <link>https://forum.processing.org/two/discussion/25851/how-to-randomize-background-color-bouncing-ball</link>
      <pubDate>Sat, 06 Jan 2018 18:48:19 +0000</pubDate>
      <dc:creator>mattwonderwall</dc:creator>
      <guid isPermaLink="false">25851@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,</p>

<p>So I'm just getting started with processing and have little knowledge on it. Anyhow, I'm trying the bouncing ball problem and for every time it threatens to go outside the width of the screen the ball will bounce back; I've got that part covered.</p>

<p>Now I want it to not only bounce back and forth, but also change the background color for each time it hits the side.</p>

<p>What I've got so far is:</p>

<p>float ballX;
float xspeed = 3;</p>

<p>void setup(){
  size(500,400);
  ballX=0;
  background(0);</p>

<p>}</p>

<p>void draw(){
  fill(255);
  ellipse(ballX,height/2,24,24);</p>

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

<p>if(ballX&gt;500 || ballX&lt;0){
 xspeed=xspeed*-1;</p>

<p>if(ballX&gt;500 || ballX&lt;0){
 background(random(255),random(255),random(255));
}
 }</p>

<p>This was the only way I got the background to stay that random color until the ball hit the opposite wall and changed again. When I had background(0); in void draw it would only flash a color and than turn back to black each time it hit a wall. The only problem I have now is that the ball is traced, just a long streak of white until it hits a wall and changes color.</p>

<p>How can I change this so that it looks normal, without the ball being traced?</p>
]]></description>
   </item>
   <item>
      <title>How would I go about turning this bouncing ball code into code to show multiple random balls?</title>
      <link>https://forum.processing.org/two/discussion/25611/how-would-i-go-about-turning-this-bouncing-ball-code-into-code-to-show-multiple-random-balls</link>
      <pubDate>Sun, 17 Dec 2017 19:07:44 +0000</pubDate>
      <dc:creator>coding94</dc:creator>
      <guid isPermaLink="false">25611@/two/discussions</guid>
      <description><![CDATA[<p>Im trying to make code based off of my previous code. I want to make random balls come into the screen and then leave the screen from random directions  without bouncing. How would I go about doing this?</p>

<p>This is what i have:</p>

<pre><code>float circleX;
float xspeed=3;

void setup(){
  size(400,400);
  circleX=0;
}
void draw(){
  background(51);
  fill(102);
  stroke(255);
  ellipse(circleX,height/2,32,32);

  circleX = circleX + xspeed;

  if(circleX&gt;width || circleX&lt;0){
    xspeed=xspeed*-1.1;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>colliding bouncing balls with mouse object</title>
      <link>https://forum.processing.org/two/discussion/25595/colliding-bouncing-balls-with-mouse-object</link>
      <pubDate>Sat, 16 Dec 2017 11:00:57 +0000</pubDate>
      <dc:creator>tsord</dc:creator>
      <guid isPermaLink="false">25595@/two/discussions</guid>
      <description><![CDATA[<p>Can someone help me with making the balls collide with my mouse image and after that making the time timer stop</p>

<pre><code>// Balls
int Balls = 5;
int BallA[] = new int[Balls];
int BallB[] = new int[Balls];
float MoveA[] = new float[Balls];
float MoveB[] = new float[Balls];
//timer
int t;

//image
PImage img;
void setup() {
  size(500, 500);

// Balls
  for(int x = 0; x &lt; Balls; x++){
    BallA[x] = int(random(50, width));
    MoveA[x] = int(random(5, 8));
    BallB[x] = int(random(50, width));
    MoveB[x] = int(random(5, 8));

//image
   img = loadImage("download.jpg");
   img.resize(img.width/5, img.height/5);
}}

void draw() {
// changing the background when moving your mouse. it is divided in 3 parts
  if (mouseX &lt; width/3) 
  { background (230,220,0);
} else if(mouseX &lt; 2*width/3){
  background (0,0,0);
} else 
  background (255,0,0);
// creating an object to move around with your mouse  
  fill(0);
  rect(mouseX, mouseY, 25, 25);
  noCursor();

//timer
  fill(255);
  t=millis()/1000;
  textSize(20);
  text (t,270,20);
  text("Score:", 210, 20);

//image
image(img,mouseX,mouseY);

//balls
  for(int x = 0; x&lt;Balls; x++){
  ellipse(BallA[x], BallB[x], 20, 20);
  if(BallA[x] &gt; width || BallA[x] &lt; 10){
      MoveA[x] = MoveA[x] * (-1);}
  if(BallB[x] &gt; height || BallB[x] &lt; 10){
      MoveB[x] = MoveB[x] * (-1);}
  BallA[x] += MoveA[x];
  BallB[x] += MoveB[x]; 
}
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Need Help constraining bouncing images to boundary of canvas</title>
      <link>https://forum.processing.org/two/discussion/25357/need-help-constraining-bouncing-images-to-boundary-of-canvas</link>
      <pubDate>Sun, 03 Dec 2017 17:15:05 +0000</pubDate>
      <dc:creator>gotuhooked</dc:creator>
      <guid isPermaLink="false">25357@/two/discussions</guid>
      <description><![CDATA[<p>Hello Everyone, I am Mel!  I have very little experience with processing, but I have an art project that I've created. My goal is to have 4 shapes bouncing around the screen, and when you click one, a sound will play. So far, I have figured out how to create the shapes, make them move around. However, my first problem is that only the flower image I have stays mostly within the screen. All other shapes are far off and barely show up in one rotation. I understand that this is similar to "bouncing ball" exercises, yet I'm still lost on how to keep the four of my shapes with the boundary.</p>

<p>This below is what I have so far. Sorry that you wont be able to play the code, but hopefully I was detailed enough for you to get the picture.Thank you for reading this and any help is much appreciated!!!</p>

<pre><code>import ddf.minim.*;

Minim minim;
AudioPlayer winter;
AudioPlayer summer;
AudioPlayer spring;
AudioPlayer autumn;


PImage flower;
PImage fire;
PImage sun;
PImage snowman;
float xpos, ypos;    // Starting position of shape    

float xspeed = 5;  // Speed of the shape
float yspeed = 10;  // Speed of the shape

int xdirection = 1;  // Left or Right
int ydirection = 1;  // Top to Bottom
import processing.sound.*;



void setup() {
  size(800, 800);
  noStroke();
  frameRate(50);
  flower = loadImage("Flower.png");
  flower.resize(200, 200);
  sun = loadImage("Sun.png");
  sun.resize(200, 200);
  fire = loadImage("campfire.png");
  fire.resize(200, 200);
  snowman = loadImage("snowman.png");
  snowman.resize(200, 200);
  xpos = width/1.8;
  ypos = height/2;


  // will play sound
  minim = new Minim(this);
  winter = minim.loadFile("Winter Mix.wav");
  summer = minim.loadFile("Summer Mix.wav");
  spring = minim.loadFile("Spring Mix.wav");
  autumn = minim.loadFile("Autumn Mix.wav");
}

void draw() {
  background(#CBE9F0);

  // Update the position of the shape
  xpos = xpos + ( xspeed * xdirection );
  ypos = ypos + ( yspeed * ydirection );

  // Test to see if the shape exceeds the boundaries of the screen
  // If it does, reverse its direction by multiplying by -1
  if (xpos &gt; width || xpos &lt; 5) {
    xdirection *= -1;
  }
  if (ypos &gt; height || ypos &lt; 10) {
    ydirection *= -1;
  }

  // Draw the shape
  image(flower, xpos, ypos);
  image(sun, -xpos, ypos);
  image(fire, xpos, -ypos);
  image(snowman, -xpos, -ypos);
}
void keyPressed() 
{
  if (winter.isPlaying() )
  {
    winter.pause();
  } else if (winter.position() == winter.length() )
  {
    winter.rewind();
    winter.play();
  }
  summer.rewind();
  summer.play();
}
void mousePressed()
{
  spring.rewind();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Colliding images change direction?</title>
      <link>https://forum.processing.org/two/discussion/25278/colliding-images-change-direction</link>
      <pubDate>Wed, 29 Nov 2017 17:36:20 +0000</pubDate>
      <dc:creator>letsgo</dc:creator>
      <guid isPermaLink="false">25278@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to make a program where the image changes direction when two images collide.</p>

<p>I want to use this code but I'm uncertain where I put it? Also what do I substitute for ob1 (object1) and x1 and where do I put the width and height variables?  Thanks</p>

<pre><code> boolean Collision()

  ( ob1 - x1, ob1 -y1, ob1 - w, ob1 - h,
    ob2 - x1, ob2 -y1, ob2 -w, ob2-h)

  return 
  (ob1 - x1 &lt; ob2 - x2 &amp;&amp; ob1 - x2 &gt; ob2 = x1 &amp;&amp;  //insert y variables








//start of code


    class Bouncy 
    {

      int x;
      int y;
      int dx; 
      int dy;

      PImage nw, ne, sw, se;

      Bouncy(int x, int y, int dx, int dy) 
      {
        this.x = x;
        this.y = y;
        this.dx = dx;
        this.dy = dy;
    nw = loadImage("NorthW.png");
    ne = loadImage("NorthE.png");
    sw = loadImage("SouthW.png");
    se = loadImage("SouthE.png");
      }


      void update() 
      {
        render();
        move();
      }

      void render() 
      {
    if (dx == -1 &amp;&amp; dy == -1)
      image(nw,x,y);

    else if (dx == 1 &amp;&amp; dy == -1)
    image(ne,x,y);

    else if (dx == -1 &amp;&amp; dy == 1)
    image(sw,x,y);

    else if (dx == 1 &amp;&amp; dy == 1)
    image(se,x,y);
          }

      void checkCollisions() 
      {
        int edge = 65; // half width of one of the PNG files

        if (y&lt;=(edge-edge)) // hit top border
     dy=1; // switch to moving downwards

    if (y&gt;=500-(edge*2)) // hit bottom border
     dy=-1; // switch to moving upwards

        if (x&lt;=edge-edge) // hit left border
    dx=1; // switch to moving right

    if (x&gt;=500-(edge*2)) // hit right border
    dx=-1;
      }



      void move() 
      {
    checkCollisions();
    x += dx;
    y += dy;

      }
    }

    Bouncy janet,jeff,jerry;

    void setup() 
    {
      size(500,500);
      janet = new Bouncy(10,100,1,-1);
      jeff = new Bouncy(10,150,-1,1);
      jerry = new Bouncy(10,350,1,1);

    }

    void draw() 
    {
      background(255);
      janet.update();
      jeff.update();
      jerry.update();

    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How can I make ball bounce from a platform to another?</title>
      <link>https://forum.processing.org/two/discussion/25165/how-can-i-make-ball-bounce-from-a-platform-to-another</link>
      <pubDate>Thu, 23 Nov 2017 12:52:52 +0000</pubDate>
      <dc:creator>rlark</dc:creator>
      <guid isPermaLink="false">25165@/two/discussions</guid>
      <description><![CDATA[<p>I want that my ball jump from platform A to platform B. If do not touch the platform, falls.</p>

<pre><code>    boolean salta = false;
    boolean baixa = false;
    boolean esquerra = false;
    boolean dreta = false;
    boolean stop=false; 
    //PImage img;


    float cercleX = 50;
    float cercleY = 50;
    float gravetat = 0.5;
    float posx = 0;
    float posy = 50;
    float vy = -1;
    float bounce = -0.5;

    //color c = get(0,0);

    //////////////////////////////////////////////////////////////////////////////////////

    void setup() {
      size (1280, 720);
      smooth();
      noStroke();
      //img = loadImage("background1-720.png");
    }

    void draw() {
      background (255);
      //image(img, 0, 0);



      //posx++;

      frameRate (70);
      fill(0);
      rect(0, 400, 500, 100);
      rect(600, 400, 500, 100);

      fill(255, 0, 255);
      ellipse(posx, posy, 20, 20);

      if (!stop) {
        vy += gravetat;
        posy += vy;
      }


      if (posy &gt; height - 330) {

        vy = bounce * abs(vy);

        if (abs(vy)&lt;0.281) {
          vy=0.0;

          stop=true;
        }
      }

      // booleans 
      if (salta) {
        posy--;
        stop=false; 
        vy=-5;
      }

      if (baixa) {
        posy++;
      }

      if (esquerra) {
        posx--;
      }

      if (dreta) {
        posx++;
      }
    }

    void keyPressed() {
      if (keyCode == UP) {
        salta = true;
      } else if (keyCode == DOWN) {
        baixa = true;
      } else if (keyCode == LEFT) {
        esquerra = true;
      } else if (keyCode == RIGHT) {
        dreta = true;
      }
    }

    void keyReleased() {
      if (keyCode == UP) {
        salta = false;
      } else if (keyCode == DOWN) {
        baixa = false;
      } else if (keyCode == LEFT) {
        esquerra = false;
      } else if (keyCode == RIGHT) {
        dreta = false;
      }
    }



    //
</code></pre>
]]></description>
   </item>
   <item>
      <title>Bouncing balls collision</title>
      <link>https://forum.processing.org/two/discussion/24966/bouncing-balls-collision</link>
      <pubDate>Sat, 11 Nov 2017 16:48:51 +0000</pubDate>
      <dc:creator>Alfio</dc:creator>
      <guid isPermaLink="false">24966@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I've tried to code a classic bouncing balls animation but I can't get to make balls properly bounce.
The problem is that sometimes the balls got stuck into each others or into the edges of the canvas, beside not changing color. I figured it might has something to do width the frame rate, which somehow make the balls enter one into another passing the edge without detection and without bouncing.. maybe Im wrong, but I can't find a solution
Someone can help?</p>

<p>here the code</p>

<pre><code>Ball[] balls = new Ball[10];

void setup() {
  size(800, 600);
  for (int i = 0; i &lt; balls.length; i++) {
    balls[i] = new Ball(random(40,60), 120);
  }
}

void draw() {
  background(0);
  for (int i = 0; i &lt; balls.length; i++) {
    balls[i].display();
    balls[i].move();
    balls[i].edges();
    for (int o = 0; o &lt; balls.length; o++) {
      if(o!=i){
      balls[i].overlaps(balls[o]);
      balls[o].overlaps(balls[i]);
      }
    }
  }
}

class Ball {
  float dia;
  float x;
  float y; 
  float col;
  float xspeed;
  float yspeed;
  float acc = sin(TWO_PI/400);
  float r;

  Ball (float tempD, float tempC) {
    x = random(100,700);
    y = random(100,400);
    dia = tempD;
    col = tempC;
    r = dia/2;
    xspeed = 2.0;
    yspeed = 3.0;
  }

  void display() {
    noStroke();
    fill(col);
    ellipse(x, y, dia, dia);
  }

  void move() {
    //xspeed = xspeed+acc;
    //yspeed = yspeed+acc;
    x = x + xspeed;
    y = y + yspeed;
  }

  void edges() {
    if (x &gt; width-r || x &lt; r) {
      xspeed = xspeed * -1;
    }
    if (y &gt; height-r || y &lt; r) {
      yspeed = yspeed * -1;
    }
  }

  void overlaps(Ball o) {
    float d = dist(x,y,o.x,o.y);
    if (d &lt; r + o.r) {
      xspeed = xspeed*-1;
      yspeed = yspeed*-1;
      col = 255;
      println(d);
    } else{
      col=120;
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Help to optimise proximity particles</title>
      <link>https://forum.processing.org/two/discussion/25012/help-to-optimise-proximity-particles</link>
      <pubDate>Tue, 14 Nov 2017 22:03:19 +0000</pubDate>
      <dc:creator>jmean</dc:creator>
      <guid isPermaLink="false">25012@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I'm trying to draw lines between particles if they are close enough to each other. 
My code seems to do that however the frame rate drops to pretty much 0.</p>

<p>How can I make this faster? 
Code here: <a rel="nofollow" href="https://codepen.io/jmean/pen/pdwXgO">https://codepen.io/jmean/pen/pdwXgO</a></p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>Trouble In getting My shape to Bounce or change color appropriately while method is being used</title>
      <link>https://forum.processing.org/two/discussion/24843/trouble-in-getting-my-shape-to-bounce-or-change-color-appropriately-while-method-is-being-used</link>
      <pubDate>Thu, 02 Nov 2017 13:21:03 +0000</pubDate>
      <dc:creator>ainderp</dc:creator>
      <guid isPermaLink="false">24843@/two/discussions</guid>
      <description><![CDATA[<pre><code>PShape star;                                                        
float red   = random(255);
float green = random(255);
float blue  = random(255);

int rad = 60;   //width of the shape
float xpos, ypos;

float xspeed = 5;
float yspeed = 5;

int xdirection = 1;
int ydirection = 1;

void setup() {
  size(1000, 1000, P2D);
  colorMode(RGB, 255);
  background(0);
  xpos = width/2;
  ypos = height/2;
  star = createShape();  // creating the star shape
  star.beginShape();
  star.fill(255, 255, 0);  // setting the default color of the star
  star.stroke(255);
  star.strokeWeight(2);
  star.vertex(0, -50);   // creating the  star shape 
  star.vertex(14, -20);
  star.vertex(47, -15);
  star.vertex(23, 7);
  star.vertex(29, 40);
  star.vertex(0, 25);
  star.vertex(-29, 40);
  star.vertex(-23, 7);
  star.vertex(-47, -15);
  star.vertex(-14, -20);
  star.endShape(CLOSE);
  shape(star, xpos, ypos);
  //shapeMode(RADIUS)             if this line of code is enabled the star is stuck in the corner and only changes color
}

void draw() {
}


void mousePressed() {                         // while mousepressed the star should change color and bounce around the screen


  xpos = xpos + (xspeed * xdirection);
  ypos = ypos + (yspeed * ydirection);


  if (xpos &gt; width-rad || xpos &lt; rad) {

    xdirection *= -1;
  }

  if (ypos &gt; height-rad || ypos &lt;rad) {

    ydirection *= -1;
  }

  background(0);
  shape(star, xpos, ypos);

  star.disableStyle();                           
  fill(red, green, blue);

  if (red&lt;255)
    red = red+random(255);
  else
    red = 0;

  if (green &lt; 255) 
    green = green+random(255);
  else
    green = 0;

  if (blue&lt;255)
    blue = blue+random(255);
  else 
  blue = 0;
}

/*void mouseReleased() {           //when mouse is released repostion star in middle 
 star.enableStyle();                    // to original color
 background(0);
 shape(star, width/2, height/2);
 }
 */
</code></pre>

<p>I want the program to start with the yellow star in the middle and then when you press and hold down the mouse button it should begin bouncing around the screen while constantly changing colors? upon mouseReleased the star resets back to the middle. I'm pretty new to processing so I can't see where I'm going wrong.</p>

<p>When I take the bounce code out of the mousePressed method and place it in draw, the star just goes from the top left corner to the botom right and changes color upon each mouseclick  any advice would be highly appreciated!</p>
]]></description>
   </item>
   <item>
      <title>I need help creating an array of bouncy balls with text and info displayed</title>
      <link>https://forum.processing.org/two/discussion/24501/i-need-help-creating-an-array-of-bouncy-balls-with-text-and-info-displayed</link>
      <pubDate>Wed, 11 Oct 2017 22:35:59 +0000</pubDate>
      <dc:creator>aliburke</dc:creator>
      <guid isPermaLink="false">24501@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I am trying to create a code to display earthquake data sets but I'm teaching myself processing and I am struggling...</p>

<p>I want to display the worlds largest 10 earthquakes in history. Each bouncy ball should be a different size depending on the size of the earthquake and when the mouse hovers over one ball information appears (location, date, magnitude). When this hover happens I want the screen to freeze so it's easier for the information to be read.</p>

<p>At the moment I have a code that has 12 bouncy balls but I can't work out how to place individual text on specific balls - right now the same text line is displayed on all the balls and when the program is closed and re-run this text changes but is still displayed on every circle.</p>

<p>I think most of my problems are coming because I haven't created an array of the bouncing balls but I don't know how to do that I keep getting an error message. I still want my bouncing balls to bounce off each other with no gravity.</p>

<p>If anyone could help me to put my 6 country names on 6 different bouncing balls and create a mouse hover code for me that would be very helpful! And if anyone can, could you display this data on one ball:</p>

<ul>
<li><p>name = indonesia</p></li>
<li><p>date = 2004</p></li>
<li><p>magnitude = 9.1</p></li>
</ul>

<p>My code so far looks like this:</p>

<pre><code>int numBalls = 12;
float spring = 0.05;
float friction = -0.9;
Ball[] balls = new Ball[numBalls];

float r = random(6);

String[] headlines = {"Indonesia", "Australia", "Japan", "Mexico", "USA", "Germany"};

String c = headlines[int(random(6))];

PFont f;



void setup() {
size(1275, 700);
for (int i = 0; i &lt; numBalls; i++) {
//array
balls[i] = new Ball(random(width), random(height), random(100, 100), i, balls);
//need to make array of different size circles then line underneath for text
}
noStroke();
fill(255, 204);
f = createFont("arial",20,true);  
}

void draw() {
background(0);

//adding text
fill(255,255,255);
String s= "WORLD'S LARGEST QUAKES";
textSize(64);
text(s,500,100);

for (Ball ball : balls) {
ball.collide();
ball.move();
ball.display(); 
}
}



class Ball {

float x, y;
float diameter;
float vx = 0;
float vy = 0;
int id;
Ball[] others;

Ball(float xin, float yin, float din, int idin, Ball[] oin) {
x = xin;
y = yin;
diameter = din;
id = idin;
others = oin;
} 

void collide() {
for (int i = id + 1; i &lt; numBalls; i++) {
  float dx = others[i].x - x;
  float dy = others[i].y - y;
  float distance = sqrt(dx*dx + dy*dy);
  float minDist = others[i].diameter/2 + diameter/2;
  if (distance &lt; minDist) { 
    float angle = atan2(dy, dx);
    float targetX = x + cos(angle) * minDist;
    float targetY = y + sin(angle) * minDist;
    float ax = (targetX - others[i].x) * spring;
    float ay = (targetY - others[i].y) * spring;
    vx -= ax;
    vy -= ay;
    others[i].vx += ax;
    others[i].vy += ay;
  }
}   
}

void move() {
x += vx;
y += vy;
if (x + diameter/2 &gt; width) {
  x = width - diameter/2;
  vx *= friction; 
}
else if (x - diameter/2 &lt; 0) {
  x = diameter/2;
  vx *= friction;
}
if (y + diameter/2 &gt; height) {
  y = height - diameter/2;
  vy *= friction; 
} 
else if (y - diameter/2 &lt; 0) {
  y = diameter/2;
  vy *= friction;
}
}

void display() {
//fill ellipse
fill(0,255,0);
ellipse(x, y, diameter, diameter);
//fill text
fill(255,255,255);
textFont(f,20);
textAlign(CENTER);
text(c,x,y);
}
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to make a code which is sensitive to the density of particle and bounce off from the surfaces</title>
      <link>https://forum.processing.org/two/discussion/24247/how-to-make-a-code-which-is-sensitive-to-the-density-of-particle-and-bounce-off-from-the-surfaces</link>
      <pubDate>Sun, 24 Sep 2017 21:58:26 +0000</pubDate>
      <dc:creator>soonk</dc:creator>
      <guid isPermaLink="false">24247@/two/discussions</guid>
      <description><![CDATA[<p><img src="" alt="" />Hello forum, 
Always thank you for yall's comments.
I think I become to feel more comfortable to write some codes and at the same time want to try something more complicated.</p>

<p>I'm thinking of making a code which is sensitive to density of particles and able to bounce off once the collisions happen.
However, I was stuck in the code which is for making my particles bounce off from the surface of squares and have no idea about how to make my particles slow down once the density of particles nearby gets higher.</p>

<p>Below is the code I made for illustrating particle movement from the bottom and squares dispersed through out the screen.</p>

<p>How can I make the particle recognize the surface of the squares in the screen, and make the speed of particles slows down once the number of particles within 100*100 pixels gets more than 50?</p>

<p>I think rather than putting the numbers for my squares, I think it would be better to set the variables for each squares to make a collision equation. No matter how many sample codes I looked through from github, I didn't find any code examples for this situation.</p>

<p>=Sketch=</p>

<pre><code>Particle [] parts = new Particle [500];

float x;
float y;
float r;
float sx1 =30, sx2=120, sx3=210, sx4=300;
float sy1 =30, sy2 =120, sy3=210, sy4=300;

void setup(){
  size(600,400);
  for(int i =0; i&lt;parts.length;i++) {
    float x = random(0,width);
    float y = 0;
    parts[i] = new Particle();
  }


}

void draw(){
  background(200);
  for (int i =0;i&lt;parts.length;i++) {
    parts[i].display();
    parts[i].movement();
    parts[i].finish();
  }
   fill(100,50);
  rect(sx1,sy1,60,60);
  rect(sx2,sy2,60,60);
  rect(sx3,sy3,60,60);
  rect(sx4,sy4,60,60);
  rect(sx2,sy1,60,60);
  rect(sx2,sy1,60,60);
  rect(sx3,sy1,60,60);
  rect(sx4,sy1,60,60);

}
</code></pre>

<p>=Particle Class=</p>

<pre><code>class Particle {

float x;
float y;
float r;
float distance;
float speed;
//float sx1 =30, sx2=120, sx3=210, sx4=300;
//float sy1 =30, sy2 =120, sy3=210, sy4=300;

Particle () {
  x= random(0,width);
  y= height;
  r= 10;
  speed = random(0.1,0.5);
}

void display() {
  stroke(0);
  fill(255,0,0,80);
  ellipse(x,y,r,r);
}

void movement() {
  x=x+random(-0.5,0.5);
  y=y-speed;

}

void finish() {
  if (y&gt;=height) {
    speed = 0;
  }
}

}
</code></pre>

<p><img src="https://forum.processing.org/two/uploads/imageupload/358/GCO55RL07EUB.jpg" alt="coding concept description" title="coding concept description" /></p>
]]></description>
   </item>
   <item>
      <title>...create a simple ascending/descending series of values</title>
      <link>https://forum.processing.org/two/discussion/24190/create-a-simple-ascending-descending-series-of-values</link>
      <pubDate>Wed, 20 Sep 2017 20:30:42 +0000</pubDate>
      <dc:creator>wnovotny</dc:creator>
      <guid isPermaLink="false">24190@/two/discussions</guid>
      <description><![CDATA[<p>My aim would be to create a counter, which starts at 0, counts up to 10, then down again to 0, and again starts from the beginning.
Somehow i can not figure out how to do that:</p>

<pre><code>int countdown =0;
int seconds, seconds2, startTime;

void setup() {



    startTime = millis()/1000 + countdown;
}

void draw() {

  seconds = startTime + millis()/1000;

    if (seconds &gt; 10)    seconds = startTime - millis()/1000;
    if (seconds &lt; 0)    seconds = startTime + millis()/1000;

    println (seconds);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Changing moving direction when reaching an specific point?</title>
      <link>https://forum.processing.org/two/discussion/24191/changing-moving-direction-when-reaching-an-specific-point</link>
      <pubDate>Wed, 20 Sep 2017 22:05:15 +0000</pubDate>
      <dc:creator>guilhermecso</dc:creator>
      <guid isPermaLink="false">24191@/two/discussions</guid>
      <description><![CDATA[<p>Captura de Tela 2017-09-20 às 18.58.15](<a href="https://forum.processing.org/two/uploads/imageupload/959/YE1MDX5NDXBD.png" target="_blank" rel="nofollow">https://forum.processing.org/two/uploads/imageupload/959/YE1MDX5NDXBD.png</a> "Captura de Tela 2017-09-20 às 18.58.15")</p>

<p>Hello everyone! I'm new to processing and I've got this program in which the line moves from the left edge to the right edge. When it reaches the right edge it appears back in the left and restart the loop. I wanna know how can I make it changes direction when hitting right edge and move back to the left. I tried conditions like <strong>if (pos &gt; width ) {pos--} but it wouldn't work because when the line goes back to the start, the position becomes &lt; width.</strong></p>

<p>Hope you guys can help me. Thanks!</p>

<p>Here goes the original program:</p>

<p>void setup() {
  size(400, 400);
  frameRate(12);
}</p>

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

<p>void draw() {
  background(204);
  pos++;
  line(pos,20,pos,80);
  if (pos &gt; width ) {
      pos=0;
   }
}</p>
]]></description>
   </item>
   <item>
      <title>Question with bouncing ball</title>
      <link>https://forum.processing.org/two/discussion/24175/question-with-bouncing-ball</link>
      <pubDate>Tue, 19 Sep 2017 15:58:11 +0000</pubDate>
      <dc:creator>FezFamiliar</dc:creator>
      <guid isPermaLink="false">24175@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody , so recently i wanted to make a realistical bouncing ball , here is the code:</p>

<p>var x = 200;
var y = 110;
var speed = 0;
var bounce = 0.3;</p>

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

<p>createCanvas(400, 400);
}</p>

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

<p>background(51);</p>

<p>ellipse(x, y, 30, 30);</p>

<p>// the ball starts to drop.</p>

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

<p>// its speed is increasing over time rather than falling at a constant speed</p>

<p>speed = speed + bounce;</p>

<p>// if it hits the ground</p>

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

<pre><code>speed = speed * -1;

speed = speed + bounce;

bounce = bounce + 0.1;
</code></pre>

<p>}
}</p>

<p>So this works fine, im proud. HOWEVER i have some issues which i cannot understand. The first question is, when i change the bounce value to a slightly larger number ( 0,4  or 0,5) i get a blank page. My second question is, when the ball gets too close to the ground it starts to go up and down really fast and i dont want that. I want the ball to transition smoothly onto the ground. Thanks in advance guys.( p5 js)</p>
]]></description>
   </item>
   <item>
      <title>Is there a better way of completing this? (bouncing)</title>
      <link>https://forum.processing.org/two/discussion/23916/is-there-a-better-way-of-completing-this-bouncing</link>
      <pubDate>Thu, 24 Aug 2017 15:16:45 +0000</pubDate>
      <dc:creator>netrate</dc:creator>
      <guid isPermaLink="false">23916@/two/discussions</guid>
      <description><![CDATA[<p>I have created a bouncing ball going back and forth (left to right).  It works but I was wondering if there is a way to clean up some of the code to make it more efficient.  The print statements are to help me out and the move is set to 50 so I didn't need to scroll through the console to see how it was doing.  Move=5 if necessary.</p>

<pre><code>diam=10
move=50

def setup():
    size(500,500)
    background(50,50,50)
    startover()

def startover():
    global placementY, x  
    x=width/2
    placementY=int(random(10, 490))         

def draw():
    global x, move
    background(50,50,50)
    fill(255)
    ellipse(x, placementY, diam, diam)
    if x &lt;=0:
        print("value of X: ", x)
        print("change over from left to right, reached ZERO")
        move*=-1
        x=x+move

    elif (x &lt; width):
        print("value of X: ", x)
        print("in between everything")
        x=x+move

    elif (x &gt; 490):
        print("made it here to 500: ", x)
        move*=-1
        x=x+move
</code></pre>
]]></description>
   </item>
   <item>
      <title>Bounce Ball off of Paddle</title>
      <link>https://forum.processing.org/two/discussion/23866/bounce-ball-off-of-paddle</link>
      <pubDate>Sat, 19 Aug 2017 21:35:35 +0000</pubDate>
      <dc:creator>gleister</dc:creator>
      <guid isPermaLink="false">23866@/two/discussions</guid>
      <description><![CDATA[<p>Hey, back again with another question... I got my ball to move, my paddle to display and to move! Now, I just cant seem to get the paddle to reverse the Ball's direction by having it bounce off of it. Ive tried a handful of different methods, but none have been successful. Sometimes the ball just starts bouncing up and down at the top of the screen.</p>

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

<pre><code>    //Gwendolyn Leister - Pong Game
    //Hit the ball with the paddle by moving the mouse left and right 
    //Each time you hit the paddle, your score goes up

    //Many thanks to the two forums that helped me: 
    //<a href="https://forum.processing.org/two/discussion/23862/subclass-won-t-display-or-move-help#latest" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/23862/subclass-won-t-display-or-move-help#latest</a>
    //<a href="https://forum.processing.org/two/discussion/23842/myclass-move-does-not-exist-but-it-does#latest" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/23842/myclass-move-does-not-exist-but-it-does#latest</a>


    //Global Variables
    boolean gameStart = false;

    //Declare Fonts
    PFont myFont;
    PFont myFont2;

    final GamePiece Ball = new Ball();
    final GamePiece Paddle = new Paddle();

    void setup () {
      size(800, 800);
      smooth();
      background(0);
      myFont = loadFont("AnonymousPro-30.vlw"); //smaller text font
      myFont2 = loadFont("AnonymousPro-80.vlw"); //larger title font
    } 

    void draw() {

      background (#0A141F);

      //Layout
      rectMode(CORNER);
      fill(#CBFEFF);
      noStroke();
      rect(0, 640, 800, 260);
      stroke(255);
      fill(#CBFEFF);
      strokeWeight(10);
      line(0, 640, 800, 640);
      fill(#0A141F);
      rect(200, 700, 400, 160);

      //score text 
      textFont(myFont);
      textAlign(RIGHT);
      textSize(20);
      text("Score:", 70, 25);

      //display classes
      Ball.display();
      Paddle.display();

      if (gameStart) { //if the user hits enter to start game and allow subclasses to move/bounce
        Ball.move();
        Ball.bounce();
        Paddle.move();
      } else {  //when enter is not pressed or if it is pressed twice, it will pause the game

        textAlign(CENTER);
        textFont(myFont2);
        textSize(80);
        text("P O N G", 400, 100);
        textSize(20);
        text("press enter to start", 400, 600);
        text("move mouse horizontally to control the", 400, 140);
        text("paddle and to bounce the ball off of", 400, 162);
      }
    }



    // Resource used: <a href="https://processing.org/tutorials/interactivity/" target="_blank" rel="nofollow">https://processing.org/tutorials/interactivity/</a>
    void keyPressed() { //if enter is pressed then the game starts {
      if (keyCode == ENTER) {
        gameStart = !gameStart;
      } else {
      }
    }

    abstract class GamePiece {
      //ball variables
      int rad = 15;
      float xPos=width/2;
      float yPos=height/2;
      float Speed = 6; 
      float xDirection = -2;
      float yDirection = -1;

      int score = 0;//call booleans
      boolean mouseMoved;
      boolean overPaddle = false;
      boolean locked = false;
      float dx=0;

      //paddle variables
      int px=mouseX;
      int py=550;
      int pw=100;
      int ph=30;
      int pSpeed = 5;

      int pDistance = 250; // paddle dis


      //calls
      abstract void move(); 
      abstract void display();
      abstract void bounce();
    }


    class Ball extends GamePiece {
      //Resource used: <a href="https://processing.org/examples/bounce.html" target="_blank" rel="nofollow">https://processing.org/examples/bounce.html</a>


      int rad = 15;
      float xPos=width/2;
      float yPos=height/2;
      float Speed = 5;
      float xDirection = -2;
      float yDirection = -1;

      Ball() {
        super();
      }

      void display() {
        stroke(255);
        strokeWeight(3);
        fill(#FCE1BD);
        frameRate(30);
        ellipseMode(RADIUS);
        ellipse(xPos, yPos, rad, rad);
      }
      void move() { // ball position change
        xPos=xPos+Speed*xDirection;
        yPos=yPos+Speed*yDirection;
      }
      void bounce() { //<a href="https://processing.org/examples/bounce.html" target="_blank" rel="nofollow">https://processing.org/examples/bounce.html</a>

        if (yPos - rad &lt; py + ph/2) { // bounce ball off of paddle
          yDirection = -yDirection;  // when i apply this, then the ball acts crazy

          if (xPos&gt;(width-rad)) { //bounce right side
            xPos = width-rad;
            xDirection=-xDirection;
          }
          if (xPos&lt; rad) { //bounce left side
            xPos = rad;
            xDirection=-xDirection;
          }
          if (yPos&lt;rad) { //bounce top side
            yPos=rad;
            yDirection=-yDirection;
          }

          if (yPos&gt;800) { //falls below screen and relocates ball to inside the frame
            yDirection = -1;
            xPos=width/2;
            yPos=height/2;
          }
        }
      }
    }

    class Paddle extends GamePiece {

      Paddle () {
        super();
      }

      void display() {
        rectMode(CENTER);
        fill(#CBFEFF);
        stroke(255);
        strokeWeight(5);
        rect(mouseX, py, pw, ph);  //moves paddle with mouse
      }

      void move() {
      }

      void bounce () { 
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Ease-in ease-out movement</title>
      <link>https://forum.processing.org/two/discussion/23131/ease-in-ease-out-movement</link>
      <pubDate>Mon, 19 Jun 2017 11:46:42 +0000</pubDate>
      <dc:creator>jaspervanblokland</dc:creator>
      <guid isPermaLink="false">23131@/two/discussions</guid>
      <description><![CDATA[<p>Hi All,</p>

<p>I do have now this code. The element will bounce to the borders in horizontal direction. 
From the left to the right the speed starts fast and the speed will slow at the end. 
When the element hits the right side, the element will bounce back.</p>

<p>From the right to the left the speed now start slow and will speed-up at the end. 
I do want to do this the other way around for the movement from right to the left where 
it starts fast and will slow at the end.</p>

<pre><code>float x;
float y;
float easing = 0.05;
float targetX;
float dx;
float w = 100;
float h = 50;
void setup() {
  size(640, 360); 
  noStroke();
}

void draw() { 
  background(51);


  targetX = width+25-w;
  dx = targetX - x;
  x += dx * easing;
  if (x &lt; 25) {
    targetX = width+25;
    dx = targetX - x;
    easing = 0.04;
  }
  if (x &gt; width - w) {
    targetX = 0;
    dx = targetX;
    x += dx * -easing;

    easing = -0.04;
  }

  float targetY = mouseY;
  float dy = targetY - y;
  y += dy * easing;

  rect(x, height/2, w, h);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why another Instance of the class?</title>
      <link>https://forum.processing.org/two/discussion/22933/why-another-instance-of-the-class</link>
      <pubDate>Mon, 05 Jun 2017 08:46:11 +0000</pubDate>
      <dc:creator>BlakHawk</dc:creator>
      <guid isPermaLink="false">22933@/two/discussions</guid>
      <description><![CDATA[<p>I am new to processing and java as well. I've been following some tutorials to generate a bouncy ball sketch.</p>

<pre><code>            import java.util.*;

            ArrayList balti = new ArrayList();



            void setup() {
              size(600, 600);
              smooth();



              for ( int i=0; i&lt;100; i++) {
                Aloo keshavball = new Aloo(random(0, width), random(0, 200));
                balti.add(keshavball);
              }
            }

            void draw() {
              background(0);
              for (int i=0; i&lt;100; i++) {
                Aloo keshavball = (Aloo) balti.get(i); // I want to focus here !! What is happening here? I am really confused ! 
                keshavball.mainfunction();
              }
            }
</code></pre>

<p><strong>and other file is</strong>:</p>

<pre><code>        class Aloo {

          float x;
          float y;
          float speedX=random(-5,5);
          float speedY=random(-5,5);

          Aloo(float _x, float _y) {

            x = _x;
            y = _y;
          }

          void mainfunction() {
            display();
            move();
            bounce();
            gravity();
          }
          void display() {
            ellipse(x, y, 20, 20);
          }

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

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

          void gravity() {
            speedY = speedY +0.25;
          }
        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Array of objects &amp; functions</title>
      <link>https://forum.processing.org/two/discussion/22783/array-of-objects-functions</link>
      <pubDate>Sat, 27 May 2017 12:45:52 +0000</pubDate>
      <dc:creator>Alivanar</dc:creator>
      <guid isPermaLink="false">22783@/two/discussions</guid>
      <description><![CDATA[<p>Hi there, 
first of, english is not my native language so i apoligize if i' making some mistakes,
then, in a minigame that i am building w/ the p5.js library, i want to use this array :</p>

<pre lang="javascript">
 bonuses_array = [
   { name: "Paddle_size +", type: "Bonus", status: false, effect: addPSize(), duration: 30, graphic: Paddle_size_plus()},
   { name: "Paddle_speed +", type: "Bonus", status: false, effect: addPSpeed(), duration: 30, graphic: Paddle_speed_plus()},
   { name: "Ball_speed -", type: "Bonus", status: false, effect: reduceBSpeed(), duration: 30, graphic: Ball_speed_minus()},
   { name: "Paddle_size -", type: "Malus", status: false, effect: reducePSize(), duration: 30, graphic: Paddle_size_minus()},
   { name: "Paddle_speed -", type: "Malus", status: false, effect: reducePSpeed(), duration: 30,graphic: Paddle_speed_minus()},
   { name: "Ball_speed +", type: "Malus", status: false, effect: addBSpeed(), duration: 30, graphic: Ball_speed_plus()},
   { name: "Ball_size -", type: "Malus", status: false, effect: reduceBSize(), duration: 30, graphic: Ball_size_minus()},
  ]</pre>

<p>All the functions are defined somewhere else, and the thing i want to achieve is to be able to call bonuses_array[value].graphic(x, y). But it seems that the functions are not defined the right way... Can someone help me ? 
Thanks !!
Ali</p>
]]></description>
   </item>
   <item>
      <title>Bounce conditional stopped working can someone help me????</title>
      <link>https://forum.processing.org/two/discussion/22814/bounce-conditional-stopped-working-can-someone-help-me</link>
      <pubDate>Mon, 29 May 2017 10:25:43 +0000</pubDate>
      <dc:creator>rupertpupket</dc:creator>
      <guid isPermaLink="false">22814@/two/discussions</guid>
      <description><![CDATA[<pre><code>int w;
int h;
int eye_w, eye_h, pupil_w, pupil_h, ear_w, ear_h, mouth_w, mouth_h, x, y, rot;
int speed=2;
int spacing =90;
int dia = 15;


void setup() {
  size(810, 810);
  w=50;
  h=50;
  eye_w=15;
  eye_h=15;
  pupil_w=7;
  pupil_h=7;
  ear_w =15;
  ear_h =30;
  mouth_w = 20;
  mouth_h = 9;
  x=width/2;
  y=height/18;
  rot=0;
}

void draw() {
  background(0);
  // grid
  for (int hoz = 90; hoz &lt; 730; hoz = hoz + spacing) {
    for (int ver = 90; ver &lt; 730; ver = ver + spacing) {
      fill(245, 216, 163);
      strokeWeight(0);
      ellipse(hoz, ver, dia, dia);
    }
  }

  if (key=='w') {
    y = y - speed;
    rot=180;
  } 
  if (key=='s') {
    y = y + speed;
    rot=0;
  }  
  if (key=='a') {
    x = x - speed;
    rot=90;
  }  
  if (key=='d') {
    x = x + speed ;
    rot=270;
  }


  bounce();
  drawFizzy(x, y, rot);
} 

void bounce() {


  if (x&lt;30) {
    x=x+speed;
    rot=270;
  }
  if (x&gt;785) {
    x=x-speed;
    rot=90;
  }
  if (y&lt;30) {
    y=y+speed;
    rot=0;
  }
  if (y&gt;785) {
    y=y-speed;
    rot=180;
  }
}



void drawFizzy(int x, int y, int rot) {

  //body
  ellipseMode(CENTER);
  translate(x, y);
  rotate(radians(rot));
  noStroke();
  //ears 
  fill(240, 152, 152);
  ellipse( -w/2, h/18, ear_w, ear_h);
  ellipse( w/2, h/18, ear_w, ear_h);
  fill(0);
  ellipse( -w/2, h/18, ear_w/2, ear_h/2);
  ellipse( w/2, h/18, ear_w/2, ear_h/2);
  //body
  fill(255, 0, 0);
  ellipse(0, 0, w, h);
  //mouth
  fill(0);
  ellipse(w/-22, h/2.8, mouth_w, mouth_h);
  fill(240, 152, 152);
  ellipse(w/-22, h/2.8, mouth_w/2, mouth_h/1);
  //eyebrows 
  fill(0);
  ellipse(-w/5, h/18, eye_w -2, eye_h);
  ellipse(w/5, h/18, eye_w -2, eye_h);
  fill(255, 0, 0);
  ellipse(-w/5, h/16, eye_w -2, eye_h);
  ellipse(w/5, h/16, eye_w -2, eye_h);
  //eyes
  fill(255);
  ellipse(-w/5, h/10, eye_w, eye_h);
  ellipse(w/5, h/10, eye_w, eye_h);
  //pupils
  fill(0);
  ellipse(-w/5, h/10, pupil_w, pupil_h);
  ellipse(w/5, h/10, pupil_w, pupil_h);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Bouncing ball programme, need help!</title>
      <link>https://forum.processing.org/two/discussion/22552/bouncing-ball-programme-need-help</link>
      <pubDate>Sat, 13 May 2017 03:20:53 +0000</pubDate>
      <dc:creator>absolutebeginner</dc:creator>
      <guid isPermaLink="false">22552@/two/discussions</guid>
      <description><![CDATA[<p>In the programme below I tried to make it so when ever you clicked the screen it creates a ball that bounces around. But when I click the screen a black circle appears and does nothing, can someone help me fix my code?</p>

<pre><code>ArrayList&lt;Ball&gt; balls;


void setup() {
 size (640, 360);
 balls = new ArrayList&lt;Ball&gt;();
 for (Ball ball : balls){
  ball.Setup();
 }
}

void draw() {
 background (55); 

 for (Ball ball : balls){
  ball.show();
  ball.update();
 }
}

void mousePressed() {

 balls.add(new Ball(mouseX, mouseY));
}


class Ball {

  float a;
  float b;
  float movex;
  float ballx;
  float movey;
  float bally;
  int fcolor;

 public Ball(float ballx, float bally) {

  this.ballx = ballx;
  this.bally = bally;
 }

void Setup() {
 fcolor = 255;
 ballx = width/2;
 bally = height/2;
 a = random(-6, 6);
 b = random(6, -6);
 if ( a &lt; 0) {
   movex = -6;
   } else {
   movex = 6;
   }
   if (b &lt; 0) {
   movey = -6;
   } else {
   movey = 6;
  }
 }

 void show() {

  fill (fcolor);
  stroke (fcolor);
  ellipse (ballx, bally, 50, 50);
 }
 void update() {

 ballx = ballx + movex;
 bally = bally + movey;

 if (ballx &gt; width) {
   ballx = width;
   movex = -movex;
   fcolor = color(random(255), random(2, 55), random(0, 255));
 }

  if (ballx &lt; 0) {
   ballx = 0;
   movex = -movex;
   fcolor = color(random(0, 255), random(0, 255), random(0, 255));
   bally = bally + 0.2;
  }

  if (bally &gt; height) {
   bally = height;
   movey = -movey;
   fcolor = color(random(0, 255), random(0, 55), random(0, 255));
  }
  if (bally &lt; 0) {
   bally = 0;
   movey = -movey;
   fcolor = color(random(0, 255), random(0, 255), random(0, 255));
  }
 }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>making the ball move both vertically but horizontally while it's changing  to random colors</title>
      <link>https://forum.processing.org/two/discussion/22511/making-the-ball-move-both-vertically-but-horizontally-while-it-s-changing-to-random-colors</link>
      <pubDate>Thu, 11 May 2017 01:18:54 +0000</pubDate>
      <dc:creator>Fire_Assassin</dc:creator>
      <guid isPermaLink="false">22511@/two/discussions</guid>
      <description><![CDATA[<p>i have this code so far but i really just want to ball to move vertically and horizontally while it's changing colors at the same time, it'll be awesome if you guys can help, i'm also new here.</p>

<pre><code>int y = 0;
int speed = 5;

void setup() {

  size (200,200); 

  smooth(); 
}

void draw() {
  background (255); 

  y = y + speed; 

  if (( y&gt;width) || (y&lt;0)) { 
    speed = speed * -1;
  }

  stroke (0); 

  fill(237,26,26);

  ellipse (100, y+16, 32, 32);
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>