Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

How to stop many individual falling arcs at the bottom of the canvas so they fall on top each other

edited March 2017

I am trying to figure out a way to create a screen full of falling arc's and I want to make them individually stop on top of each other when they reach a certain distance to the set y axis ( (if y > 650) { stop();}. I have so far created a canvas with falling arc's except when one arc reaches the limit, all the other arc's stop as well. I am trying to find a way to solve this issue but I can't get around it. So I am currently stuck and not sure what to do. Here is what my code looks like. As you'll see, when one stops they all stop. I need them to stack on top of each other. Any help will be appreciated.

``````Arc[] arc = new Arc[60];

void setup() {
size(1500, 700);
for (int i = 0; i < arc.length; i++) {
arc[i] = new Arc();
}
}

void draw() {
background(255);
for (int i = 0; i < arc.length; i++) {
arc[i].fall();
arc[i].show();
}
}

class Arc {
float x;
float y;
float z;
float yspeed;

Arc() {
x  = random(width);
y  = random(-500, -50);
z  = random(0, 20);

yspeed  = map(z, 0, 20, 1, 20);
}
void fall() {
y = y + yspeed;
if (y > 650) {
stop();
yspeed = map(z, 0, 20, 4, 10);
}
}
void show() {
float thick = map(z, 0, 20, 1, 3);
strokeWeight(5);

stroke(0);
arc(x, y, 20, 20, 0, PI);
}
}
``````
Tagged:

Kf

• edited March 2017 Answer ✓

Your big problem is that your class `Arc` calls a `stop()` method internally...but you forgot to implement an `Arc.stop()` method!

Instead, that call to `stop()` is stopping the whole PApplet.

Inside `Arc.fall()` try something more like:

``````if (y > 650) {
// stop();
// yspeed = map(z, 0, 20, 4, 10);
yspeed = 0;
}
``````

There are a couple other odd behaviors you may want to work out, but this should get you going.

• Thanks Jeremy for taking your time to answer my question. I now see what I have done wrong. The only problem I'm currently having right now is that if I increased my numbers of arc's on a screen, they are not stacking on top of each other but rather over lapping. Is there a way I could set my arc's to be a 2D solid block? Thanks a lot, really appreciated it! ^:)^

• Right now, you stop your arcs after they cross the line y > 650. Depending on their speed that means they stop at different places, but those places don't have anything to do with each other.

How would you like to check where to stop an arc? What is the concept? ... Search for dark pixels? Object collision detection?

Add noFill() within your show method so you can see overlapping arcs.

I wouldn't recommend using z to control speed. Instead use a variable called speed... this is for clarity. Clarity is very important practice.

What is the relation between z and yspeed? Why do you map your variables that way? I am just curious...

Kf

• edited March 2017

Hi, thanks kfrajer for correcting my mistakes. I have now fixed my variables and it looks a lot cleaner and easier to understand. Also Jeremy, I'm currently looking online and in the forums for the arc to detect dark pixels. So that the arcs can stop when there is the slightest of touch. Thanks for your guys help! so here is what I've changed in my code thanks to you two:

``````Arc[] arc = new Arc[50];

void setup() {
size(1500, 700);
for (int i = 0; i < arc.length; i++) {
arc[i] = new Arc();
noFill();

}
}

void draw() {
background(255);
for (int i = 0; i < arc.length; i++) {
arc[i].fall();
arc[i].show();
}
}

class Arc {
float x;
float y;
float speed;
float yspeed;

Arc() {
x  = random(100, 1200);
y  = random(-500, -50);
speed = 5;
yspeed  = map(speed, 0, 20, 1, 20);
}
void fall() {
y = y + yspeed;
if (y > 650) {
//stop();
//yspeed = map(z, 0, 20, 4, 10);
yspeed = 0;
}
}
void show() {

strokeWeight(5);
stroke(0);
arc(x, y, 20, 20, 0, PI);
}
}
``````
• Dark pixels? It is better if you do collision detection:

https://forum.processing.org/two/search?Search=collision

Kf