Car week 9

This commit is contained in:
Andrea Bianchi 2025-04-22 12:26:03 +09:00
parent d3411d50ec
commit b3acd85915
12 changed files with 90167 additions and 0 deletions

11
w9_cars/css/style.css Normal file
View File

@ -0,0 +1,11 @@
html,
body {
margin: 0;
/* padding: 5px; */
align-items: center;
text-align: center;
background-color: beige;
}
canvas {
display: block;
}

BIN
w9_cars/data/car.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
w9_cars/data/font.vlw Normal file

Binary file not shown.

BIN
w9_cars/data/sport.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
w9_cars/data/truck.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

18
w9_cars/index.html Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<script src="./js/p5.js"></script>
<script src="./js/p5.dom.min.js"></script>
<script src="./js/p5.sound.min.js"></script>
<link rel="stylesheet" type="text/css" href="./css/style.css" />
<meta charset="utf-8" />
</head>
<body>
<script src="sketch.js"></script>
</body>
</html>

3
w9_cars/js/p5.dom.min.js vendored Normal file

File diff suppressed because one or more lines are too long

90025
w9_cars/js/p5.js Normal file

File diff suppressed because one or more lines are too long

28
w9_cars/js/p5.sound.min.js vendored Normal file

File diff suppressed because one or more lines are too long

44
w9_cars/sketch.js Normal file
View File

@ -0,0 +1,44 @@
const vehicles = [];
const IMG_SIZE = 400;
let message = '';
const images = {};
function setup() {
// createCanvas(400, 300);
createCanvas(window.innerWidth, window.innerHeight);
vehicles.push(new Car(4));
}
function draw() {
background(255);
for (let i = 0; i < vehicles.length; i += 1) {
vehicles[i].draw(i * IMG_SIZE, 0, IMG_SIZE);
}
fill(0);
textFont('Arial', 20);
textAlign(CENTER);
text(message, width / 2, IMG_SIZE);
}
function mousePressed() {
const index = floor(mouseX / IMG_SIZE);
message = vehicles[index]?.getDescription() ?? 'None'; // polymorphism!
}
// CLASSES
class Car {
constructor(passengers) {
// ...
}
getDescription() {
// PLACEHOLDER
}
draw() {}
}

38
w9_cars/test.wsd Normal file
View File

@ -0,0 +1,38 @@
@startuml
class Vehicle {
-img: PImage
+ {abstract} getDescription(): String
+ draw (x: Number, y: Number, size: Number): void
}
class Car {
- passengers: Number
+ constructor (passengers: Number)
+ getDescription (): String
}
class Truck {
- load: Number
+ constructor (load: Number)
+ getDescription (): String
}
class SportCar {
- fullOp: Bolean
+ constructor (fullOptions: Boolean)
+ getDescription (): String
+ getTurbo (): String
+ getOptions (): String
}
class Convertible {
+ constructor()
+ getDescription(): String
+ getRooftop(): String
}
Vehicle <|.. Car
Vehicle <|.. Truck
Car <|-- SportCar
SportCar <|-- Convertible
@enduml