Time to make objects!!
We need to understand the difference between data and functions. First lets look at a car:
Data might include:
Color
Make
Model
Functions:
Stop
Start
Turn
We can actually create a variable for car that hold all this information!!!
How it works now instead of making a variable car, we make a class called car.
Car myCar;
void setup(){
myCar= new Car();
}
void draw(){
background(0);
myCar.move();
myCar.display();
}
Now this might be very confusing, and so where is a comparison of two codes of an ellipse moving;
We need to understand the difference between data and functions. First lets look at a car:
Data might include:
Color
Make
Model
Functions:
Stop
Start
Turn
We can actually create a variable for car that hold all this information!!!
How it works now instead of making a variable car, we make a class called car.
Car myCar;
void setup(){
myCar= new Car();
}
void draw(){
background(0);
myCar.move();
myCar.display();
}
Now this might be very confusing, and so where is a comparison of two codes of an ellipse moving;
int c;
int xPos; int yPos; int xSpeed; void setup(){ size(400,400); c=color(0); yPos=30; xPos=0; xSpeed=4; } void draw(){ background(255); display(); move(); } void display(){ fill(c); ellipse(xPos,yPos,10,10); } void move(){ xPos=xPos+xSpeed; if(xPos>width){ xSpeed=xSpeed*-1; } |