moving into object oriented programming
in
Programming Questions
•
2 years ago
Hi,
I am a beginner at Processing so forgive me if my question is stupid/simple.
This is Roger following the mouse:
- void setup() {
- size (400, 400);
- }
- void draw() {
- background (255);
- ellipseMode(CENTER);
- noStroke();
- fill(156, 109, 203);
- //main body
- ellipse(mouseX, mouseY, 180, 180);
- //ears
- ellipse(mouseX-20, mouseY-90, 40, 120);
- ellipse(mouseX+20, mouseY-90, 40, 120);
- //eyes
- fill(0, 0, 0);
- ellipse(mouseX-15, mouseY-30, 30, 30);
- ellipse(mouseX+15, mouseY-30, 30, 30);
- fill(255, 255, 255);
- ellipse(mouseX-7, mouseY-24, 10, 10);
- ellipse(mouseX+7, mouseY-24, 10, 10);
- //lips
- smooth();
- strokeWeight(10);
- stroke(255);
- line(mouseX-40, mouseY+20, mouseX+40, mouseY+20);
- }
- Roger roger;
- void setup() {
- size (500, 500);
- background(255);
- roger = new Roger(200, 180, 180, 180);
- }
- void draw() {
- roger.display();
- roger.rabbitFollowsMouse();
- }
- class Roger {
- float a;
- float b;
- float c;
- float d;
- Roger (float a, float b, float c, float d) {
- a = a;
- b = b;
- c = c;
- d = d;
- }
- void display() {
- noStroke();
- fill(156, 109, 203);
- //main body
- ellipse(a, b, c, d);
- //ears
- ellipse(a-20, b-90, c-140, d-60);
- ellipse(a+20, b-90, c-140, d-60);
- //eyes
- fill(0);
- ellipse(a-15, b-30, c-150, d-150);
- ellipse(a+15, b-30, c-150, d-150);
- fill(255);
- ellipse(a-7, b-27, c-170, d-170);
- ellipse(a+7, b-27, c-170, d-170);
- //lips
- smooth();
- strokeWeight(10);
- stroke(255);
- line(a-40, b+20, c+60, d+20);
- }
- void rabbitFollowsMouse() {
- a = mouseX;
- b = mouseY;
- //main body
- ellipse(mouseX, mouseY, c, d);
- //ears
- ellipse(mouseX-20, mouseY-90, c-140, d-60);
- ellipse(mouseX+20, mouseY-90, c-140, d-60);
- //eyes
- ellipse(mouseX-15, mouseY-30, c-150, d-150);
- ellipse(mouseX+15, mouseY-30, c-150, d-150);
- ellipse(mouseX-7, mouseY-24, c-170, d-170);
- ellipse(mouseX+7, mouseY-24, c-170, d-170);
- //lips
- line (mouseX-40, mouseY+20, c+60, d+20);
- }
- }
Thanks is advance!
2bad
1