good morning
How to translate the following line of code to Preocessing:
// array containing the x positions of the line graph, scaled to fit the canvas
posx = Float32Array.from({ length: time }, (_, i) => map(i, 0, time, 0, W));
~~
final int W = 680, H = 200; // dimensions of canvas
final int time = 400; // number of x tick values
final int step = W/time; // time step
float data ; // to store number of infected people
int count = 0; // steps counter
int pos, fy, c, infected, colors, l, f;
void setup() {
size(W, H);
fill(255, 30, 70, 90);
// array containing the x positions of the line graph, scaled to fit the canvas
//posx = Float32Array.from({ length: time }, (_, i) => map(i, 0, time, 0, W));
float posx = new float[time];
for (int i = 0; i < time; posx[i] = map(i++, 0, time, 0, W));
// function to map the number of infected people to a specific height (here the height of the canvas)
fy = _ => map(_, 3, 0, H, 10);
// colors based on height stored in an array list.
colors = d3.range(H).map(i => d3.interpolateWarm(norm(i, 0, H)))
}
I don't know how to translate the last two lines.
I do not understand them:
fy, is declared as in int
but I don't understand the oprarator "_"! which follows after the sign =.
and d3 is declared internally within void? !!
_ isn’t an operator but a function parameter.
Having a parameter named as _ is a convention which means just ignore it.
However that’s not the case there; _ should be renamed to something else.
Sorry but that d3 is another library:
Which means you won’t be able to convert it to Processing unless you find another way to convert the D3’s methods range() & interpolateWarm() to Java.