How to text array

hi all

how to text array elements i have try but i could not do it looks random and wrong code

any help

thanks in advance



void  setup () { 
size ( 800 ,  800 );  

}
void  draw () { 

  fill(0);
int[] x = { 
  50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
 50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
 50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
676, 61, 83, 69, 71, 50, 29, 31, 17, 39
};


fill(0);

for (int i = 0; i < x.length; i++) {

  
  textSize(20);
  text(x[i],x[i]*12,i*10);
}
}

Have you tried str() should convert strings or floats.

Weirdly this isnt required for println as it auto converts.

i want to text it on screen not with println

Not a problem use str()

give me hint how to use str()

https://processing.org/reference/strconvert_.html

look what i want this array contains few elements i text all of them but if the more than screen width they out of boarder i want to text the elements as the are in the array



void  setup () { 
size ( 800 ,  800 );  

}
void  draw () { 

  fill(0);
int[] x = { 
  50, 61, 83, 69, 71, 50, 
 

};


fill(0);

for (int i = 0; i < x.length; i++) {

  
  textSize(20);
  text(x[i],i*44,55);
}
}

didnt understand much of that. Can you clarify please.

what are you trying to achieve your code already displays the values in the array.

image

if(i*44<width)text(x[i],i*44,55);

this will limit the displayed number to only those that fit in the window, note the array values are still being iterated though.

what i need incited of printing array elements on consuls

this is just 6 elements texting them no issue but what if the array contains lets say 200 elements how to text them

void  setup () { 
size ( 800 ,  800 );  

}
void  draw () { 

  fill(0);
int[][] x = { 
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{676, 61, 83, 69, 71, 50, 29, 31, 17, 39}
};


fill(0);

for (int i = 0; i < x.length; i++) {
  for (int j = 0; j < x[0].length; j++) {
  
  textSize(20);
  text(x[i][j],50*j,i*20);
}
}}
1 Like
void  setup () { 
size ( 800 ,  800 );  

}
void  draw () { 

  fill(0);
int[] x = { 
  50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
 50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
 50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
676, 61, 83, 69, 71, 50, 29, 31, 17, 39
};


fill(0);
int row = 0;
float spacing = 25;
float xx = 0;
for (int i = 0; i < x.length; i++) {
  xx += spacing;
  textSize(20);
  if(xx>width){
    xx = 0;
    row++;
  }
  println(row);
  text(x[i],xx,50+row*20);
}
}
1 Like

paulgoux

thanks a a lot that is what i want but i do have other question but let my prepare how to ask it thanks again for the second way

1 Like

@paulgoux
thanks for you the code is part of timing measurement like this but may i ask some other thing when i apply my all stuff

free

Sure what do you need?

i am not sure yet did not fished and i am not stuck for now

@paulgoux
explain this line

 for (int j = 0; j < x[0].length; j++) {

Your iterating through a double array so you need the length of the internal array.

The code however is assuming that all internal arrays are the same size, else use x[i].length

1 Like

Using @paulgoux suggestion for using String, I wonder if this too is of use to your question. Then you don’t need to use the array and for loop…
:thinking:

//////////////////////////////////////////////

void  setup () { 
  size (800, 800);
}
void  draw () { 

  fill(0);

  String strg1 = "50, 61, 83, 69, 71, 50, 29, 31, 17, 39, 50, 61, 83, 69, 71, 50, 29, 31, 17, 39, 50, 61, 83, 69, 71, 50, 29, 31, 17, 39, 50, 61, 83, 69, 71, 50, 29, 31, 17, 39"; // I did not include all of your numbers, this is just a text to see if solves the question

  textSize(20);
  text(strg1, 20, 40, 750, 750);
}
1 Like

this might be interesting https://www.processing.org/tutorials/data/

it shows how to load and display Tabular Data

2 Likes