Open chasestarr opened 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;
}
}
We're only supposed to do three, correct?
@Brandonsugar Only needed to do one, but doing more is good practice! :+1:
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;
}
}
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(); }
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; } } }
Vector Ball
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();
}
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;
}
}
}
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.