Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>Objects: Simple Cars</title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.13/p5.js"></script>
- <script>
- var cars = [];
- function setup() {
- createCanvas(500, 500);
- car1 = new Car();
- car2 = new Car();
- car3 = new Car();
- }
- function draw() {
- background(0);
- car1.move();
- car1.display();
- car2.move();
- car2.display();
- car3.move();
- car3.display();
- }
- function Car() {
- this.x = random(width);
- this.y = random(height);
- this.speed = random(0, 6);
- this.move = function() {
- this.x += this.speed;
- if (this.x > width) {
- this.x = 0;
- }
- }
- this.display = function() {
- rect(this.x, this.y, 100, 50);
- }
- }
- </script>
- </head>
- <body>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement