JSFiddle - React, Tailwind, and code Playground
HTML
<canvas id="main-canvas" width="600" height="400"></canvas>
CSS
#main-canvas {
border: solid 1px #333;
}
JavaScript
class CVehicule {
constructor(nom, type, fichier) {
this.nom = nom;
this.type = type;
this.image = new Image();
this.image.src = fichier;
}
draw(ctx,x,y,w,h) {
ctx.drawImage(this.image,x,y,w,h);
}
}
const mainCanvas = document.getElementById('main-canvas');
const ctx = mainCanvas.getContext('2d');
const mavoiture = new CVehicule("Mercedes", 1, "https://placehold.co/600x400");
mavoiture.draw(ctx, 0, 0, 600, 400);