Category Archives: Organized

Workin’ that cheese…

I want to eventually make a mouse have to catch the cheese and dodge the spinning cat.

VIDEO

PImage cheese;
PImage cat;

float siz = 30;
float posX = 20; 
float posY = 80;
float xspeed = 10; 
float yspeed = 6;

void setup(){
  size(900,600);
  cheese = loadImage("cheese_icon.png");
  cat = loadImage("cat_icon.png");

}

void draw(){
 // followMouse();
  mouseTime();
  spinCheese();

}

void mouseTime(){
  background(255,15,155);
  posX = posX + xspeed; 
  posY = posY + yspeed;

  if(posX > width ||posX < 0){
    xspeed = xspeed * -1;
  }
  if(posY > height ||posY < 0){
    yspeed = yspeed * -1;
  }

image(cheese, posX-40, posY-20);
}

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

}
}

 

A paint program?

void setup() {
  size(1000, 1000);
  background(0);
}

void draw() {

  variableEllipse(mouseX, mouseY, pmouseX, pmouseY);
}

void variableEllipse(int x, int y, int px, int py) {
  float speed = abs(x-px) + abs(y-py);
  fill((255-speed*0.2), 255, speed*20);
  noStroke();
  ellipse(x, y, speed/10, speed/10);

  for (int i = 3; i < height; i += 3) {

    stroke(0, 0, mouseX/4); 
    if (i < 300) { 
      stroke(mouseY/4, 0, 0);
    }
    line(width, i, 10, i);
  }
}

II really don’t know what this is…..

屏幕快照 2014-03-10 2.38.21 PM

Interactive Screen Saver: NOW WITH 20% MORE INTERACTIVITY

So I just continued to work on my bouncing ball screen saver thingy but I tried to add a new feature. A “stop sign” where if the mouse is in the stop sign the ball would stop bouncing until you move the mouse off of the sign. I got this to work… kinda… but there is one problem. If the ball is moving in a negative direction when it is stopped, then when it begins moving again it moves in the positive direction. I know why this is; however, I have not been able to figure out how to fix it.

Here is the code:

//going to need another variable to take care of the stop problem I think... maybe a for loop? Always goes positive when stopped
float circlex = 0;
float xSpeed = 2;
float xVelocity = 2;
float circley =0;
float ySpeed = 2;
float yVelocity = 2;
float i = 0;
float red = random(255);
float green = random(255);
float blue = random(255);
void setup() {
  size(1360, 700);
  background (75, 100, 200);
}
void mouseClicked() {

  red = random(255);
  green = random(255);
  blue = random(255);
  background (green, blue, red);
  circley = mouseY;
  circlex = mouseX;
  xreversal();
  yreversal();
}

void draw() {

  StopSign();
  shoulditstop();
  stroke(0);
  fill(red, green, blue);
  ellipse(circlex, circley, 20, 20);
  ballspeed();
  if (circlex > width || circlex <= 0) {
    xreversal();
  }
  if (circley > height || circley <= 0) {
    yreversal();
  }
  i = i+1;
  if (i > 2500) {  
    background (blue, red, green);
    i = i - 2500;
  }
  if (circlex <= 0 || circlex >= width+1 || circley <= 0 || circley >= height+1) {
    red = random(255);
    green = random(255);
    blue = random(255);
  }
}

void xreversal() {
  xSpeed = xSpeed * -1;
}
void yreversal() {
  ySpeed = ySpeed * -1;
}

//stop toggle
// giving me problems, debug it!!!!!!!!
void shoulditstop() {
  if (dist(mouseX, mouseY, 680, 350) < 50) {
    speedstop();
  }
  else if (dist(mouseX,mouseY,680,350) >=50 && xSpeed == 0 && ySpeed == 0 ){

    xSpeed = xVelocity;
    ySpeed = yVelocity;
    ballspeed();
  }
}

//stops the ball
void speedstop() {
  xSpeed = xSpeed * 0;
  ySpeed = ySpeed * 0;
}

//Creates stop button
void StopSign() {
  noStroke();
  fill(0);
  ellipse(680, 350, 50, 50);
}

//starts ball again
void ballspeed(){
  circlex = circlex + xSpeed;
  circley = circley + ySpeed;
}

The problem is that to stop the ball xSpeed and ySpeed go to zero. I tried to work around that with the x and y Velocity variables but that didn’t work because they both are positive… So currently I’m lost. Also I think there may be more instances where I could have used functions but I wasn’t sure how to go about that.

Pacman Pt.2 – omnomnom

pacpt2 pacpt2-1

Got pacman to work, kind of – the dots have yet to disappear, although I have tried to use an if statement for it. The trails they’re leaving behind due to the stroke(255) was cool, so I left it there. Pacman trails!

I know that the code can be simplified further if I used for loops for the pellet locations.

Code below.

	Pacman pac1;
	Pacman pac2;
	Pellet pellet1;
	Pellet pellet2;
	Pellet pellet3;
	Pellet pellet4;
	Pellet pellet5;

	void setup() {
	  background(255);
	  stroke(255);

	  size(600, 400);
	  smooth();
	  noCursor();
	  pac1 = new Pacman(0, 50, 5);
	  pac2 = new Pacman(0, 100, 2);
	  pellet1 = new Pellet(color(100,0,400,34),400,50);
	  pellet2 = new Pellet(color(300,0,400,100),400,100);
	  pellet3 = new Pellet(color(100,0,400,34),400,150);
	  pellet4 = new Pellet(color(300,0,400,100),400,200);
	  pellet5 = new Pellet(color(100,0,400,34),400,250);
	}

	void draw() {
	  pac1.body();
	  pac2.body();
	  pac1.eat();
	  pac2.eat();

	  pellet1.place();
	  pellet2.place();
	  pellet3.place();
	  pellet4.place();
	  pellet5.place();

	 //line(400, 0, 400, height);
	}

	class Pellet {
	  color c;
	  float pelletX;
	  float pelletY; 

	  Pellet(color tempC, float tempxpos, float tempypos) {
	    c=tempC;
	    pelletX = tempxpos;
	    pelletY = tempypos;
	  }

	  void place() {
	    fill(c);
	    smooth();

	    //for (int i=0; i<10; i++){
	    ellipse(pelletX, pelletY+50, 15, 15);
	   // }

	 //Attempted to make the pellets disappear (turn white)
	 //   if (pacX == 400) {
	 //    c=0;
	 //   }
	  }
	}

	class Pacman {
	  float pacX;
	  float pacY;
	  float pacsize=20;
	  float xspeed;

	  Pacman(float temppacX, float temppacY, float tempxspeed) {
	    pacX = temppacX;
	    pacY = temppacY;
	    xspeed = tempxspeed;
	  }

	  void body() {
	    fill(250, 250, 40); //classic yellow color
	    arc(pacX, pacY, 50, 50, PI/4, 7*PI/4);
	  }

	  void eat() {
	    pacX= pacX + xspeed;
	    if (pacX > 600 || pacX < 0) {
	      xspeed = xspeed * -1.2;
	      pacY = pacY + 100;
	      // if (pacY > 500) {
	      //   xspeed = 0;
	    }
	  }
	}

 

Travolta Bounce

 

Screen Shot 2014-03-10 at 1.21.35 PM

I decided to keep pushing forward with the Travolta Bounce. I cleaned up the code and added a few things ( a cool background and also the ability to click the Travolta ball into place.) What i really wanted to get was a new ball with every click…so I’ll continue to work on that.

Here it is in action.

PImage travolta;
PImage travoltabackground;

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

void setup() {
  size(1100, 688);
  travolta = loadImage("travoltaball.png"); 
  travoltabackground =  loadImage("travoltabouncebackground.jpg");
}

void draw() {
  background(travoltabackground);   
  displaytravolta();
  moveball();
  checkedges();
}

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

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

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;
  }
}

 

 

$~make it rain~$

Rain r1;

int raindrops = 50;
int checkWeather;
int whichWeather;

Rain[] drops = new Rain[raindrops]; // Declare and create the array

void setup() {
  size(600, 600);
  background(255);
  smooth();
  noStroke();

  //Loop through array to create each object
  for (int i = 0; i < drops.length; i++) {
    drops[i] = new Rain(); // Create each object
    r1 = new Rain();
  }
}

void draw() {
  fill(255, 50);
  rect(0, 0, 600, 600);
  for (int i = 0; i < drops.length; i++) {
    drops[i].fall();
  }
  if (checkWeather == 1) {
    background(184, 232, 252);
    fill(255, 255, 0);
    noStroke();
    ellipse(500, 100, 100, 100);
  }
}

void keyPressed() {
  checkWeather = 1;
}

void keyReleased() {
  checkWeather = 0;
}

class Rain {
  float x = random(600);
  float y = random(-height);

  void fall() {
    y = y + 10;
    fill(176, 227, 255, 100);
    ellipse(x, y, 10, 10);

    if (y>height) {
      x = random(600);
      y = random(-200);
    }
  }
}

 

VIDEO

 

 

Trapped in the Ignition Remix

 

As you may remember from last week, I did the R Kelly bounce. For this version, I made the code for the edges more concise, separated my code into modular functions. Next I added in for loops, and R. Kelly is pretty much synonymous with Trapped in the Closet and peeing on people. Because I want to steer clear of animating the latter, I added in for loops of some of the key characters from the Big Man reveal scene, all chasing each-other at different speeds. All of this comes together to be a rather distracting background for my original rainbow ball bounce/speed change.

Trapped in the For Loop

Screen Shot 2014-03-10 at 3.45.30 AM

Also, I insulated my glue sniffing with push/pop matrices, like we did in class. I got some inspiration for how to do the rotation speeds from the star example in processing.

Yay code!

PImage photo;
PImage kellyhead;
PImage thePie;
PImage midget;
PImage bridget;
float circleX = 300;
float circleY = 300;
float xspeed = 2;
float yspeed = 2;
float diameter = 100;

void setup() {
  size (930, 700); //x,y
  photo = loadImage ("rkelly.jpeg");
  kellyhead = loadImage ("kellyHead.png");
  thePie = loadImage ("thepie.png");
  midget = loadImage ("midget.png");
  bridget = loadImage ("bridget.png");
  smooth ();
}

void draw() {
  image(photo, 0, 0);
  runPie();
  runMidget();
  runBridget();
  maskKelly();
  displayBall();
  moveBall();
  colorEdges();
}

void mousePressed () {
  xspeed = random (0, 20);
  yspeed = random (0, 20);
}

void displayBall () {
  noStroke ();
  ellipse (circleX, circleY, diameter, diameter);
}

void moveBall () {
  circleX = circleX + xspeed;
  circleY = circleY + yspeed;
}

void colorEdges () {
  if (circleX + diameter / 2 >= width || circleX <= diameter / 2) {
    xspeed = xspeed * -1;
    println("Runnin' her hands through my 'fro");
    fill(random (255), random (255), random (255));
  }

  if (circleY + diameter / 2 >= height || circleY <= diameter / 2) {
    yspeed = yspeed * -1;
    println("Bouncin' on 24's");
    fill(random (255), random (255), random (255));
  }
}

void runPie () {
  pushMatrix();
  translate (width/2, height/2);
  rotate(frameCount / 80.0);
  for (int g=0; g<5; g++) {
    image (thePie, 100 + g*70, 0, 100, 100);
  }
  popMatrix();
}

void runMidget () {
  pushMatrix();
  translate (width/2, height/2);
  rotate(frameCount / 100.0);
  for (int g=0; g<5; g++) {
    image (midget, 100 + g*70, 0, 150, 150);
  }
  popMatrix();
}

void runBridget () {
  pushMatrix();
  translate (width/2, height/2);
  rotate(frameCount / 120.0);
  for (int g=0; g<5; g++) {
    image (bridget, 100 + g*70, 0, 130, 130);
  }
  popMatrix();
}

void maskKelly() {
  pushMatrix();
  translate (width/2, height/2);
  rotate(frameCount / 150.0);
  for (int i=0; i<5; i++) {
    image (kellyhead, 100 + i*70, 0, 100, 120);
  }
  popMatrix();
}

 

 

Alright Alright Alright

This week I combined my drawing and animation projects.

Muffin + Bouncing Seizure Ball = Bouncing Seizure Muffin

Next steps:

1. Get rid of that stupid line created by the overlap of the two rectangles

2. Get the muffin to bounce when its edge hits a side, as opposed to the x1 & y1 coordinates

3. Give the muffin the eyes, eyebrows, and wrapper that it usually sports

muffin

float multiplier;
float rectHeight;
float rectLength;
float thirdIndent;
float bigDiameter;
float smallDiameter;
float firstTier;
float secondTier;
float thirdTier;
float secondIndent;
float x1 = 200;
float y1 = 200;
float xspeed=random(10);
float yspeed=random(10);

void setup() {
size(800,800);
background(0);
}

void draw (){
  drawMuffin();
  moveMuffin();
  edgeCheck();
}

void drawMuffin () {
 rectHeight = multiplier*12;
 rectLength = multiplier*4;
 thirdIndent = rectLength*1.5;
 bigDiameter = multiplier*6.5;
 smallDiameter = multiplier*6;
 firstTier = rectHeight/5;
 secondTier = rectHeight/2;
 thirdTier = rectHeight/1.5;
 secondIndent = rectLength/2.25;
  background(0);
  fill(random (255),random (255),random (255),255);
  noStroke();
  //components of muffin, relatively defined
  rect(x1,y1,rectHeight,rectLength);
  ellipse(x1,y1-firstTier,bigDiameter,bigDiameter);
  ellipse(x1+rectHeight,y1-firstTier,bigDiameter,bigDiameter);
  ellipse(x1+secondIndent,y1-secondTier,smallDiameter,smallDiameter);
  ellipse(x1+rectHeight-secondIndent,y1-secondTier,smallDiameter,smallDiameter);
  ellipse(x1+thirdIndent,y1-thirdTier,smallDiameter,smallDiameter);
  rect(x1+secondIndent,y1-secondTier,thirdTier,secondTier);
}

void moveMuffin () {
  x1=x1+xspeed;
  y1=y1+yspeed;
}

void edgeCheck () {
  if(x1>=width||x1<=0){
    xspeed=xspeed*-1;
    multiplier = random(1,25); 
   };
  if (y1>=height||y1<=0){
    yspeed=yspeed*-1;
    multiplier = random(1,25);
   };
}

 

 

 

 

Party in the sky

I organized my last code into three main functions — consumingClouds, confettiTrail, and shootingStar — and added the bouncing ball effect and borrowed Shiffman’s code for a star shape. Can I add some ’80s disco music later on?

//What's happening conceptually?
//void draw(){
//consumingClouds();
//twinklingStars();
//shootingStar();
//}

//DECLARING VARIABLE
float cloudX;
float cloudY;
int x = 0;
int y = 0;
int xspeed = 30;
int yspeed = 10;

//INITIALIZE VARIABLE
void setup(){
size(800,800);
background(255);
}

//USE VARIABLE
void draw(){
consumingClouds();
confettiTrail();
shootingStar();
}

void consumingClouds(){
cloudX = random(width);
cloudY = random(height);
stroke(135,206,235,20);
fill(135,206,235,70);
ellipse(cloudX,cloudY,200,100);
}

void confettiTrail(){
if (mousePressed) {
float r = random(0,255);
float g = random(0,255);
float b = random(0,255);
float a = random(0,255);
fill(r,g,b,a); //fill(random(255),random(255),random(255),random(255));
ellipse(mouseX,mouseY,30,30);
}
}

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);
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);
}
}

Multiply the Rainbow

I tried organizing my code into methods (as best I could) and clean up  what was in the the void draw().

It’s still a pretty intimidating chunk of code, since a lot of my variables are declared globally, and not everything was passed by value in those methods since I kept bugging my program when I tried to make some variables local. 

int circleX;
int circleY;
int velocityX;
int velocityY;
int bubblecount;
int bubblecount2;
boolean bubbleadd;

//MousePressed/keyPressed
boolean disco;

//Use arrays to store color values:
int[] red = {
  255, 255, 255, 0, 0, 75, 143
};

int[] green = {
  0, 127, 255, 255, 0, 0, 0
};
int[] blue = {
  0, 0, 0, 0, 255, 130, 255
};
int cycle_color;
int cycle_color2;

//Use arrays to store coordinates of new bubbles
int[] bubbleX = new int[1000];
int[] bubbleY = new int[1000];

//Use arrays to store velocities of new bubbles
int[] bubblevelocityX = new int [1000];
int[] bubblevelocityY = new int [1000];
void setup() {
  strokeWeight(0);
  stroke(100, 0, 150);
  size(800, 600);
  circleX = mouseX;
  circleY = mouseY;
  velocityX = 7;
  velocityY = 7;
  bubblecount = 0;
  bubblecount2 = 0;
  bubbleX[0]=circleX;
  bubbleY[0]=circleY;
  bubblevelocityX[0]=velocityX;
  bubblevelocityY[0]=velocityY;
  //colors of background/bubbles(2)
  cycle_color = 0;
  cycle_color2 = 1;

  //cool effect
  disco = true;
}

void draw() {
  background(red[cycle_color], green[cycle_color], blue[cycle_color]);

  bubbleadd = true;
  bubblecount2 = bubblecount;

  for (int i = 0; i <= bubblecount2; i++) {
    if (disco) {
      fill(red[cycle_color2], green[cycle_color2], blue[cycle_color2]);
    }
    else {
      fill(random(255), random(255), random(255));
    }

    bubble_speed(i);
    check_sides(i);
    check_top_and_bottom(i);
    draw_bubble(i);
    change_color();
  }
}

void check_sides(int index) {
  if (bubbleX[index] >= width || bubbleX[index] <= 0) {
    bubblevelocityX[index] *= -1;

    if (bubbleadd) {
      bubblecount += 1;
      bubbleX[bubblecount] = bubbleX[index];
      bubbleY[bubblecount] = bubbleY[index];
      bubblevelocityX[bubblecount] = bubblevelocityX[index];
      bubblevelocityY[bubblecount] = -bubblevelocityY[index]+(int)random(5);
      bubbleadd = false;
    }
  }
}

void check_top_and_bottom (int index) {
  if (bubbleY[index] >= (height) || bubbleY[index] <= 0) {
    bubblevelocityY[index] *= -1;
    if (bubbleadd) {
      bubblecount += 1;
      bubbleX[bubblecount] = bubbleX[index];
      bubbleY[bubblecount] = bubbleY[index];
      bubblevelocityX[bubblecount] =-bubblevelocityX[index]+(int)random(5);
      bubblevelocityY[bubblecount] = bubblevelocityY[index];
      bubbleadd = false;
    }
  }
}

void draw_bubble(int i) {
  strokeWeight(0);
  stroke(red[cycle_color2], green[cycle_color2], blue[cycle_color2]);
  ellipse(bubbleX[i], bubbleY[i], 120, 120);
}

void bubble_speed (int index) {
  bubbleX[index]+=   bubblevelocityX[index];
  bubbleY[index]+= bubblevelocityY[index];
}

void change_color () {
  if (bubblecount2 > 500) {
    bubblecount2=0;
    bubblecount=0;
    cycle_color += 1;
    cycle_color2 += 1;
    if (cycle_color >= 7){
      cycle_color=0;
      cycle_color2 += 1;

  }
    if (cycle_color2 >= 7){
      cycle_color2=0;
    }
  }
}

  //Cool effect (on)
  void mousePressed() {
    disco=false;
  }

  //Cool effect (off)
  void keyPressed() {
    disco=true;
  }