class Alien { int LeftLegX; int LeftLegY; int RightLegX; int RightLegY; int LeftLegXVel; int LeftLegYVel; int RightLegXVel; int RightLegYVel; int LeftArmX; int LeftArmY; int RightArmX; int RightArmY; int LeftArmXVel; int LeftArmYVel; int RightArmXVel; int RightArmYVel; int eye1X; int eye1Y; int eye2X; int eye2Y; int eye3X; int eye3Y; int eye4X; int eye4Y; int eye5X; int eye5Y; int r; // alien color values int g; int b; int aX; // alien position values int aY; float Ascale; Alien(int _x, int _y, int _r, int _g, int _b, float _scale) // receive user-defined color values { r = _r; g = _g; b = _b; aX = _x; // original 500 aY = _y; // original 480 - shoulder height Ascale = _scale; // initial values eye1X = aX - 170; // 330; eye1Y = aY - 200; // 280; eye2X = aX - 85; // 415; eye2Y = aY - 220; // 260; eye3X = aX + 20; // 520; eye3Y = aY - 240; // 240; eye4X = aX + 115; // 615; eye4Y = aY - 220; // 260; eye5X = aX + 190; // 690; eye5Y = aY - 220; // 280; LeftArmX = aX - 120; // 380; // arm values LeftArmY = aY; // 480; RightArmX = aX + 100; // 600; RightArmY = aY + 70; // 550; LeftArmXVel = -2; LeftArmYVel = -7; RightArmXVel = -2; RightArmYVel = 7; LeftLegX = aX - 60; // 440; // leg values LeftLegY = aY + 180; // 660; LeftLegXVel = -1; LeftLegYVel = 6; RightLegX = aX + 55; // 555; RightLegY = aY + 150; // 630; RightLegXVel = -1; RightLegYVel = -6; } void moveAlien() { // animate legs if (LeftLegX <= (aX-60) || LeftLegX >= (aX-55)) // 440 --> 445 { LeftLegXVel = -LeftLegXVel; } if (LeftLegY <= (aY+150) || LeftLegY >= (aY+180)) // 630 --> 660 { LeftLegYVel = -LeftLegYVel; } if (RightLegX <= (aX+55) || RightLegX >= (aX+60)) // 555 --> 560 { RightLegXVel = -RightLegXVel; } if (RightLegY <= (aY+150) || RightLegY >= (aY+180)) // 630 --> 660 { RightLegYVel = -RightLegYVel; } LeftLegX = LeftLegX + LeftLegXVel; LeftLegY = LeftLegY + LeftLegYVel; RightLegX = RightLegX + RightLegXVel; RightLegY = RightLegY + RightLegYVel; /* animLimb(LeftLegX, LeftLegY, LeftLegXVel, LeftLegYVel, 450, 600, 440, 445, 630, 660); animLimb(RightLegX, RightLegY, RightLegXVel, RightLegYVel, 550, 600, 555, 560, 630, 660); */ // animate arms if (LeftArmX <= (aX-120) || LeftArmX >= (aX-100)) // 380 --> 400 { LeftArmXVel = -LeftArmXVel; } if (LeftArmY <= aY || LeftArmY >= (aY+70)) // 480 --> 550 { LeftArmYVel = -LeftArmYVel; } if (RightArmX <= (aX+100) || RightArmX >= (aX+120)) // 600, 620 { RightArmXVel = -RightArmXVel; } if (RightArmY <= aY || RightArmY >= (aY+70)) // 480, 550 { RightArmYVel = -RightArmYVel; } LeftArmX = LeftArmX + LeftArmXVel; LeftArmY = LeftArmY + LeftArmYVel; RightArmX = RightArmX + RightArmXVel; RightArmY = RightArmY + RightArmYVel; } // make eyes follow cursor void eyeFollow (int eyeX, int eyeY, int eyeCX, int eyeCY, int eyeXrange, int eyeYrange, int eyeW, int eyeH) { if (mouseX <= (Ascale*(eyeCX-eyeXrange))) // but make sure they don't fall out! { eyeX = int(Ascale*(eyeCX-eyeXrange)); } else if (mouseX >= (Ascale*(eyeCX+eyeXrange))) { eyeX = int(Ascale*(eyeCX+eyeXrange)); } else { eyeX = mouseX; } if (mouseY <= (Ascale*(eyeCY-eyeYrange))) { eyeY = int(Ascale*(eyeCY-eyeYrange)); } else if (mouseY >= (Ascale*(eyeCY+eyeYrange))) { eyeY = int(Ascale*(eyeCY+eyeYrange)); } else { eyeY = mouseY; } ellipse(eyeX, eyeY, Ascale*eyeW, Ascale*eyeH); } // modularize limb movement /* void animLimb(int limbX, int limbY, int limbXVel, int limbYVel, int bodyX, int bodyY, int limbXMin, int limbXMax, int limbYMin, int limbYMax) { if (limbX <= limbXMin || limbX >= limbXMax) { limbXVel = -limbXVel; } if (limbY <= limbYMin || limbY >= limbYMax) { limbYVel = -limbYVel; } limbX = limbX + limbXVel; limbY = limbY + limbYVel; stroke(r,g,b); strokeWeight(36); strokeJoin(ROUND); strokeCap(ROUND); line (bodyX, bodyY, limbX, limbY); } */ void drawAlien() { noStroke(); scale(Ascale); // head fill(r,g,b); ellipse(aX, (aY-210), 560, 380); // (500, 270, 560, 380); // eyes fill(100); ellipse(aX, (aY-280), 100, 200); // (500, 200, 100, 200); // center eye // left side ellipse((aX-100), (aY-255), 80, 160); // (400, 225, 80, 160); // medium left ellipse((aX-180), (aY-230), 60, 120); // (320, 250, 60, 120); // small left // mirror on right side ellipse((aX+100), (aY-255), 80, 160); // (600, 225, 80, 160); // medium right ellipse((aX+180), (aY-230), 60, 120); // (680, 250, 60, 120); // small right // mouth fill(100); ellipse(aX, (aY-100), 400, 80); // (500, 380, 400, 80); // teeth fill(r,g,b); triangle((aX-160),(aY-140),(aX-140),(aY-140),(aX-145),(aY-100)); // (340, 340, 360, 340, 355, 380); // top left fang triangle((aX+160),(aY-140),(aX+140),(aY-140),(aX+145),(aY-100)); // (660, 340, 640, 340, 645, 380); // top right fang triangle((aX-60),(aY-50),(aX-45),(aY-50),(aX-55),(aY-85)); // (440, 430, 455, 430, 445, 395); // lower left fang triangle((aX+60),(aY-50),(aX+45),(aY-50),(aX+55),(aY-85)); // (560, 430, 545, 430, 555, 395); // lower right fang // antennae triangle((aX-280),(aY-210),(aX-260),(aY-210),(aX-290),(aY-300)); // (220, 270, 240, 270, 210, 180); // left ear triangle((aX+280),(aY-210),(aX+260),(aY-210),(aX+290),(aY-300)); // (780, 270, 760, 270, 790, 180); // right ear triangle(aX,(aY-450),(aX-6),(aY-400),(aX+6),(aY-400)); // (500, 30, 494, 80, 506, 80); // central horn // body stroke(r,g,b); strokeWeight(36); strokeJoin(ROUND); strokeCap(ROUND); beginShape(); // torso vertex((aX-50),aY); // (450, 480); vertex((aX+50),aY); // (550, 480); vertex((aX+50),(aY+120)); // (550, 600); vertex((aX-50),(aY+120)); // (450, 600); vertex((aX-50),aY); endShape(); // arms line((aX-50), aY, LeftArmX, LeftArmY); // left arm line((aX+50), aY, RightArmX, RightArmY); // right arm // legs /* animLimb(LeftLegX, LeftLegY, LeftLegXVel, LeftLegYVel, 450, 600, 440, 445, 630, 660); animLimb(RightLegX, RightLegY, RightLegXVel, RightLegYVel, 550, 600, 555, 560, 630, 660); */ // legs line((aX-50), (aY+120), LeftLegX, LeftLegY); // left leg line((aX+50), (aY+120), RightLegX, RightLegY); // right leg /* original line(450, 600, LeftLegX, LeftLegY); // left leg line(550, 600, RightLegX, RightLegY); // right leg */ // tail strokeWeight(10); line((aX-50),(aY+120),(aX-150),(aY+120)); // (450, 600, 350, 600); line((aX-150),(aY+120),(aX-150),(aY+20)); // (350, 600, 350, 500); strokeCap(SQUARE); line((aX-150),(aY+20),(aX-200),(aY+70)); // (350, 500, 300, 550); noStroke(); triangle((aX-205),(aY+75),(aX-205),(aY+45),(aX-198),(aY+70)); // (295, 555, 295, 525, 302, 550); // tail end triangle((aX-205),(aY+75),(aX-175),(aY+75),(aX-198),(aY+68)); // (295, 555, 325, 555, 302, 548); moveAlien(); fill(r,g,b); scale(1/Ascale); // pupils eyeFollow(eye3X, eye3Y, aX, (aY-280), 20, 40, 30, 90); // center pupil eyeFollow(eye2X, eye2Y, (aX-100), (aY-255), 15, 35, 20, 60); eyeFollow(eye1X, eye1Y, (aX-180), (aY-230), 10, 30, 15, 45); eyeFollow(eye4X, eye4Y, (aX+100), (aY-255), 15, 35, 20, 60); eyeFollow(eye5X, eye5Y, (aX+180), (aY-230), 10, 30, 15, 45); } }