I just keep getting errors that is happening with my colors trying to identify objects by their ID.
mover.js
class Mover {
constructor(id) {
this.velocityKmH = 0;
this.targetSpeedKmH = 0;
this.pos = createVector(0, 200);
this.id = id;
let colors = [255, 0, 125.5];
this.maxDistancePixels = 400;
this.totalDistanceKm = 0;
this.distanceTravelledKm = 0;
}
setVirtualDistance(distanceKm) {
this.virtualDistanceKm = distanceKm;
this.distanceTravelledKm = 0;
this.pos.x = 0;
}
setTrip(distanceKm, timeHours) {
this.totalDistanceKm = distanceKm;
this.targetSpeedKmH = distanceKm / timeHours;
this.velocityKmH = 0;
this.distanceTravelledKm = 0;
this.pos.x = 0;
}
display() {
let colors = [color(0, 0, 255), color(255, 0, 0)];=
fill(colors[this.id % colors.length]);
noStroke();
ellipse(this.pos.x, this.pos.y, 30, 30);
textSize(17);
text(this.id, this.pos.x - 18, this.pos.y - 22);
}
move() {
if (this.distanceTravelledKm < this.totalDistanceKm) {
const deltaTimeHours = 1 / frameRate();
const distanceThisFrameKm = this.targetSpeedKmH * deltaTimeHours;
this.distanceTravelledKm += distanceThisFrameKm;
const visualProgress = this.distanceTravelledKm / this.totalDistanceKm;
this.pos.x = visualProgress * this.maxDistancePixels;
this.pos.x = constrain(this.pos.x, 0, this.maxDistancePixels);
this.velocityKmH = this.targetSpeedKmH;
}
else {
this.velocityKmH = 0;
}
}
}
I was just trying to identify the colors based on the ID the user entered. But the fill()
function just doesn’t seem to take the color(255, 0, 0)
as a valid parameter.
Anyone know how to resolve this problem?
Any answer is appreciated.