Transform Array of float into an other Array or ArrayList

Hello,

I’m trying to transform data of 5 differences phases in order to have it constrained and mapped positively between 200 and 12000.

I did like this:

`````` for (int i = 0; i < net.size; i++) {. // 5 phases coupled in a net

pushMatrix();
float x = displacement*cos(net.phase[i]);
float y = displacement*sin(net.phase[i]);

// ***************************************DATA TO MANAGE SOUND

if  (net.phase[i] < 0) {

phaz[i] = constrain( map( net.phase[i], 0, -TWO_PI, 200, 12000 ), 200, 12000 );

}

else  {

//     phaz[i] = constrain( map( net.phase[i], 0, TWO_PI, 200, 12000 ), 200, 12000 );

}

//   moog0.frequency.setLastValue( phaz[0]  ); // modulate the cutoff or the moog filter with phase
//   moog1.frequency.setLastValue( phaz[1]  ); // modulate the cutoff or the moog filter with phase
//   moog2.frequency.setLastValue( phaz[2]  ); // modulate the cutoff or the moog filter with phase
//   moog3.frequency.setLastValue( phaz[3]  ); // modulate the cutoff or the moog filter with phase
//   moog4.frequency.setLastValue( phaz[4]  ); // modulate the cutoff or the moog filter with phase
``````

I’m trying to map values from an array into an other array or array list. (I’m not a programmer at all).

I have problem with ArrayIndexOutOfBoundsException: 3 or ArrayIndexOutOfBoundsException: 0

I put this before in the setup, and I don’t know what to choose

``````float phaz[]= new float [0];
//ArrayList phaz = new ArrayList();
``````

I have put nothing in the setup.

Thanks. Maybe the solution is very simple

1 Like

What is net and how is it filled

Hello,

Here the program but not entirely because wee need a special library to use it.

``````//MANAGE SOUND

import ddf.minim.*;
import ddf.minim.ugens.*;

// MANAGE ARDUINO
import processing.serial.*;
Serial arduinoport;

// MANAGE data TO SEND to ARDUINO
float speed0, speed1, speed2, speed3, speed4;
int VirtualPosition, VirtualPosition1;
float[] pos;

// MANAGE SOUND
Minim       minim;

AudioOutput out0;
AudioOutput out1;
AudioOutput out2;
MoogFilter  moog0;
MoogFilter  moog1;
MoogFilter  moog2;

//MANAGE VARIABLE TO MODULATE SOUND
float phaz, freq;
float rez, freqrez;

// MANAGE PERSPECTIVE
import peasy.*;
PeasyCam cam;

// change these for screen size
float fov = 45;  // degrees
float w = 1000;
float h = 800;

// don't change these
float cameraZ, zNear, zFar;
float w2 = w / 2;
float h2 = h / 2;

// MAANGE MOVEMENT
import sync.*;

PNetwork net;
float side;
float displacement;
float NaturalF;
float coupling;

float noiseScale= 1;

void setup() {
//perspective setting
size(1000, 800, P3D);

//********to send value to Arduino
String[] ports = Serial.list();
printArray(ports);
// arduinoport = new Serial(this,ports[6],115200);

//***************

// initialize the minim and out objects

minim   = new Minim(this);

out0    = minim.getLineOut();
out1    = minim.getLineOut();

// construct a law pass MoogFilter with a
// cutoff frequency of 1200 Hz and a resonance of 0.5
moog0    = new MoogFilter( 1200, 0.5 );
moog1    = new MoogFilter( 1200/8, 0.5 );
moog2    = new MoogFilter( 1200*8, 0.5 );

// we will filter a white noise source,
// which will allow us to hear the result of filtering
Noise noize = new Noise( 0.5f );

// send the noise through the filter
noize.patch(moog0).patch(out0);
noize.patch(moog1).patch(out1);

/*  to manage later reflection on sphere
colorMode(RGB, 1);
//  fill(0.4);
*/

cam = new PeasyCam(this, 1000);
cameraZ = (h / 2.0) / tan(radians(fov) / 2.0);
zNear = cameraZ / 10.0;
zFar = cameraZ * 10.0;
println("CamZ: " + cameraZ);
rectMode(CENTER);
//

int networkSize = 12; // To modulate sound of 12 note (one octave) Later!!!
coupling = 1;// How modulate this?
float noiseLevel = 0 ; // Usefull only with case Q?
net = new PNetwork(this, networkSize, coupling, noiseLevel);
side = height*0.15*1/networkSize;
displacement = width/2;

frameRate(20);
}

void draw() {

//   MODULATE COUPLING with MouseX

coupling = mouseX/80;
net.setCoupling(coupling);
println(coupling);

// MODULATE the noise in Q and q case
noiseDetail(4, mouseY/(height*1/1.2));//mouseX/(width/20), mouseY/(height*1/1.2)

background(220);

// Calculate the overall order (cohesion) in the network
PVector order = net.getOrderVector();
float orderParameter = net.getOrderParameter();
stroke(100);
fill(100);
String ordometer = String.format("Order: %.2f", orderParameter);
text(ordometer, 10, 20);
//  net.setCoupling(coupling);
String couplingFormat = String.format("Coupling: %.2f", coupling);
text(coupling, 200, 20);

translate(width/2, height/2);

/* to manage later the direction of the light
lightSpecular(1, 1, 1);
directionalLight(0.8, 0.8, 0.8, 0, 0, -1);
float s = mouseX / float(width);
specular(s, s, s);
*/

// Draw  spheres corresponding to the phase of each oscillator

stroke(75, 190, 70);
for (int i = 0; i < net.size; i++) {
pushMatrix();
float x = displacement*cos(net.phase[i]);
float y = displacement*sin(net.phase[i]);

// ***************************************DATA TO MANAGE SOUND

if  (net.naturalFrequency[i] < 0) {

freq = constrain( map( net.naturalFrequency[i], 0, -5, 200, 12000 ), 200, 12000 );

}

else  {

freq = constrain( map( net.naturalFrequency[i], 0, 5, 200, 12000 ), 200, 12000 );

}

if  (net.phase[i] < 0) {

phaz = constrain( map( net.phase[i], 0, -2*PI, 200, 12000 ), 200, 12000 );

}

else  {

phaz = constrain( map( net.phase[i], 0, 2*PI, 200, 12000 ), 200, 12000 );

}

float  freq = constrain( map( net.naturalFrequency[i], 0, 5, 200, 16000 ), 200, 12000 );// adjust frequency between 200 and 12000

float phaz0 = constrain( map( net.phase[0], 0, 2*PI, 200, 16000 ), 200, 12000 ); // adjust phase between 200 and 12000

float phaz1 = constrain( map( net.phase[1], 0, 2*PI, 200, 16000 ), 200, 12000 ); // adjust phase between 200 and 12000

moog0.frequency.setLastValue(phaz0); // modulate the cutoff or the moog filter with  phase0 of the background (orange).

moog1.frequency.setLastValue(phaz1); // modulate the cutoff or the moog filter with  phase0 of the background (orange).

//  moog2.frequency.setLastValue(phaz); // modulate the cutoff of the moog2 filter with all phase one after one

// ************** PRINT DATA TO SEE COHERENCE BETWEEN MOVEMENT AND SOUND

print ("phase "); print (i);  print (" "); print (net.phase[i]); print (" ");
print ("phaz "); print (i);  print (" "); println (phaz );
print ("phaz0"); print (i);  print (" "); println (phaz0 );

// print ("frequency "); print (i); print (" ");
//    print (net.naturalFrequency[i]);  print (" ");
print ("freqrez "); print (i); print (" "); println (freqrez );
print ("freq "); print (i); print (" "); println (freq );
print ("rez"); print (i); print (" "); println (rez );

translate(-w2, -h2, -1000); // Set the perspective 3D with two fingers on the trackpad

line (250,250, 250, 250);  // line showing how ball will behang by the motor's axe.

// line (0,0,0,0,0, 11*250+200+250); //axe helping the 3D representation. axe qui relie les pendules

fill (0);
sphere(side*3); // this sphere serves as a reference
sphereDetail( 4*5);

// Draw sphere
fill(25*(net.size-i),  11*(net.size-i), (i+net.size)*11 );
noStroke();  //
translate (x*1,y*1, 200+(50*5*i));  //*-1 go in clockwise, *1 go in CCW
sphere(side*3);

// Draw axe of each sphere
rotate(net.phase[i]);
stroke(120);
line(0, 0, displacement*-1, 0 ); // * opposite / translate
noStroke();

popMatrix();
}
//********* AESTHETIC PROPOSITION to HAVE the same movement at the OPPOSITE SIDE

/*
noiseDetail(4, mouseY/(height*1/1.2));//mouseX/(width/20), mouseY/(height*1/1.2)

//  background(0);
translate(-(width/2), -(height/2), -1000);

stroke(75, 190, 70);
for (int i = 0; i < net.size; i++) {
pushMatrix();
float x = displacement*cos(net.phase[i]);
float y = displacement*sin(net.phase[i]);

/*
rotate(net.phase[i]);
stroke(120);
line(0, 0, displacement*1, 0 );
rotate(-net.averagePhase); // draw a line pointing to the average phase of the network
color (12);
stroke (255);
line(0, 0, displacement*net.orderParameter, 0);
*/

/*
// Draw sphere
fill(25*(net.size-i),  11*(net.size-i), (i+net.size)*11 );
noStroke();  //
translate (x*-1,y*-1, 200+(50*5*i));  //*-1 go in clockwise, *1 go in CCW
sphere(side*3);

// Draw axe of each sphere
rotate(net.phase[i]);
stroke(120);
line(0, 0, displacement*1, 0 ); // * opposite / translate
noStroke();

popMatrix();

}
*/

net.step();

}
}

``````

Above // ***************************************DATA TO MANAGE SOUND

I have net.frequency and net.phase of a net “oscillators coupled”. I want to transform each phase by changing phaz in a new array phaz[I] like that

``````  if  (net.phase[i] < 0) {

phaz[i] = constrain( map( net.phase[i], 0, -2*PI, 200, 12000 ), 200, 12000 );

}

else  {

phaz[i]= constrain( map( net.phase[i], 0, 2*PI, 200, 12000 ), 200, 12000 );

}
``````

For now, I made a pseudo solution to have phaz[0] and phase[1] when only net.phase[0] and net.phase[1 ]is > 0. So, it’s too long if I want to do that 12 times.

1 Like

Re: Transform Array of float into an other Array or ArrayList

You can use FloatList
https://processing.org/reference/FloatList.html

``````// assuming
float[] data = new float(){3.1, 1.0, PI};
// then
FloatList f = new FloatList(data);
// or
FloatList f = new FloatList();
f.append(data);
``````
1 Like