Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. class Person {
  2. color head, body, eyes;
  3. float xpos, xpos1, xpos2, xpos3, xpos4,xpos5,xpos6;
  4. float ypos, ypos3, ypos4,ypos5, increaseWidth;
  5. float xspeed, reverseXspeed, flag;
  6. int pos;
  7.  
  8. Person() {
  9. body = color(190, 114, 60);
  10. head = color(222, 171, 127);
  11. eyes = color(0);
  12.  
  13. xpos = width/2;
  14. ypos = height/2;
  15. xpos1 = 81;
  16. xpos2 = 119;
  17. xpos3 = 90;
  18. ypos3 = 50;
  19. xpos4 = 110;
  20. ypos4 = 150;
  21. xspeed = 1;
  22. reverseXspeed = 1;
  23. xpos5= 94;
  24. ypos5 = 152;
  25. xpos6 = 106;
  26. }
  27.  
  28. void move()
  29. {
  30. //head and body
  31. if(xpos == width) flag = 1;
  32. else if (xpos == 0) flag = 0;
  33.  
  34. if(flag == 1)
  35. xpos = xpos - xspeed;
  36.  
  37. else if(flag == 0)
  38. xpos = xpos + xspeed;
  39.  
  40.  
  41.  
  42. //left eye
  43. xpos1 = xpos1 + xspeed;
  44. if (xpos1 > width+increaseWidth) {
  45. xpos1 = -20;
  46. }
  47.  
  48. //right eye
  49. xpos2 = xpos2 + xspeed;
  50. if (xpos2 > width+increaseWidth) {
  51. xpos2 = -20;
  52. }
  53.  
  54. //left arm
  55. xpos3 = xpos3 + xspeed;
  56. if (xpos3 > width+increaseWidth) {
  57. xpos3 = -20;
  58. }
  59.  
  60. ypos3 = ypos3 + xspeed;
  61. if (ypos3 > width-50) {
  62. ypos3 = 50;
  63. }
  64. //right arm
  65. xpos4 = xpos4 + xspeed;
  66. if (xpos4 > width+increaseWidth) {
  67. xpos4 = -20;
  68. }
  69.  
  70. xpos5 = xpos5 +xspeed;
  71. if(xpos5 > width+increaseWidth){
  72. xpos5 = -20;
  73. }
  74. xpos6 = xpos6 +xspeed;
  75. if(xpos6 > width+increaseWidth){
  76. xpos6 = -20;
  77. }
  78.  
  79.  
  80. }
  81.  
  82. void display() {
  83. rectMode(CENTER);
  84. ellipseMode(CENTER);
  85.  
  86. stroke(0);
  87. fill(body);
  88. rect(xpos, ypos, 20, 100);
  89.  
  90. drawHead(xpos, 70, 60, 60);
  91. // drawEyes(xpos1, 70, 16, 32);
  92. // drawEyes(xpos2, 70, 16, 32);
  93. // drawArms(xpos3, 100, xpos3-25, ypos3);
  94. // drawArms(xpos4, 100, xpos4+25, ypos3);
  95. // drawLegs(xpos5,150,xpos5,182);
  96. // drawLegs(xpos6,150, xpos6, 182);
  97. }
  98.  
  99. void drawLegs(float xpos, float ypos, float legWidth, float legHeight){
  100. stroke(0);
  101. strokeCap(ROUND);
  102. line(xpos, ypos, legWidth, legHeight);
  103. }
  104.  
  105. void drawHead(float xpos, float ypos, float headWidth, float headHeight) {
  106. stroke(102);
  107. smooth();
  108. fill(222, 171, 127);
  109. ellipse(xpos, ypos, headWidth, headHeight);
  110. }
  111.  
  112. void drawEyes(float xpos, float ypos, float eyesWidth, float eyesHeight) {
  113. fill(0);
  114. ellipse(xpos, ypos, eyesWidth, eyesHeight);
  115. }
  116.  
  117. void drawArms(float xpos, float ypos, float armsWidth, float armsHeight) {
  118. stroke(0);
  119. strokeCap(ROUND);
  120. line(xpos, ypos, armsWidth, armsHeight);
  121. }
  122. }
  123.  
  124. Person myPerson;
  125.  
  126. void setup() {
  127. size(200, 200);
  128.  
  129. myPerson = new Person();
  130. }
  131.  
  132. void draw() {
  133. background(255);
  134. myPerson.move();
  135. myPerson.display();
  136. text( "x: " + mouseX + " y: " + mouseY, mouseX, mouseY );
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement