Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. var vel = 2;
  2. var vel2 = 4;
  3. var vel3 = 4;
  4. var velBici = 3;
  5. var altura = 20;
  6. var largura = 30;
  7.  
  8.  
  9.  
  10. function setup() {
  11. createCanvas(400, 700);
  12. robot1 = 0 + int((((width / 2) - largura) - 0 + 1) * random());
  13. robot2 = 0 + int((((width / 2) - largura) - 0 + 1) * random());
  14. robot3 = 0 + int((((width / 2) - largura) - 0 + 1) * random());
  15. }
  16.  
  17. function draw() {
  18. background(220);
  19. desenharRobot(robot1, (350), largura, altura);
  20. desenharRobot(robot2, (460), largura, altura);
  21. desenharRobot(robot3, (570), largura, altura);
  22.  
  23. vel = vel * baterParede(robot1, largura, vel);
  24. vel2 = vel2 * baterParede(robot2, largura, vel2);
  25. vel3 = vel3 * baterParede(robot3, largura, vel3);
  26.  
  27. robot1 = robot1 + vel;
  28.  
  29. robot3 = robot3 + vel3;
  30.  
  31. }
  32.  
  33. function desenharRobot(x, y, largura, altura) {
  34.  
  35.  
  36. if (largura > altura)
  37. raio = altura / 5;
  38. else
  39. raio = largura / 5;
  40.  
  41. rect(x, y - 25, largura, altura); //cabeça
  42. line(x + 15, y, x + 15, y - 5); //pescoço
  43. line(x + 55, y, x - 30, y); //tronco linha
  44. line(x + 55, y, x + 55, y + 30); //mao direita
  45. line(x - 30, y, x - 30, y + 30); //mao esquerda
  46. rect(x, y, largura, altura * 2); // tronco retangulo
  47. line(x, y, x, y + 80); //perna esqueda
  48. line(x + 30, y, x + 30, y + 80); //perna direita
  49. ellipse(x, y + 80, 2 * raio, 2 * raio); // perna bola esquerda
  50. ellipse(x + 30, y + 80, 2 * raio, 2 * raio); // perna bola direita
  51. }
  52.  
  53. function baterParede(xrobot, largura) {
  54. if (xrobot > width - largura) {
  55. return -1;
  56. } else if (xrobot < 0) {
  57. return -1;
  58. }
  59. return 1;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement