mositech / CS2015

All course materials for MOSI Home School Computer Science will be stored here
2 stars 1 forks source link

HW #13 #31

Open chasestarr opened 8 years ago

chasestarr commented 8 years ago

In this homework we will practice reformatting old homework projects to use vectors.

Post a link to a Github repository or paste your code below.

Jeswing commented 8 years ago
PVector position= new PVector(400,400);
PVector velocity= new PVector(1,3.3);
void setup (){
  size(800,800);
  background(0);
}

void draw (){

  position.x= position.x + velocity.x;
  position.y= position.y + velocity.y;
rect(position.x,position.y,50,50);
if((position.x > width) || (position.x < 0)){
  velocity.x = velocity.x *-1;
}
  if((position.y > height) || (position.y < 0)){
    velocity.y = velocity.y *-1;
  }
  }
Brandonsugar commented 8 years ago

https://github.com/Brandonsugar/Downloaded-Homework-Brandon/blob/master/WK_14_HW_adjustedFromWeek5_PT_1/WK_14_HW_adjustedFromWeek5_PT_1.pde

Brandonsugar commented 8 years ago

https://github.com/Brandonsugar/Repository-1/blob/master/Expanding_sphere_Modified_WK_14_HW/Expanding_sphere_Modified_WK_14_HW.pde

Brandonsugar commented 8 years ago

https://github.com/Brandonsugar/Repository-1/blob/master/Color_Changing_rects_warmup_HW_WK14/Color_Changing_rects_warmup_HW_WK14.pde

Brandonsugar commented 8 years ago

We're only supposed to do three, correct?

chasestarr commented 8 years ago

@Brandonsugar Only needed to do one, but doing more is good practice! :+1:

Pummelweed commented 8 years ago
PVector position = new PVector(0,500);
PVector positionII = new PVector(500,0);
PVector velocity = new PVector(1,3.3);

void setup(){
  size(1000,1000);
}
void draw(){
  background(234);
  noStroke();
  fill(243,151,203);
  ellipse(position.x,position.y,100,100);

  position.add(velocity);

  if(position.x>1000){
    velocity.x = velocity.x*-2;
  }
    if(position.x<0){
    velocity.x = velocity.x*-1;
  }

  ellipse(position.x,position.y,100,100);
  position.add(velocity);
  if(position.y>1000){
    velocity.y = velocity.y*-1;
  }
    if(position.y<0){
    velocity.y = velocity.y*-1;
  }
}
The-Space-Core commented 8 years ago

Ball madBall;

void setup(){ size(800,800); madBall =new Ball(); }

void draw(){ background(255); madBall.move(100); madBall.display(); madBall.gravity(); madBall.bounce(); madBall.yMove(); }

The-Space-Core commented 8 years ago

class Ball{ color c; float size; float gravity; PVector position= new PVector(width/2,height/2); PVector velocity= new PVector(5,5);

Ball(){ c=color(0);

gravity=1;

}

void display(){ stroke(255); fill(c); ellipse(position.x,position.y,50,50); } void move(float gravity){ position.x = position.x+velocity.x; } void yMove(){ position.y=position.y+velocity.y; } void gravity(){ velocity.y=velocity.y+gravity; if(position.y>=775){ velocity.y=velocity.y-0.85; } } void bounce(){ if (position.x>=775){ velocity.x=velocity.x-0.75; } if (position.x<=25){ velocity.x=velocity.x*-0.75; } } }

The-Space-Core commented 8 years ago

Vector Ball

GoHawks12 commented 8 years ago

Tab one


Ball myBall;

void setup() {
  size(1000, 1000);
  myBall = new Ball();
}

void draw() {
  background(200);
  myBall.sideMove();
  myBall.verticalMove();
  myBall.bounce();
  myBall.display();
  myBall.gravity();
}
GoHawks12 commented 8 years ago

Tab two

class Ball {
color b;
PVector position = new PVector(width/2, height/2);
PVector velocity = new PVector(3, 4.5);
float gravity;
  Ball() {
    fill(b);
  gravity=0.98;
  }

  void display() {
    stroke(0);
    fill(b);
    ellipse(position.x, position.y, 70, 70);
  }

  void gravity() {
    velocity.y = velocity.y + gravity;
    if (position.y>=950) {
      velocity.y = velocity.y - 0.85;
    }
  }

  void sideMove() {
    position.x = position.x + velocity.x;
  }

  void verticalMove() {
    position.y = position.y + velocity.y;
  }

  void bounce() {
    if (position.x > 950) {
      velocity.x = velocity.x - 0.7;
    }

    if (position.x <=50) {
      velocity.x = velocity.x * -0.75;
    }
  }
}