Open chasestarr opened 8 years ago
@mositech/cs2015
Hi everyone, How is the homework coming along? Post any questions you have here. Other people may have the same ones. :exclamation:
First Tab
Ball theBall;
void setup(){
size(1000,1000);
theBall = new Ball();
}
void draw(){
background(150);
theBall.sideMove();
theBall.verticalMove();
theBall.bounce();
theBall.display();
theBall.gravity();
}
class Ball{
color c;
float xPos;
float yPos;
float gravity;
float xSpeed;
float ySpeed;
Ball(){
c=color(0);
xPos=width/2;
yPos=height/2;
ySpeed=5;
xSpeed=2.5;
gravity=0.98;
}
void display(){
stroke(0);
fill(c);
ellipse(xPos,yPos,70,70);
}
void gravity(){
ySpeed=ySpeed+gravity;
if(yPos>=967){
ySpeed=ySpeed*-0.85;
}
}
void sideMove(){
xPos=xPos+xSpeed;
}
void verticalMove(){
yPos=yPos+ySpeed;
}
void bounce(){
if(xPos>=967){
xSpeed=xSpeed*-0.7;
}
if(xPos<=42){
xSpeed=xSpeed*-0.75;
}
}
}
first tab
Ball myBall;
void setup() {
size(1000, 1000);
myBall = new Ball();
}
void draw() {
background(200);
myBall.sideMove();
myBall.verticalMove();
myBall.bounce();
myBall.display();
myBall.gravity();
}
second tab
class Ball {
color b;
float xPos;
float yPos;
float gravity;
float xSpeed;
float ySpeed;
Ball() {
b=color(0);
xPos=width/2;
yPos=height/2;
xSpeed=3;
ySpeed=4.5;
gravity=0.98;
}
void display() {
stroke(0);
fill(b);
ellipse(xPos, yPos, 70, 70);
}
void gravity() {
ySpeed=ySpeed+gravity;
if (yPos>=950) {
ySpeed=ySpeed-0.85;
}
}
void sideMove() {
xPos=xPos+xSpeed;
}
void verticalMove() {
yPos=yPos+ySpeed;
}
void bounce() {
if (xPos>950) {
xSpeed=xSpeed-0.7;
}
if (xPos<=50) {
xSpeed=xSpeed*-0.75;
}
}
}
First Tab
greenBall myGreenBall;
void setup(){
size(900,1100);
myGreenBall=new greenBall();
}
void draw(){
background(16,166,144);
myGreenBall.display();
myGreenBall.gravity();
myGreenBall.bounceBall();
}
Second Tab
class greenBall{
color g;
float xBall;
float yBall;
float speed;
float gravity;
greenBall(){
g=color(192,248,98);
xBall=450;
yBall=79;
speed=0;
gravity=0.98;
}
void display(){
fill(g);
ellipse(xBall,yBall,150,150);
}
void gravity(){
yBall=yBall+speed;
speed=speed+gravity;
}
void bounceBall(){
if(yBall>1025){
speed=speed*-0.9;
}
}
}
Tab No.1
aBall myBall;
void setup(){
size(550,500);
myBall = new aBall();
}
void draw(){
background(0);
myBall.display();
myBall.gravity();
myBall.bounce();
}
Tab No.2
class aBall{
color c;
float xpos;
float ypos;
float xspeed;
float gravity;
float speed;
aBall(){
c= color (255,201,245);
xpos = 250;
ypos = 1;
xspeed = 0;
speed = 5;
gravity = 0.98;
}
void display(){
fill(c);
ellipse(xpos,ypos,50,50);
}
void gravity(){
ypos = ypos + xspeed;
xspeed = xspeed + gravity;
}
void bounce(){
if(ypos >= 500){
xspeed = xspeed*-0.7;
}
}
}
Oops the code was improved last night.
Ball madBall;
void setup(){
size(800,800);
madBall =new Ball();
}
void draw(){
background(255);
madBall.move(5);
madBall.display();
madBall.gravity();
madBall.bounce();
madBall.yMove();
}
class Ball{
color c;
float ellipseX;
float ellipseY;
float speed;
float gravity;
float speed2;
Ball(){
c=color(0);
ellipseX=width/2;
ellipseY=height/2;
speed=5;
gravity=0.2;
speed2=5;
}
void display(){
stroke(255);
fill(c);
ellipse(ellipseX,ellipseY,50,50);
}
void move(float gravity){
ellipseX = ellipseX+speed2;
}
void yMove(){
ellipseY=ellipseY+speed;
}
void gravity(){
speed=speed+gravity;
if(ellipseY>=775){
speed=speed*-0.85;
}
}
void bounce(){
if (ellipseX>=775){
speed2=speed2*-0.75;
}
if (ellipseX<=25){
speed2=speed2*-0.75;
}
}
}
In this homework we will practice how to organize our code using object oriented programming. Look back on your homework from week06 for help.
Look at the example from class this week for to base your homework on.
Please paste your code as a comment on this post