/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://accdf12.sketchpad.cc/sp/pad/view/ro.Qq5r-OUS1W9/rev.15
*
* authors:
* Eugeni Lee
* Michael Kontopoulos
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
//Creating a class and using it in setup/draw. The BASICS.
//Declare a Smiley object
Smiley guy;
void setup(){
size(300,300);
smooth();
//Initialize Smiley Object (by calling the constructor)
guy = new Smiley();
}
void draw(){
background(0);
//Call methods on the object.
guy.display();
println(guy.xpos + ", " + guy.ypos); //Cool! You can access class fields with the "dot operator"
}
class Smiley{
//Class "Fields" (variables)
float xpos, ypos;
//Constructor
Smiley(){
xpos = width/2;
ypos = height/2;
}
//Class "Methods" (functions)
void display(){
pushMatrix();
translate(xpos, ypos);
ellipse(0,0, 100,100);
ellipse(-10,-10, 5,5);
ellipse(10, -10, 5,5);
arc(0,0, 75,75, radians(15), radians(165));
popMatrix();
}
}