CodingTrain / CodingTrain/Suggestion-Box
while and loops with an array
- Vorherrschende Sprache
- Keine Sprachdaten
- Sterne
- 570
- Forks
- 85
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Hi,
I am looking for having an array of objects to be manipulated upon the canvas. But this array contains 10000000 elements and is always incrementing. Then my goal is not to create this big array, but to create it step by step each time I am able to fill a canvas with it's elements. Then I will manipulate each visible element into the canvas.
I try the following code in order to put my array elements into the canvas. But I am not able to stop the function before the variable i is out of Tableautemp's range. When all the canvas is full, I want to create another canvas.
How can I do that ? I want to track the last item able to be put in the canvas.
```
function PositionObjets (Tableautemp) {
this.Tableautemp = Tableautemp;
fill(0);
stroke(250);
let x =xinit;
let y =yinit;
let spacing = 0;
let i = 0;
while (y+margeh<=htot) {
console.log(i);
while (x+this.Tableautemp[i].w+margew<=wtot) {
this.Tableautemp[i].x = x;
this.Tableautemp[i].y = y;
this.Tableautemp[i].Dessine(); // it draws a rectangle but it is just for test purpose that I is put at this place
x=x+this.Tableautemp[i].w+spacing;
if (i
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne mit der in der Issue gezeigten Funktion PositionObjets und verfolge beide while-loop-Bedingungen zusammen mit dem Zugriff auf Tableautemp[i]. Reproduziere das Out-of-Range-Verhalten anhand des bereitgestellten Beispiels und bestimme anschließend, wie das letzte zeichnbare Element und eine vollständige canvas dargestellt werden sollten. Als erledigt gilt, dass die Schleife die Array-Grenze behandelt, ohne auf ein fehlendes Element zuzugreifen, und den für die nächste canvas benötigten Index beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- computer-graphics
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100