Debugging -Parameter in der Füllfunktion in JavaScript [geschlossen]JavaScript

Javascript-Forum
Anonymous
 Debugging -Parameter in der Füllfunktion in JavaScript [geschlossen]

Post by Anonymous »

Ich erhalte immer wieder Fehler, die mit meinen Farben geschieht, um Objekte nach ihrer ID zu identifizieren.

Code: Select all

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;
}
}
}
< /code>
Ich versuche, die Farben basierend auf der ID zu identifizieren, die der Benutzer eingegeben hat. Die Funktion fill () 
scheint die Farbe (255, 0, 0) als gültiger Parameter einfach nicht zu nehmen. Wie kann ich dieses Problem lösen?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post