`
ok but i want to make the ball that falls big then smaller not that the balls first are all small and then get bigger. when they fall the need to gradually get smaller every time
it works the only thig is that when it bounces off it needs to fade out but if i put an AlphaValue all the balls fade from the beginning not just when they touch the ground
Answers
Have their size depend on their position.
If your balls is at a position (x,y), how far is that from the top?
How big does the ball need to be at the top?
How about at the bottom?
If you need more help, post your code. If you have none, attempt some and post the attempt. (Other people get really fussy about this...)
Didn't you like my previous explanation?
`Drop[] drops = new Drop[100];
void setup() { size(800, 800); for(int i = 0; i < drops.length; i++) { drops[i] = new Drop(); } }
void draw() { background(0); for(int i = 0; i < drops.length; i++) { drops[i].fall(); drops[i].show(); } }
class Drop { float x = random(width); float y = random(-500, -50); float yspeed = random (1, 6); float radius = 7; boolean bDead; void fall() { y = y + yspeed; yspeed = yspeed + 0.00005;
if(y > height) { y = random(-200,-100);
} }
void show() { stroke(255); ellipse( x, y, 20, 20); radius = radius - 0.05; if(radius <= 0) { bDead =true; println("dead"); } } }
`
not bad at all!
you need to use radius in the ellipse command please
you don't check bdead yet.
to do so make a backward for loop over the arrayList in draw and if bdead is true, remove(i)
btw not sure what bdead is initially, you want to say
boolean bdead =false;
where you declare it` ellipse( x, y, radius, radius); radius = radius - 0.05;
` ok but i want to make the ball that falls big then smaller not that the balls first are all small and then get bigger. when they fall the need to gradually get smaller every time
like when you see something from really close the you star going away from it
they get smaller, starting at 7. if you want, replace 7 with 37
ok now i need to make them all of a different color bu if i but `void show() { fill(random(255),random(255), random(255));
}` every ball changes color. how do i make them all different colors
please don't post duplicates.
please learn how to format code.
at the start of the class
use the color here:
to make it bounce off the bottom what do i do?
Good progress here!
see here please
https://www.processing.org/examples/bounce.html
Drop[] drops = new Drop[100]; float ypos; float yspeed = 2.2; int ydirection = 1; int rad =60; void setup() { size(800, 800); for(int i = 0; i < drops.length; i++) { drops[i] = new Drop(); } ypos = height/2; } void draw() { background(36, 94, 80); for(int i = 0; i < drops.length; i++) { drops[i].fall(); drops[i].show(); } if (ypos > height-rad) { ydirection *= -1;} }
post also the class, we need the entire code
this must obviously be in the class, hm?
yea in which part of the class ?
why not in show() ?
You must declare the variables that are new where the others are declared inside the class
The new commands in show()
Understand the principle of the example, don’t just copy the lines
You have to change the variable names anyway
ArrayList<PVector> pos; ArrayList<PVector> vel; ArrayList<PVector> size; boolean a=false; color c; //PVector gravity; //int d = 30; void setup() { size(800,800); background(0); c = color (random(255),random(255), random(255)); init(); } void draw() { background(0); for(int i = 0; i < pos.size(); i++) { PVector p = pos.get(i); PVector v = vel.get(i); PVector s = size.get(i); ellipse(p.x, p.y , s.x, s.x); fill(c * i); p.add(v); if (p.y > height) { // println("funziona"); v.y = v.y * -1; p.y = height; a = true; } if (p.y < (height - 50) && v.y < 0 && a==true ) { v.y = v.y * -0.5; //println(p.y); } } particles(); } void init() { pos = new ArrayList<PVector>(); vel = new ArrayList<PVector>(); size = new ArrayList<PVector>(); } void particles() { PVector rndVel = new PVector(0, random(4,6)); vel.add(rndVel); PVector rndPos = new PVector(random(0,width) ,0); pos.add(rndPos); PVector rndSize = new PVector(random(10,15), random(10,15)); size.add(rndSize); }
Looks good!
Does it work?
Solution with a class would have been better but never mind
it works the only thig is that when it bounces off it needs to fade out but if i put an AlphaValue all the balls fade from the beginning not just when they touch the ground
instead of using a class, you took a step back and work with parallel arrays now, which is ok
but that means that parallel to
ArrayList size;
you need also an ArrayList with the fade value as int and with the information whether if ball is fading
here is a example for bouncing with gravity