CodingTrain / CodingTrain/Suggestion-Box

while and loops with an array

Aperta
#967 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
570
Fork
85
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia dalla funzione PositionObjets mostrata nell’issue e traccia entrambe le condizioni del while-loop insieme all’accesso a Tableautemp[i]. Riproduci il comportamento out-of-range usando l’esempio fornito, quindi determina come dovrebbero essere rappresentati l’ultimo elemento disegnabile e un canvas completo. Il lavoro è completato quando il ciclo gestisce il limite dell’array senza accedere a un elemento mancante e preserva l’indice necessario per il canvas successivo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
computer-graphics
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.