Hi!
We are trying to use the stuff from your explosion code woth our bubble…
What we want is the bubble to be a object that is complete with all its functions:
- Rising up
- Wobbling
- Popping when clicked on
We have made a wobbling bubble that rises and the option to repeat/reset it.
For that we now use 3 lines of code beside the line that we use to tell size (b1=newBubble(50);
):
Create it, make it move and reset at top.
We would want the bubble object to be like when creating a rect for example. You just say rect(value).
So… All of the coding would have to be done for the bubble class.
The main tab would only have so little code.
I guess that might not be possible… But is it possible to make it at least short as below and still all of the functionality built in?
Example:
Bubble b1;
void setup() {
size(640, 360);
b1 = new Bubble(50);
}
void draw() {
background(0);
noFill();
stroke(255);
b1.show();
}
Well… we havent been able to make your code and our bubble work so far as I said and I think we need assistans
I’ll share our bubble code below.
Its 2 tabs (separated below with a bunch of ===)
Bubble b1;
void setup() {
size(640, 360);
b1 = new Bubble(50);
}
void draw() {
background(0);
noFill();
stroke(255);
b1.show();
b1.move();
b1.top();
println("Y", mouseY);
println("RS", riseStart);
println("X", mouseX);
println("Strt", start);
}
void mousePressed() {
if ((mouseX < start + w/2) && (mouseX > start - w/2) &&
(mouseY < riseStart + h/2) && (mouseY > riseStart - h/2)) {
fill(0, 255, 0);
ellipse(100, 100, 20, 20);
//setup();
}
}
====================================================
//Bubble class tab
float tempSize;
float w;
float h;
boolean move = true;
float maxW;
float maxH;
float minW;
float minH;
float wspeed;
float hspeed;
float riseY = random(0.5, 2);
float riseStart;
float start = random(0, 640);
float mX;
float mY;
class Bubble {
Bubble(float tempSize) {
w = tempSize;
h = tempSize;
riseStart = tempSize + height;
maxW = w*1.1+random(0, maxW/2);
maxH = h*1.1+random(0, maxH/1);
minW = w/1.1;
minH = h/1.1;
wspeed = w/100;
hspeed = h/75;
mX = mouseX;
mY = mouseY;
}
void show() {
strokeWeight(2);
ellipse (start, riseStart, w, h);
if (move) {
w = w + wspeed;
//println(start, riseStart);
if ((w > maxW) || (w < minW)) { // Makes bubble wobble.
wspeed = wspeed * -1;
}
if (move) {
h = h + hspeed;
}
if ((h > maxH) || (h < minH)) { // Makes bubble wobble.
hspeed = hspeed * -1;
}
}
}
void move() {
riseStart = riseStart - riseY;
}
void top() {
if (riseStart < tempSize - tempSize -100) {
riseStart = tempSize + height+100;
start = random(0, 640);
}
}
}