Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person {
- color head, body, eyes;
- float xpos, xpos1, xpos2, xpos3, xpos4,xpos5,xpos6;
- float ypos, ypos3, ypos4,ypos5, increaseWidth;
- float xspeed, reverseXspeed, flag;
- int pos;
- Person() {
- body = color(190, 114, 60);
- head = color(222, 171, 127);
- eyes = color(0);
- xpos = width/2;
- ypos = height/2;
- xpos1 = 81;
- xpos2 = 119;
- xpos3 = 90;
- ypos3 = 50;
- xpos4 = 110;
- ypos4 = 150;
- xspeed = 1;
- reverseXspeed = 1;
- xpos5= 94;
- ypos5 = 152;
- xpos6 = 106;
- }
- void move()
- {
- //head and body
- if(xpos == width) flag = 1;
- else if (xpos == 0) flag = 0;
- if(flag == 1)
- xpos = xpos - xspeed;
- else if(flag == 0)
- xpos = xpos + xspeed;
- //left eye
- xpos1 = xpos1 + xspeed;
- if (xpos1 > width+increaseWidth) {
- xpos1 = -20;
- }
- //right eye
- xpos2 = xpos2 + xspeed;
- if (xpos2 > width+increaseWidth) {
- xpos2 = -20;
- }
- //left arm
- xpos3 = xpos3 + xspeed;
- if (xpos3 > width+increaseWidth) {
- xpos3 = -20;
- }
- ypos3 = ypos3 + xspeed;
- if (ypos3 > width-50) {
- ypos3 = 50;
- }
- //right arm
- xpos4 = xpos4 + xspeed;
- if (xpos4 > width+increaseWidth) {
- xpos4 = -20;
- }
- xpos5 = xpos5 +xspeed;
- if(xpos5 > width+increaseWidth){
- xpos5 = -20;
- }
- xpos6 = xpos6 +xspeed;
- if(xpos6 > width+increaseWidth){
- xpos6 = -20;
- }
- }
- void display() {
- rectMode(CENTER);
- ellipseMode(CENTER);
- stroke(0);
- fill(body);
- rect(xpos, ypos, 20, 100);
- drawHead(xpos, 70, 60, 60);
- // drawEyes(xpos1, 70, 16, 32);
- // drawEyes(xpos2, 70, 16, 32);
- // drawArms(xpos3, 100, xpos3-25, ypos3);
- // drawArms(xpos4, 100, xpos4+25, ypos3);
- // drawLegs(xpos5,150,xpos5,182);
- // drawLegs(xpos6,150, xpos6, 182);
- }
- void drawLegs(float xpos, float ypos, float legWidth, float legHeight){
- stroke(0);
- strokeCap(ROUND);
- line(xpos, ypos, legWidth, legHeight);
- }
- void drawHead(float xpos, float ypos, float headWidth, float headHeight) {
- stroke(102);
- smooth();
- fill(222, 171, 127);
- ellipse(xpos, ypos, headWidth, headHeight);
- }
- void drawEyes(float xpos, float ypos, float eyesWidth, float eyesHeight) {
- fill(0);
- ellipse(xpos, ypos, eyesWidth, eyesHeight);
- }
- void drawArms(float xpos, float ypos, float armsWidth, float armsHeight) {
- stroke(0);
- strokeCap(ROUND);
- line(xpos, ypos, armsWidth, armsHeight);
- }
- }
- Person myPerson;
- void setup() {
- size(200, 200);
- myPerson = new Person();
- }
- void draw() {
- background(255);
- myPerson.move();
- myPerson.display();
- text( "x: " + mouseX + " y: " + mouseY, mouseX, mouseY );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement