# Why things doesn’t turn out how it’s supposed to be?

```PImage bg;
Hand hand;
Timer timer;
Blood[] blood;       // arry for thing
int totalBlood = 0; // total blood

void setup() {
size(600, 372);
smooth();
hand = new Hand(32); // radius
blood = new Blood;
timer = new Timer(70);
timer.start();
}

void draw() {

hand.setLocation(mouseX, mouseY);
hand.display();

if (timer.isFinished()) {
blood[totalBlood] = new Blood();
totalBlood ++ ;
if (totalBlood > blood.length) {
totalBlood = 0;
}
timer.start();
}

// the drippy effect?

for (int i = 0; i < totalBlood; i++ ) {
blood[i].move();
blood[i].display();
if (hand.intersect(blood[i])) {
blood[i].caught();
}
}
}

////////////////////hand class/////////////////////////

class Hand {
float r;
float x, y;

Hand(float tempR) {
r = tempR;
color(255);
x = 0;
y = 0;
}

void setLocation(float tempX, float tempY) {
x = tempX;
y = tempY;
}

void display() {
stroke(255);
fill(255);
ellipse(x, y, r*2, r*2);
}

boolean intersect(Blood d) {
float distance = dist(x, y, d.x, d.y);

if (distance < r + d.r) {
return true;
}
else {
return false;
}
}
}

////////////////////////////////////////dripping//////////////////////////////////////

class Blood {
float x, y;
float speed;
float r;

Blood() {
r = 10;
x = random(width);
y = -50;
speed = random(2, 5);
color(255, 0, 0);
}

// make the blood drop
void move() {
y += speed;
}

boolean reachedBottom() {
if (y > height + r*4) {
return true;
}
else {
return false;
}
}

void display() {
fill(255,0,0);
noStroke();
for (int i = 2; i < r; i++ ) {
ellipse(x, y, i*2, i*2);
}
}

void caught() {
speed = 0;
y = - 1000;
}
}

////////////////////Timer kind of//////////////////////////////////

class Timer {

int savedTime;
int totalTime;

Timer(int tempTotalTime) {
totalTime = tempTotalTime;
}

// Starting the timer
void start() {
// When the timer starts it stores the current time in milliseconds.
savedTime = millis();
}

boolean isFinished() {
// Check how much time has passed
int passedTime = millis()- savedTime;
if (passedTime > totalTime) {
return true;
}
else {
return false;
}
}
}```

My original idea didn’t work so I just sort of went with my mistake and made this…

It is supposed to rain Oscars and leo’s head is supposed to be your mouse, trying to catch his dignity and glory. But the image won’t load, and the oscar (now blood) left a trail behind it. So now the project became weirdly violent and emo….

# Object Oriented: Space Jam

Space Jam was on TV. ’nuff said.

Michael Jordan’s firey, inquisitive eyes are the only thing that can block the five Monstars’ (Pound, Bupkus, Bank, Blanko, and Nawt) shots. Use your mouse to block the shots. I tried adding music, but couldn’t get around a file type error. See the commented out parts (audio code from Anna). Next steps include:

-a score/block counter

-debugging for the egdechecks

-more sound effects

-idk, you tell me!

```//import ddf.minim.spi.*;
//import ddf.minim.signals.*;
//import ddf.minim.*;
//import ddf.minim.analysis.*;
//import ddf.minim.ugens.*;
//import ddf.minim.effects.*;
PImage background;
float blockheight;

//Minim minim;
//AudioPlayer sou;

Cube pound;
Cube bupkus;
Cube bang;
Cube blanko;
Cube nawt;
Block mj;

void setup () {
size(894,894);
smooth();
//minim = new Minim(this);
//sou.loop();
pound = new Cube(); //cube is constructor: birth of object
bupkus = new Cube();
bang = new Cube();
blanko = new Cube();
nawt = new Cube();
mj = new Block();

}

void draw () {
background(background);
mj.exist();
pound.launch();
bupkus.launch();
bang.launch();
blanko.launch();
nawt.launch();
}```

```class Cube {
float xpos;
float ypos;
float xspeed;
float yspeed;
float ballsize;

Cube(){
xpos=random(width);
ypos= height;
yspeed= random(1,6);
xspeed= random(-5,5);
ballsize=57;
}

void launch () {
blockCheck();
xCheck();
display();
move();
}

void display () {
stroke(0);
fill(255);

}

void move (){
ypos = ypos - yspeed;

if (yspeed < 0) {
xpos = xpos - xspeed;
}
}

void blockCheck () {
if (ypos <= blockheight && xpos > mouseX && mouseX + 100 > xpos || ypos >= height+1) {
yspeed = -yspeed;
}
}

void xCheck () {
if (xpos>=width || xpos<=0) {
xspeed = -xspeed;
}
}
}

class Block {
float blocky;
PImage jordaneyes;

Block () {
blocky = 0;
blockheight = 30;
}

void exist () {
image(jordaneyes, mouseX, blocky, 100, blockheight);
}
}```

# If you ever need crazy colorful circles for whatever reason

(But where is my shooting star?)

```//float sizeX;
int x = 0;
int y = 0;
int xspeed = 30;
int yspeed = 10;
int count = 500;
Circles [] circles;

//INITIALIZE VARIABLE
void setup(){
size(800,800);
background(255);
//cloudX = width/2;
//cloudY = height/2;
circles = new Circles[count];
for (int k = 0; k < count; k++){
circles[k] = new Circles();
}
}

//USE VARIABLE
void draw(){
for (int i = 0; i < count; i++){
circles[i].draw();
}

//shootingStar();
//Dan's code:
//fill(0,0,0,10);
//rect(0,0,width,height);
}

void shootingStar(){
x = x + xspeed;
y = y + yspeed;

if (x > width || x < 0){
xspeed = xspeed * -1;
}

if (y > height || y < 0){
yspeed = yspeed * -1;
}

if(mousePressed){
stroke(255,215,10,100);
fill(255,215,10,100);
//ellipse(x,y,32,32);
beginShape();
vertex(x,   y-50);
vertex(x+14,y-20);
vertex(x+47,y-15);
vertex(x+23,y+7);
vertex(x+29,y+40);
vertex(x,   y+25);
vertex(x-29,y+40);
vertex(x-23,y+7);
vertex(x-47,y-15);
vertex(x-14,y-20);
endShape(CLOSE);
}
}

class Circles{
float cloudX = random(0,255);
float cloudY= random(0,255);

float r = random(0,255);
float g = random(0,255);
float b = random(0,255);
float a = random(0,255);

void draw(){
cloudX = random(width);
cloudY = random(height);
stroke(r,g,b,a);
fill(r,g,b,a);
ellipse(cloudX,cloudY,200,100);
}
}```

# too much travolta for one brain to handle…

So I have turned my travolta ball into an object and created an array list to organize various objects. However, for some reason I’m having trouble having to so a new ball is created with each click. For some reason, it either creates 2 or 3 new balls- but never more than four. Sadly, I’m not going to be in class today but I will keep tinkering away. I’m probably getting close to breaking the world record of longest stare-off with John Travolta’s face- so, if someone has any ideas I would gladly appreciate them.

This is how far I’ve gotten… And this is my code:

```Travoltaball[] travoltaballs = new Travoltaball;
PImage travoltaBackground;
PImage travoltaPic;

int total = 0;

void setup() {
size(1100, 688);
for (int i = 0; i < travoltaballs.length; i++) {
travoltaballs[i] = new Travoltaball();
}
}

void mousePressed() {
total = total + 1;
for (int i = 0; i < total; i++) {
travoltaballs[i].ballAppear();
}
}

void draw () {
background(travoltaBackground);
for (int i = 0; i < total; i++) {
travoltaballs[i].displaytravolta();
travoltaballs[i].moveball();
travoltaballs[i].checkedges();
}
}

class Travoltaball {

float size = 60;
float posX = 60;
float posY = 100;
float speedX = 10;
float speedY = 10;

void displaytravolta() {
image(travoltaPic, posX-20, posY-20);
}

void ballAppear() {
posX = mouseX;
posY = mouseY;
speedX = speedX * -1;
speedY = speedY * -1;
}

void moveball() {
posX = posX + speedX;
posY = posY + speedY;
}

void checkedges() {
if (posX > width ||posX < 0) {
speedX = speedX * -1;
}
if (posY > height ||posY < 0) {
speedY = speedY * -1;
}
}
}```

# Lunch Under the Sea!

It’s a fish-eat-fish world out there, and you start out on the bottom of the food chain in this game.. As a tiny white fish (controlled by your mouse), gobble your prey and if you eat enough, you grow in size. Just make sure to avoid your predators!

Can you make it to the top? Here’s the entire setup (I include pictures and a certain font type so they’ll be necessary for running it successfully)

Here is my main code:

```//Fish Objects:
Fish self;
Fish test;
Fish[] prey_array = new Fish;
Fish[] predator_array = new Fish;

int number_of_predator; //Uses to manipulate predator array length for each level
int number_of_prey_eaten; //Uses to manipulate prey array lengths for interactions
int temp_num_prey_eaten; //Changes inside the prey collision for loop and will be set to the prey_eaten after the for loop (without dynamically changing the for loop)
int[] temporary_array_shift = new int; //stores the indexes of all the prey objects that have been eaten

int actual_prey_eaten_per_level;
/*Will be set to the difference between temporary prey eaten and regular prey eaten and will be used to set the for loop parameters
Will be use "see" how many fish were consumed per draw loop (not per level)
*/

int index_of_new_array; //

//Setting level booleans: used to "start" the each level once without it looping and constantly restarting
boolean level_1, level_2, level_3, level_4, level_5;

//Counter that sets parameters of each level:
int total_eat_count;

//Used to control lose screen:
boolean lose;

//Used for controlling special self and prey object (surprise!)
boolean self_surprise; boolean prey_surprise;

PImage sea_win;
PImage diver;
PImage bone;
PFont font;

void setup() {
size(900, 700);
//Set all the booleans true to start each level. They will be used once to intialize the start of each level ONCE
level_1=true;
level_2=true;
level_3=true;
level_4=true;
level_5=true;

total_eat_count = 0;

number_of_predator = 0;
initializePrey(247, 77, 214, 25);
initializePredator(60, 245, 60, 75);
index_of_new_array=0;
number_of_prey_eaten = 0;
temp_num_prey_eaten = 0;
self = new Fish(0, 0, 0, 40, 1, 1, 0, 0);

lose = false;
//Set up font:
self_surprise = false;

}

void draw() {

if (lose==false){
background(00, 00, 200);
//moving self

if (self_surprise == false){
self.move_Self();
}
else if(self_surprise){
self.changetoMerman();
}
//PREDATOR:
for (int i=0;i<predator_array.length - number_of_predator;i++) {
predator_array[i].moveFish();
if (predator_array[i].checkBoundaries()) {
predator_array[i].move_back_Fish();
}
if (predator_array[i].check_Collision(self)){
lose = true;
}
}

//PREY:
index_of_new_array =0;
//Moving Fish:
for (int i=0;i<prey_array.length- number_of_prey_eaten;i++) {

//Use boolean for surprise!
if (prey_surprise == false){

//Moving fish (and accomodating when it goes out of bounds)
prey_array[i].moveFish();
}
else if(prey_surprise)
{
prey_array.draw_diver();
}
if (prey_array[i].checkBoundaries()) {
prey_array[i].move_back_Fish();
}
if (prey_array[i].check_Collision(self)) {
total_eat_count++;
temp_num_prey_eaten++;
temporary_array_shift[index_of_new_array]=i;
index_of_new_array++;
}
}
actual_prey_eaten_per_level = temp_num_prey_eaten - number_of_prey_eaten;
number_of_prey_eaten = temp_num_prey_eaten;
for (int i=0;i<actual_prey_eaten_per_level;i++) {
shifting_index(temporary_array_shift[i]); //For EACH fish that is eaten (for loop), the index of the prey_array will be shifted over
}

nextLevel();

}

else if(lose == true){
background (255,0,0);
image(bone, 300, 400, 200, 150);
textFont(font, 48);
fill(0,0,0);
text ( "You've been eaten!" ,200,300);
}

}
//END OF DRAW

//Other Methods:

//Initializing Prey/Predator:
void initializePrey(int red, int green, int blue, int size) {
Fish[] temp = new Fish;
for (int i=0;i<prey_array.length;i++) {
temp[i] = new Fish(red, green, blue, size, (int)random(0, width), (int)random(0, height), random(-3, 3), random(-3, 3));
}
for (int i=0;i<prey_array.length;i++) {
prey_array[i] = temp[i];
}
}

void initializePredator(int red, int green, int blue, int size) {
for (int i=0;i<predator_array.length;i++) {
predator_array[i] = new Fish(red, green, blue, size, (int)random(0, width), (int)random(0, height), random(-3, 3), random(-3, 3));
}
}

//"Shifting" remaining uneaten fish over one index to the left
void shifting_index(int index) {
for (int j = index; j<prey_array.length-1;j++) {
prey_array[index] = prey_array[index+1];
}
}
//Next Level functions:
void nextLevel() {
int level = 0;
//Convert number of prey eaten to level amounts:
if (total_eat_count <= 9) {
level = 1;
if (level_1) {
initializePrey(247, 77, 214, 25);
initializePredator(60, 245, 60, 75 );
self.change_fish_color(255, 255, 255);
self.change_fish_size(50);
number_of_prey_eaten=0;
number_of_predator = 0;
temp_num_prey_eaten =0;
level_1=false;
}
}
if (total_eat_count <= 18 && total_eat_count > 9) {
level = 2;
if (level_2) {
initializePrey(255, 255, 255, 50);
initializePredator(153, 76, 0, 100);
number_of_prey_eaten=1;
temp_num_prey_eaten=1;
number_of_predator = 3;
self.change_fish_color(60, 245, 60);
self.change_fish_size(75);
level_2=false;
}

}
if (total_eat_count <= 23 && total_eat_count > 18 ) {
level = 3;
if (level_3) {
initializePrey(60, 245, 60, 75);
initializePredator(135, 31, 166, 175);
self.change_fish_color(153, 76, 0);
self.change_fish_size(100);
number_of_predator = 4;
number_of_prey_eaten=5;
temp_num_prey_eaten=5;
level_3=false;
}

}
if (total_eat_count == 24) {
level = 4;
if (level_4) {
initializePrey(255, 255, 255, 75);
prey_array.draw_diver();
initializePredator(0, 0, 0, 250);
self.change_fish_color(132, 224, 247);
self.change_fish_size(175);
number_of_prey_eaten=9;
temp_num_prey_eaten=9;
number_of_predator = 6;
prey_surprise = true;
level_4=false;
}
total_eat_count=24;
}
if (total_eat_count == 25) {
level = 5;
if (level_5) {
number_of_prey_eaten=10;
temp_num_prey_eaten=10;
number_of_predator = 7;
level_5=false;
}
self_surprise = true;
textFont(font, 36);
fill(255,255,255);
text ( "You're the king of the sea!" ,250,300);
}

}//End of next_level function  INSERT PIC OF HUMAN SWIMMING  case 4: initializePrey

//Level reset function:
void level_reset(){
//Set all level booleans back so that levels can re-initialize again & reset level_progression variable back to 0
level_1=true;
level_2=true;
level_3=true;
level_4=true;
level_5=true;
total_eat_count = 0;
self_surprise= false;
prey_surprise = false;
}

void keyPressed(){
lose = false;
level_reset();
}```

And here is my separate fish class file:

```class Fish {
//Fish color:
int r;
int g;
int b;

//Fish size
int fish_width;
int fish_height;
int fish_size;

//Fish position
int x;
int y;

//Fish speed
float velocity_x;
float velocity_y;

//For when fish is eaten --> variable
boolean eaten = false;

//Constructor
Fish(int _r, int _g, int _b, int _fish_size, int _x, int _y, float _velocity_x, float _velocity_y) {
r = _r;
g = _g;
b = _b;
fish_size = _fish_size;
fish_width = 2 * _fish_size;
fish_height = _fish_size;
x = _x;
y = _y;
velocity_x = _velocity_x;
velocity_y = _velocity_y;
}

void drawFish() {
stroke(r, g, b);
fill(r, g, b);
triangle(x, y, x, y+fish_height, x+ (fish_width/3), y+(fish_height/ 2));
ellipse((x+((10*fish_width/18))), y+(fish_height/2), ((2*fish_width)/3), (15*fish_height/16));
}
void moveFish() {
x+=velocity_x;
y+=velocity_y;
this.drawFish();
}

boolean checkBoundaries() {
boolean out_of_bounds = false;
//Out of screen (horizontal)
if (x>(width+(1.5* fish_width))|| x < (0 - (1.5*fish_width))) {
out_of_bounds = true;
}

//Out of screen (vertical)
if (y>(height+(1.5*fish_height)) || y < (0 - (1.5* fish_height))) {
out_of_bounds = true;
}
return out_of_bounds;
}

void move_Self() {
x = mouseX -(fish_width / 2);
y = mouseY - (fish_height / 2);
this.drawFish();
}

void move_back_Fish() {
//Will randomize the side from which the fish returns
//Will maintain the same magnitude of velocity
/* Must figure out magnitude from original x and y velocities
Then use magnitude to determine the new velocities
Use random to find new angle of reentry (radians)
magintude SIN (theta) = y
magnitude COS (theta) = X
*/

float theta = random(.1*PI, .9*PI);

float magnitude = 0;
magnitude = sqrt((float)(Math.pow(velocity_x, 2))+(float)(Math.pow(velocity_y, 2)));
int side = (int) random(1, 5);
switch (side) {
//Top
case 1:
y = 0 - fish_height;
x = width/2;
velocity_y = (magnitude * sin(theta));
velocity_x = (magnitude * cos(theta));
break;

//Bottom
case 2:
y = height + fish_height;
x = 450;
velocity_y = -(magnitude * sin(theta));
velocity_x = (magnitude * cos(theta));
break;

//Left
case 3:
y = 375;
x = 0 - fish_width;
velocity_y = (magnitude * sin(theta));
velocity_x = (magnitude * cos(theta));
break;
//Right
case 4:
y = 375;
x = width + fish_width;
velocity_y = (magnitude * sin(theta));
velocity_x = -(magnitude * cos(theta));
break;
}
}

//Getter Methods for collision detection
int get_X_Position() {
return x;
}
int get_Y_Position() {
return y;
}
int get_fish_Height() {
return fish_height;
}

int get_fish_Width() {
return fish_width;
}
//COLLISION
boolean check_Collision(Fish temporary) {
boolean signal = false;
int temp_x = temporary.get_X_Position();
int temp_y = temporary.get_Y_Position();
int temp_fish_height = temporary.get_fish_Height();
int temp_fish_width = temporary.get_fish_Width();

if (x < (temp_x + temp_fish_width) && (x+fish_width) > (temp_x )) {
if (y < (temp_y + temp_fish_height) && (y+fish_height) > (temp_y )) {
signal = true;
}
else {
signal = false;
}
}
return signal;
}

//If prey and  self have collided, sets collided prey to eaten
void set_to_Eaten() {
eaten = true;
}
//Getter method to check if fish have been eaten
boolean get_if_Eaten() {
return eaten;
}

//Change fish color:
void change_fish_color(int _r, int _g, int _b){
r = _r;
g = _g;
b = _b;
}

void change_fish_size(int _size){
fish_size = _size;
fish_width = 2 * _size;
fish_height = _size;
}

void draw_diver(){
float temp_x = x;
float temp_y = y;
image (diver, temp_x, temp_y, 150, 75);
x+=velocity_x;
y+=velocity_y;
}

void changetoMerman(){
image(sea_win,mouseX,mouseY,250,400);
x = mouseX -(fish_width / 2);
y = mouseY - (fish_height / 2);

}

//End of Fish Class
}```

PS. Make it to level 4 and you’ll see a surprise.  Can you conquer the sea?

Potential improvement:

-I think I’d like to to make a smoother transition from game over to the reset level 1. I’ve had the displeasure of the pressing a key to reset the level but then automatically dying again because my fish is placed over where the predators are drawn..

– Fix this weird glitch where sometimes two fish are “eaten”

-Fix “stuck” moments

# FIXED!! Pee Dodge – The R.Kelly Saga Completed

NEW VIDEO OF WORKING GAME:

http://youtu.be/cHm3-YetP2s For this week, I worked on a game that I started at the end of last class. Unfortunately, over break my access to computers/internet was much more limited than I had anticipated, so I did not have as much time to work on this as I would have liked.

The basic premise is dodging drops of R.Kelly’s pee by controlling an avatar which follows your mouse. Every time a pee drop hits, text should pop up saying “GROSS!” but I had some issues with getting int and float to work together, and figuring out .intersect. Hopefully I will be able to make some progress, but if not, maybe you guys can help. I found the code for the moving eyes here, so all credit for that feature goes to that awesome programmer: http://bavc-dposs.blogspot.com/2012/02/eye-follower-processing-sketch.html

Here is the video:

http://youtu.be/_mVIGnv1cJc

And the code:

```import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
PImage girl;
PImage kelly;

Minim minim;
AudioPlayer sou; //variable name;

Pee [] drops = new Pee ;

Eye eye1, eye2;

void setup() {
size(800, 600);
smooth();
minim = new Minim(this);
sou.loop();

for (int i = 0; i < drops.length; i++) {
drops [i] = new Pee(20);
}

eye1 = new Eye( width/2 - 70, height/3 + 10);
eye2 = new Eye( width/2 + 40, height/3 + 10);
}

void draw() {
background(#9D1BC9);
image (kelly,width/2, height/2);
// update eye 1
eye1.update();
eye1.draw();

// update eye2
eye2.update();
eye2.draw();

runGirl();
// if (drops.intersect(mouseX)){
//    touchText();
// }
for (int i = 0; i < drops.length; i++) {
drops[i].fall();
drops[i].display();
drops[i].bottom();
if(dist(drops[i].x, drops[i].y,mouseX,mouseY) < 25){
println("gross");
touchText();
}
}

}

void runGirl() {
image (girl, mouseX, mouseY, 50, 50);
imageMode (CENTER);
}

void touchText(){
textSize(150);
fill (#FF0000);
text ("GROSS!", 150, 150);
}```

EYE

```class Eye {

// eye position and diameter
float x, y, dia = 30;

// pupil position and diameter
float pupilx, pupily, pupildia = 40;

// eye setup
Eye(float _x, float _y) {
// setting the initial variables of the eye
x = _x;
y = _y;
pupilx = x;
pupily = y;
}

// eye update
void update() {

// distance from mouse center
float d = dist(mouseX, mouseY, x, y);

if (d < dia/2) {
// if mouse is inside the eye
// set the pupil to the mouse position
pupilx = mouseX;
pupily = mouseY;
}
else {
// else, mouse is outside the eye
// point the pupil at the mouse
atan2(mouseY-y, mouseX-x);
float r = atan2(mouseX-x, mouseY-y);
pupilx = sin(r) * dia/2 + x;
pupily = sin(r + PI/2) * dia/2 + y;
}

}

// eye draw
void draw() {

// eye background
stroke(0);
fill(255);
ellipse(x, y, dia+pupildia, dia+pupildia);

// pupil
noStroke();
fill(0);
ellipse(pupilx, pupily, pupildia, pupildia);
}
}```

PEE

```class Pee {

float x;
float y;
float diameter;
float yspeed;

Pee(float tempD){
x = random (width);
y = 0;
diameter = tempD;
yspeed = random (0.5, 2.5);
}

void fall(){
y = y + yspeed;
x = x + random (-2,2);
}

void display(){
noStroke();
fill(#FFF380, 95);
ellipse(x,y, diameter, diameter);
}

void bottom(){
if (y > height){
y = 0;
}
}
}```

# Risky Business (Take a Chance on Cheese)

This time around I used an array to make many cheeses and added a nasty carpet in the background. And the little mouse is in there, too!

I tried to see how I could get the cheese to identify when it was clicked, but couldn’t figure it out. Ideally, as the mouse eats the cheese, the cheese would disappear.

Cheese Array Files

```//PART 1
PImage cat;
PImage lilmouse;

Cheese[] cheeses = new Cheese;   //declare an array of 50 cheeses
float grav;
PImage bImgFor;
PImage bImgRev;
PImage bCarpet;
//PImage fGrass;

//PART 2
void setup() {
size(720, 480);
for (int i=0; i < cheeses.length; i++) {   //Loop to initialize each object in the array
cheeses[i] = new Cheese();
}
}
//PART 3

void draw() {
image(bCarpet, 0, 0, width, height);

spinCat();
for (int i=0; i < cheeses.length; i++) {   //Loop to display and move each object in the array
cheeses[i].display();
cheeses[i].move();
}

}

/// CLASS CHEESE

class Cheese {
float x;
float y;
float w;
float xSpeed;
float ySpeed;
PImage b;

Cheese() {   //Constructor!
x = random(20, 600);
y = random(0, height/2);
w = random(10, 100);
xSpeed = 5;
ySpeed = 0;
b = bImgFor;
}

void display() {  //display cheeses
if (x < 0) {
b = bImgFor;
}
image(b, x, y, w, w);
}

void move() {
x = x + xSpeed;
y = y + ySpeed;
ySpeed = ySpeed+grav;
if (y > height-w) {
ySpeed = ySpeed * -0.95;
}
if (x > width-w) {
xSpeed = xSpeed * -1;
}
if (x < 0) {
xSpeed = xSpeed * -1;
}
}
}

void spinCat() {
translate (width/2, height/2);
rotate(frameCount / 100.0);
for (int s=0; s<1; s++) {
image (cat, 100 + s*10, 0, 200, 300);
}}```

# plus-plus drip

i recently joined a multimedia artist collective and i’ve been working on visuals for it. it’s called the ++ collective. please watch the sketch at the following link:

https://vimeo.com/89892527

```Plus1[] p1 = new Plus1;
Plus2[] p2 = new Plus2;
PImage plus1;
PImage plus2;
PImage plusfill;

void setup() {
background(255);
size(1280, 720);

for (int i = 0; i < p1.length; i++) {
p1[i] = new Plus1(i *4 );
}

for (int i = 0; i < p2.length; i++) {
p2[i] = new Plus2(i *4 );
}
}

void draw() {

for (int i = 0; i < p1.length; i++) {
p1[i].drawplus1();
p1[i].move();
p1[i].bottom();
}

for (int i = 0; i < p2.length; i++) {
p2[i].drawplus2();
p2[i].move();
p2[i].bottom();
}

image(plusfill, 0, 0, 1280, 720);

}

class Plus1 {

float x;
float y;
float size;
float yspeed;
float xspeed;

Plus1(float tempD) {
x = random(width);
y = 0;
size = tempD;
yspeed = random(0.5, 2.5);
}

void drawplus1() {
smooth();
image(plus1, x, y-25, 50, 50);
}

void move(){
y = y + yspeed/2;
x = x + random(-2, 2);
}

void bottom() {
if (y > height) {
y = 0;
}
}
}

class Plus2 {

float x;
float y;
float size;
float yspeed;
float xspeed;

Plus2(float tempD) {
x = random(width);
y = 0;
size = tempD;
yspeed = random(0.5, 2.5);
}

void drawplus2() {
smooth();
image(plus2, x, y-25, 50, 50);
}

void move(){
y = y + yspeed/2;
x = x + random(-2, 2);
}

void bottom() {
if (y > height) {
y = 0;
}
}
}```

# Piggy Bubbles

So I wanted to make something with bubbles just to figure out object oriented programming. But I wanted to take it a step further by adding something with popping. Then I thought… WAIT…. I NEED SOUND! So I decided to add a wide variety of sounds with each bubble corresponding to a different sound.

And here is my code, the sound files were taken from freesound.org and I’ll put them on my flashdrive so we can hear them.

```//imports sounds library and sets up sound
import ddf.minim.*;
Minim m;
AudioPlayer s0,s1,s2,s3,s4,s5,s6,s7,s8,s9;
AudioPlayer[] sounds;

//background photo
PImage photo;

//creates bubble array
Bubble[] bubbles = new Bubble;

void setup() {
size(510, 418);
bubbles = new Bubble();
bubbles = new Bubble();
bubbles = new Bubble();
bubbles = new Bubble();
bubbles = new Bubble();
bubbles = new Bubble();
bubbles = new Bubble();
bubbles = new Bubble();
bubbles = new Bubble();
bubbles = new Bubble();

m = new Minim(this);
sounds = new AudioPlayer;

}

void draw() {
smooth();
background(photo);
bubbles.everything();
bubbles.everything();
bubbles.everything();
bubbles.everything();
bubbles.everything();
bubbles.everything();
bubbles.everything();
bubbles.everything();
bubbles.everything();
bubbles.everything();

}

void stop() {
s1.close();
m.stop();
super.stop();
}

void mouseClicked() {
popDist(0);
popDist(1);
popDist(2);
popDist(3);
popDist(4);
popDist(5);
popDist(6);
popDist(7);
popDist(8);
popDist(9);
}

void popDist(int tempNum) {
if ( dist(mouseX, mouseY, bubbles[tempNum].x, bubbles[tempNum].y) <= bubbles[tempNum].Size) {
float soundNot = random(0,9);
int soundNum = int(soundNot);
sounds[soundNum].play();
sounds[soundNum].rewind();
bubbles[tempNum].bubbleChange();
}
}```

and here is the bubble class with the functions:

```class Bubble {
float x;
float y;
float Red=random(1, 255);
float Green=random(1, 255);
float Blue=random(1, 255);
float Opaque=random(75, 200);
float Size=random(50, 90);

//creates the bubble location
Bubble() {
x = random(width);
y = height;
}

void everything() {
display();
ascend();
top();
}

//creates the bubble
void display() {
noStroke();
fill(Red, Green, Blue, Opaque);
ellipse(x, y, Size, Size);
}

//makes the bubble rise
void ascend() {
y--;
x = x +random(-2, 2);
}

//checks if the bubble reaches the top
void top() {
if (y < 0-Size) {
bubbleChange();
}
}

//changes bubble properties
void bubbleChange() {
y = height+Size;
x = random(width);
Red = random(1, 255);
Green = random(1, 255);
Blue = random(1, 255);
Opaque = random(75, 200);
Size = random(50, 90);
}

}```

# Lucky Star

For this assignment, I wanted to try a little bit of everything. I tried out the P3D mode of animation, the minim library, push and pop matrixes, and a PShape definition as well as object oriented stuff. Admittedly, some of the code is found which I then tweaked. Whatever I did copy, I made sure I understood it so that it was still a learning process(ing) lol. What was important to me this week was to just try out everything and get a grasp on what I could. This assignment has a few files to go with it, so here is a zip file of it 🙂 Zzzzzzip

# Geometry Game

The purpose of the game is to move the mouse to move the circle and avoid the moving shapes. If the mouse hits one of the shapes, the circle’s radius gets larger until it grows to cover the whole screen. Some of the shapes change color if it touches the mouse-circle. Players can press ‘h’ to freeze the shapes for 0.5s and move the mouse around (as a helper), and press ‘q’ to restart the game. I want to add ‘levels’ to the game by increasing the number of shapes on the screen after a set amount of time by adding a boolean/timer buuuuuttttt…… uh I still have to figure that out!! https://vimeo.com/89877903

```Mouse theMouse;
Square [] theSquare = new Square;
Circle [] theCircle = new Circle ;
Triangle [] theTriangle = new Triangle;
Star [] theStar = new Star;
float r = 12;
boolean startGame = false;

void setup() {
size (900, 600); //P2D
theMouse = new Mouse();
for (int i=0; i<3; i++) {
theSquare[i] = new Square (90);
}
for (int i=3; i<6; i++) {
theSquare[i] = new Square (50);
}
for (int i=0; i<3; i++) {
theCircle[i] = new Circle (80);
}
for (int i=3; i<5; i++) {
theCircle[i] = new Circle (60);
}
for (int i = 0; i < theTriangle.length; i++) {
theTriangle[i] = new Triangle (50);
}
for (int i = 0; i < theStar.length; i++) {
theStar[i] = new Star ();
}
}

void draw() {
background (255);
grid();

theMouse.position(mouseX, mouseY);
for (int i = 0; i < theSquare.length; i++) {
theSquare[i].move();
if (theMouse.intersectS(theSquare[i])) {
theMouse.grow();
theSquare[i].highlight();
}
}

for (int i = 0; i < theCircle.length; i++) {
theCircle[i].move();
if (theMouse.intersectC(theCircle[i])) {
theMouse.grow();
theCircle[i].highlight();
}
}

for (int i = 0; i < theTriangle.length; i++) {
theTriangle[i].move();
if (theMouse.intersectZ(theTriangle[i])) {
theMouse.grow();
theTriangle[i].highlight();
}
}

for (int i = 0; i < theStar.length; i++) {
theStar[i].move();
if (theMouse.intersectD(theStar[i])) {
theMouse.grow();
theStar[i].highlight();
}
}

theMouse.display();
for (int i = 0; i < 5; i++) {
theSquare[i].display();
}

for (int i = 0; i < 5; i++) {
theCircle[i].display();
}

for (int i = 0; i < theTriangle.length; i++) {
theTriangle[i].display();
}

for (int i = 0; i < theStar.length; i++) {
theStar[i].display();
}
}

void keyPressed() {
if (key == 'q') {
r = 12;
}

if (key == 'h') { //'help' button
delay(500);
}
}

//Circle
class Circle {
float circleX, circleY; //circle location
float circleXspeed, circleYspeed;
color cc = color(0, 0, 255, 200);
boolean fill = false;

Circle(float tempW) {
w = tempW;
circleX = random(w, 5*w);
circleY = random(w, 5*w);
circleXspeed = random(3, 5);
circleYspeed = random(3, 5);
}

void move() {
circleX = circleX + circleXspeed;
circleY = circleY + circleYspeed;
//boundary conditions
if (circleX>width-w/2||circleX<w/2) {
circleXspeed = -circleXspeed;
}
if (circleY>=height-w/2||circleY<w/2) {
circleYspeed = -circleYspeed;
}
}

void highlight() {
fill = true;
}

void display() {
if (fill = true) {
noStroke();
fill (255, 215, 10, 200);
}
else {
stroke(0, 0, 255);
noFill();
}
shapeMode(CENTER);
ellipse(circleX, circleY, w, w);
cc = color(0, 0, 255, 200);
}
}

//Grid
float k=0;
float j=0;//gridlines
float l = 100; //length of square

void grid() {
for (k=0; k<height/l; k++) {
for (j=0;j<width/l;j++) {
stroke(103, 227, 215);
strokeWeight(1.2);
line(j*l, 0, j*l, height); //use j*s if width>height
line(0, j*l, width, j*l); //use k*s if height>width
}
}
}

//Mouse
class Mouse {
float x, y; //position

Mouse() {
r = 12;
}

void grow() {
r = r + 1;
}

void position(float tempX, float tempY) {
x = tempX;
y = tempY;
}

void display() {
stroke(0);
strokeWeight(3.5);
noFill();
ellipse(x, y, r*2, r*2);
}

boolean intersectS(Square q) {
float distanceS = dist(x, y, q.squareX, q.squareY);
if (distanceS < r + q.s) {
return true;
}
else {
return false;
}
}

boolean intersectC(Circle t) {
float distanceC = dist(x, y, t.circleX, t.circleY);
if (distanceC < r + t.w) {
return true;
}
else {
return false;
}
}

boolean intersectZ(Triangle p) {
float distanceZ = dist(x, y, p.triangleX, p.triangleY);
if (distanceZ < r + p.h) {
return true;
}
else {
return false;
}
}

boolean intersectD(Star d) {
float distanceD = dist(x, y, d.starX, d.starY);
if (distanceD < r + 50) {
return true;
}
else {
return false;
}
}
}

//Square
class Square {
float s; //square side
float squareX, squareY; //square location
float squareXspeed, squareYspeed;
color qc = color(255, 139, 242, 200);
float rotation;

Square(float tempS) {
s = tempS;
squareX = random(2*s, width - 4*s);
squareY = random(2*s, width - 4*s);
squareXspeed = random(4, 6);
squareYspeed = random(4, 6);
}

void move() {
squareX = squareX + squareXspeed;
squareY = squareY + squareYspeed;
//boundary conditions
if (squareX>width-s/2||squareX<s/2) {
squareXspeed = -squareXspeed;
}
if (squareY>=height-s/2||squareY<s/2) {
squareYspeed = -squareYspeed;
}
}

void highlight() {
qc = color(0, 255, 0, 200);
}

void display() {
noStroke();
fill(qc);
rotation = rotation+0.08;
pushMatrix();
translate(squareX, squareY);
rotate(rotation);
rectMode(CENTER);
rect(0, 0, s, s);
popMatrix();
qc = color(255, 0, 0, 200);
}
}

//Star
class Star {
float starX, starY; //star location
float starXspeed, starYspeed;
color sc = color(0, 255, 0, 200);

Star() {
starX = random(150, width - 150);
starY = random(150, 400);
starXspeed = random(3, 5);
starYspeed = random(2, 4);
}

void move() {
starX = starX + starXspeed;
starY = starY + starYspeed;
//boundary conditions
if (starX>width-50||starX<50) {
starXspeed = -starXspeed;
}
if (starY>=height-50||starY<50) {
starYspeed = -starYspeed;
}
}

void highlight() {
sc = color(255, 0, 0, 200);
}

void display() {
noStroke();
fill(sc);
shapeMode(CENTER);
beginShape();
vertex(starX, starY-50);
vertex(starX+14, starY-20);
vertex(starX+47, starY-15);
vertex(starX+23, starY+7);
vertex(starX+29, starY+40);
vertex(starX, starY+25);
vertex(starX-29, starY+40);
vertex(starX-23, starY+7);
vertex(starX-47, starY-15);
vertex(starX-14, starY-20);
endShape(CLOSE);
sc = color(0, 0, 255, 200);
}
}

//Triangle
class Triangle {
float h ; //half-side of tiangle
float triangleX, triangleY; //location
float triangleXspeed, triangleYspeed;
float tc = (#C2CECD);
float rotation;

Triangle(float tempH) {
h = tempH;
triangleX = random(4*h, width-4*h);
triangleY = random(4*h, height-4*h);
triangleXspeed = random(3, 5);
triangleYspeed = random(2, 4);
}

void move() {
triangleX = triangleX + triangleXspeed;
triangleY = triangleY + triangleYspeed;

if (triangleX > width -h || triangleX < h) {
triangleXspeed *= -1;
}

if (triangleY > height -h || triangleY < h) {
triangleYspeed *=-1;
}
}

void highlight(){
tc = (#15FFE9);
}

void display() {
stroke(0,255,0);
strokeWeight(8);
noFill();
rotation = rotation+0.08;
pushMatrix();
translate(triangleX, triangleY);
rotate(rotation);
shapeMode(CENTER);
triangle(-h, h, h, h, 0, -h/1.5);
popMatrix();
tc = color(255,0,0,200);
}
}```

# … v a c a t i o n …

Exam on Thursday… I’ve already mentally check out.
A visual representation of my [mushy] brain.

https://vimeo.com/88618166

```Ball [] ball = new Ball; //number of balls in array
PImage pineapple; //background image

void setup() {
size (700, 400);
pineapple.resize(width, height); //rescale background image to fit screen size
background (pineapple);
for (int i=0; i<ball.length; i++) {
ball[i] = new Ball (i*1.8); //determining size of ball by [i]
}
}

void draw() {
background(pineapple);
for (int i=0; i<ball.length; i++) {
ball[i].move();
ball[i].display();
ball[i].boundary();
}
}

class Ball {
float x;
float y;
float ySpeed;
float d; //diameter of ball

Ball(float _D) {
x = random(0, width);
y = height;
ySpeed = random(0.1, 2);
d = _D;
}

void move() {
x = x + random(-1, 1);
y = y -ySpeed;
}

void display() {
float t = random(100, 130);
stroke(0, 0, 255, t);
fill(255, 255, 255, t);
ellipse(x, y, d, d);
}

void boundary() {
if (y < d/2) {
y = height;
}
}
}```

# So I’m obsessed with One Direction… Hard to believe… But yes, I have been under the British/Irish boy band’s charm for years now..

For this week’s assignment, I started to work on a game where a crazy fan was chasing around One Direction. There’s definitely a lot more work to do with it.. I want to have something happen if the fan is over one of the boys, but nothing happens when I implement anything mouseClicked(). I’m not sure if this has anything to do with the construction of a new class and how it accesses that. I probably over complicated the code.

Here’s a video of the program running! ```import ddf.minim.*;

Minim minim;
AudioPlayer player;

Member [] oneDirection = new Member ;
float xPos, yPos;
float xSpeed, ySpeed;
PImage harry, liam, louis, niall, zayn;
PImage [] boy = {harry, liam, louis, niall, zayn };
PImage crazyFan;

void setup(){
size(800,600);
oneDirection = new Member(harry, xPos, yPos);
oneDirection = new Member(liam, xPos, yPos);
oneDirection = new Member(louis, xPos, yPos);
oneDirection = new Member(niall, xPos, yPos);
oneDirection = new Member(zayn, xPos, yPos);
minim = new Minim(this);
player.play();

}

void draw(){
background(255);
for (int i = 0; i < 5; i ++){
oneDirection[i].positionChange();
}

crazyFan.resize(0,150);
image(crazyFan,mouseX, mouseY);

oneDirection.drawHarry();
oneDirection.drawLiam();
oneDirection.drawLouis();
oneDirection.drawNiall();
oneDirection.drawZayn();

mouseClicked();

}

class Member{
float xPos = random(0,width-75);
float yPos = random(0,height-150);
float xSpeed = random (4.0, 6.0);
float ySpeed = random (4.0, 6.0);
PImage [] boy = {harry, liam, louis, niall, zayn };

//Constructor
Member(PImage lad, float xPos, float yPos){

}//constructor

void positionChange(){
if(xPos >= width - 75|| xPos <0){
xSpeed *= -1;
}
if(yPos >= height - 150 || yPos<0){
ySpeed *= -1;
}

xPos += xSpeed;
yPos += ySpeed;
}

void drawHarry(){
xPos += xSpeed;
yPos += ySpeed;
smooth();
harry.resize(0,150);
image(harry, xPos, yPos);
}

void drawLiam(){
xPos += xSpeed;
yPos += ySpeed;
smooth();
liam.resize(0,150);
image(liam, xPos, yPos);
}

void drawLouis(){
xPos += xSpeed;
yPos += ySpeed;
smooth();
louis.resize(0,150);
image(louis, xPos, yPos);
}
void drawNiall(){
xPos += xSpeed;
yPos += ySpeed;
smooth();
niall.resize(0,150);
image(niall, xPos, yPos);
}
void drawZayn(){
xPos += xSpeed;
yPos += ySpeed;
smooth();
zayn.resize(0,150);
image(zayn, xPos, yPos);
}

}//member```