Help with sketch(animated bubbles)
in
Programming Questions
•
2 years ago
I'm working on my first interactive sketch, Currently I have an animated bubble moving across the screen and bouncing off the edges. I want to loop them (maybe have about 10?) and randomize them. I also want to be able to grab them with my cursor and move them around. If anyone can help I'd greatly appreciate it. Code is below.
//Define xPos & yPos variables
float xPos;
float yPos;
//Define Speed variables
float xSpd;
float ySpd;
void setup()
{
//Create the size of the sketch
size(600,400);
smooth();
//Center ellipse
xPos = width/2;
yPos = height/2;
xSpd = 1;
ySpd = 2;
}
void draw()
{
background(255,251,170);
//Moving Ellipse
xPos = xPos + xSpd;
yPos = yPos + ySpd;
//Ellipse hits walls
if (yPos +30 > height || yPos -30 <0)
{
ySpd = ySpd * -1;
}
if (xPos +30 > width || xPos -30 <0)
{
xSpd = xSpd * -1;
}
fill(0,100,200,50);
stroke(255);
strokeWeight(1);
ellipse(xPos,yPos,60,60);
}
1