xxxxxxxxxx
//WORKS IN PROCESSING
//REFERENCED WORK FROM
//Josie Hrenak's " BubbleGenerator "
// and Manu Raj Patel's "Wave"
//Thank you Ms. Dutta and Mr. Ben! Have a great summer
////STREAK TYPES///////
float blue = 150;
float green = 100;
float red= 252;
float yellow= 0;
float theta = 0.0;
float amplitude = 70.0;
float period = 1200.0;
float dx;
//array of y locations for all the ball waves
float[] yvalues;
////IMAGES////////////
PImage bg;
PImage buble;
////VARIABLE/////////
//int y;
float counter;
//float red, green, blue; //color variables
int bured; //for reset
//the spacing needs to be lower to make the grid look similar to the one you did manually.
int xspacing = 20;
int yLoc = 0;
int w;
/////ARRAY////////
ArrayList bubbles;
////SETUP///////////
void setup() {
size(800, 533);
colorMode(HSB, 255);
noStroke();
w = width+ 900;
dx = (TWO_PI / period) * xspacing;
yvalues = new float[w/xspacing];
/////BACKGROUND////
//bg = loadImage("ashpalt.jpg");
background(0);
//image (bg, 0, 0);
buble = loadImage ("bubble.png");
bubbles = new ArrayList();
}
/////SETUP///////
void draw () {
background(100);
renderWave();
calcWave();
}
void calcWave() {
//Movement of everything vertically
theta += 0.01;
float x = theta;
for (int i = 0; i < yvalues.length; i++) {
yvalues[i] = sin(x)*amplitude;
//make it wavy
x+=dx;
}
}
void renderWave() {
//drawing a grid of circles using for loop
//(look at grid of circles code from class)
for (int x = 0; x < yvalues.length; x++) {
for (int i = 0; i < height; i +=20) {
//reducing the range of the map so the color range shows up
// width/ higher or lower number changes the range of the colors
float c = map (x, 0, width/20, red, yellow);
stroke(c,50,255);
fill(c, 255, 255);
ellipse (x*xspacing, yvalues[x] + i, 12, 12);
fill(c, 255, 250);
ellipse (x*xspacing, yvalues[x] + i, 8, 8);
fill(c, 0, 0);
ellipse (x*xspacing, yvalues[x] + i,1,1);
}
}
/////BUBBLES////
for (int i = bubbles.size()-1; i >= 0; i--) {
Bubble bubble = (Bubble)bubbles.get(i);
bubble.update();
bubble.display();
}
counter += 1;
if (counter > 100) { //bubbless "pop" after a certain amount of time passes
counter = 1;
if (bubbles.size() > 1) { //limits removal
bubbles.remove(0); //removes oldest bubbles
}
}
}
void mousePressed() {
if (mouseButton == LEFT) {
bubbles.add(new Bubble());
}
}
class Bubble {
//PImage buble;
//X Axis Variables
float dia = random(50, 150); //diameter
//float diaF = dia; //dia follower
float locX = mouseX; //x
float locXF = locX; //follower x
int dirX = 1;
float speedX = 3;
//Y Axis Variables
float locY = mouseY; //y
float locYF = locY; //follower y
int dirY = 1;
float speedY = 3;
//color variables
float r, g, b;
int rStart = int(random(0, 400));
int rEnd = int(random(0, 600));
Bubble() {
} //end of constructor
void update() {
locX += speedX * dirX; //X velocity
locY += speedY * dirY; //Y velocity
// X bounce
if (locX >= width - (dia/2)) { //right wall
locX = width-(dia/2);
dirX *= -1;
speedX = random(.1, .3);
}
if (locX <= 0 + (dia/2)) { //left wall
locX = 0 + (dia/2);
dirX *= -1;
speedX = random(1, 3);
}
// Y bounce
if (locY >= height - (dia/2)) { //bottom wall
locY = width-(dia/2);
dirY *= -1;
speedY = random(1, 3);
}
if (locY <= 0 + (dia/2)) { //top wall
locY = 0 + (dia/2);
dirY *= -1;
speedY = random(1, 3);
}
//movement
locXF += (locX-locXF)*0.1;
locYF += (locY-locYF)*0.1;
if (dist(mouseX, mouseY, locXF, locYF) < dia/2+10) { //if mouse near bubble, speed up
speedX = random(5, 7);
speedY = random(5, 7);
}
} //end of update
void display() {
imageMode(CENTER);
image(buble, locXF, locYF, dia, dia);
}
}