Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3.  
  4. <head>
  5. <title>Objects: Simple Cars</title>
  6. <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.13/p5.js"></script>
  7. <script>
  8. var cars = [];
  9.  
  10. function setup() {
  11. createCanvas(500, 500);
  12. car1 = new Car();
  13. car2 = new Car();
  14. car3 = new Car();
  15. }
  16.  
  17. function draw() {
  18. background(0);
  19. car1.move();
  20. car1.display();
  21. car2.move();
  22. car2.display();
  23. car3.move();
  24. car3.display();
  25.  
  26. }
  27.  
  28. function Car() {
  29. this.x = random(width);
  30. this.y = random(height);
  31. this.speed = random(0, 6);
  32.  
  33. this.move = function() {
  34. this.x += this.speed;
  35. if (this.x > width) {
  36. this.x = 0;
  37. }
  38. }
  39.  
  40. this.display = function() {
  41. rect(this.x, this.y, 100, 50);
  42. }
  43.  
  44. }
  45.  
  46. </script>
  47. </head>
  48.  
  49. <body>
  50.  
  51. </body>
  52.  
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement